diff --git a/ports/rtubufferedport.js b/ports/rtubufferedport.js index fe37de6..c76effa 100644 --- a/ports/rtubufferedport.js +++ b/ports/rtubufferedport.js @@ -23,6 +23,7 @@ var RTUBufferedPort = function(path, options) { this._id = 0; this._cmd = 0; this._length = 0; + this.debug = false; // create the SerialPort this._client= new SerialPort(path, options); @@ -69,7 +70,12 @@ util.inherits(RTUBufferedPort, EventEmitter); * @private */ RTUBufferedPort.prototype._emitData = function(start, length) { - this.emit('data', this._buffer.slice(start, start + length)); + var buffer = this._buffer.slice(start, start + length); + + // emit debug message + if (this.debug) { this.emit('debug', {action: 'recive', data: buffer}); } + + this.emit('data', buffer); this._buffer = this._buffer.slice(start + length); }; @@ -132,6 +138,9 @@ RTUBufferedPort.prototype.write = function (data) { break; } + // emit debug message + if (this.debug) { this.emit('debug', {action: 'send', data: data}); } + // send buffer to slave this._client.write(data); };