Skip to content

Commit

Permalink
Fixed Read Holding Registers Server Function
Browse files Browse the repository at this point in the history
+ fixed the test so it catches the bug I introduced earlier
  • Loading branch information
psorowka committed Nov 22, 2016
1 parent 4e9b3e1 commit 195dd32
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/handler/server/ReadHoldingRegisters.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module.exports = stampit()
head.writeUInt8(0x03, 0);
head.writeUInt8(quantity * 2, 1);

var response = Buffer.concat([head, mem.slice(byteStart * 2, byteStart * 2 + quantity * 2)]);
var response = Buffer.concat([head, mem.slice(byteStart, byteStart + quantity * 2)]);

this.log.debug('finished read holding register request.');

Expand Down
6 changes: 2 additions & 4 deletions test/modbus-server-core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ describe("Modbus Server Core Tests.", function () {
it('should handle a read holding registers request just fine.', function (done) {

var core = Core(),
request = Buffer.from([0x03,0x00,0,0x00,5]),
exResponse = Buffer.from([0x03,10,0x00,1,0x00,2,0x00,3,0x00,4,0x00,5]);
request = Buffer.from([0x03,0x00,0x01,0x00,0x04]),
exResponse = Buffer.from([0x03,0x08,0x00,0x02,0x00,0x03,0x00,0x04,0x00,0x05]);
core.getHolding().writeUInt16BE(0x01, 0);
core.getHolding().writeUInt16BE(0x02, 2);
core.getHolding().writeUInt16BE(0x03, 4);
Expand All @@ -213,9 +213,7 @@ describe("Modbus Server Core Tests.", function () {
var resp = function (response) {

assert.equal(response.compare(exResponse), 0);

done();

};

core.onData(request, resp);
Expand Down

0 comments on commit 195dd32

Please sign in to comment.