Skip to content

Commit

Permalink
re-add debug to serial-buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacov committed Jan 29, 2017
1 parent c40b06c commit 0eb3338
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion ports/rtubufferedport.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
};

Expand Down Expand Up @@ -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);
};
Expand Down

0 comments on commit 0eb3338

Please sign in to comment.