Permalink
Browse files

Added `ModbusResponseStack#writeException()` to send an exception cod…

…e after a MODBUS request from a master (client).
  • Loading branch information...
1 parent 27e1d1a commit 2e8122910a517d804419fce531edf55ff756d625 @TooTallNate committed Jan 1, 2011
Showing with 15 additions and 0 deletions.
  1. +15 −0 lib/modbus-stack.js
View
@@ -210,6 +210,21 @@ ModbusResponseStack.prototype.writeResponse = function() {
.write(this.stream);
}
+// Sends back an exception response after receiving a request.
+ModbusResponseStack.prototype.writeException = function(exceptionCode) {
+ if (!this._gotRequest) {
+ throw new Error('Can\'t call "writeException" until after the "request" event');
+ }
+ return Put()
+ .word16be(this.request.transactionId)
+ .word16be(this.request.protocolVersion)
+ .word16be(3)
+ .word8(this.request.unitIdentifier)
+ .word8(this.functionCode | EXCEPTION_BIT)
+ .word8(exceptionCode)
+ .write(this.stream);
+}
+
// Reads the "MODBUS Application Protocol" header from the given bufferlist,
// and return a object with 'transactionId', 'protocolVersion', 'length', and

0 comments on commit 2e81229

Please sign in to comment.