Skip to content

Commit

Permalink
Merge branch 'fix-byte-bugs'
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanpoeter committed Nov 22, 2016
2 parents 4e9b3e1 + 40530e7 commit 6f97bc4
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/handler/client/WriteSingleRegister.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ module.exports = Stampit()
fc : fc,
registerAddress : registerAddress,
registerValue : registerValue,
registerAddressRaw: pdu.slice(1,2),
registerValueRaw: pdu.slice(3,2)
registerAddressRaw: pdu.slice(1,3),
registerValueRaw: pdu.slice(3,5)
};

if (fc !== 6) {
Expand Down
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
3 changes: 1 addition & 2 deletions src/handler/server/ReadInputRegisters.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ module.exports = stampit()
head.writeUInt8(0x04, 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)]);

cb(response);

Expand Down
4 changes: 4 additions & 0 deletions test/modbus-client-core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,9 @@ describe("Modbus Serial Client", function () {

assert.equal(resp.fc, 6);
assert.equal(resp.registerAddress, 3);
assert.deepEqual(resp.registerAddressRaw, Buffer.from([0x00,0x03]));
assert.equal(resp.registerValue, 123);
assert.deepEqual(resp.registerValueRaw, Buffer.from([0x00,0x7b]));

done();

Expand Down Expand Up @@ -349,6 +351,8 @@ describe("Modbus Serial Client", function () {
assert.equal(resp.fc, 6);
assert.equal(resp.registerAddress, 3);
assert.equal(resp.registerValue, 123);
assert.deepEqual(resp.registerAddressRaw, Buffer.from([0x00,0x03]));
assert.deepEqual(resp.registerValueRaw, Buffer.from([0x00,0x7b]));

done();

Expand Down
10 changes: 4 additions & 6 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 Expand Up @@ -269,8 +267,8 @@ describe("Modbus Server Core Tests.", function () {
it('should handle a read input registers request just fine.', function (done) {

var core = Core(),
request = Buffer.from([0x04,0x00,0,0x00,5]),
exResponse = Buffer.from([0x04,10,0x00,5,0x00,4,0x00,3,0x00,2,0x00,1]);
request = Buffer.from([0x04,0x00,0x01,0x00,0x04]),
exResponse = Buffer.from([0x04,0x08,0x00,4,0x00,3,0x00,2,0x00,1]);
core.getInput().writeUInt16BE(0x05, 0);
core.getInput().writeUInt16BE(0x04, 2);
core.getInput().writeUInt16BE(0x03, 4);
Expand Down

0 comments on commit 6f97bc4

Please sign in to comment.