Permalink
Browse files

Added new test case for a 'readInputRegisters' response.

  • Loading branch information...
1 parent 5f0492f commit 5f16a8a1e464363d3a95d3cd106263401c341a09 @TooTallNate committed Dec 31, 2010
Showing with 22 additions and 0 deletions.
  1. +22 −0 test/test-response-readInputRegisters.js
View
22 test/test-response-readInputRegisters.js
@@ -0,0 +1,22 @@
+var fs = require('fs');
+var assert = require('assert');
+var modbus = require('modbus-stack');
+
+exports['readInputRegisters response'] = function() {
+ var dump = fs.createReadStream(__dirname + "/responses/readInputRegisters.start0.count4.dump");
+ var req = new modbus.ModbusRequestStack(dump);
+ var gotResponse = false;
+ req.on('response', function(res) {
+ gotResponse = true;
+ assert.equal(res.functionCode, modbus.FUNCTION_CODES.READ_INPUT_REGISTERS, "response Function Code is not '" + modbus.FUNCTION_CODES.READ_INPUT_REGISTERS + "'");
+ assert.equal(res.byteLength, 8, "Expected byte length of 8");
+ assert.ok(Array.isArray(res), "response should be an Array");
+ assert.equal(res[0], 732);
+ assert.equal(res[1], 737);
+ assert.equal(res[2], 744);
+ assert.equal(res[3], 716);
+ });
+ dump.on('close', function() {
+ assert.ok(gotResponse, "The 'response' event was never fired");
+ });
+}

0 comments on commit 5f16a8a

Please sign in to comment.