Skip to content

Commit

Permalink
fixes WRITE_MULTIPLE_COILS missing "number of bytes to follow" field
Browse files Browse the repository at this point in the history
  • Loading branch information
dresende committed Feb 10, 2016
1 parent db973a4 commit 8e04035
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/Server/ReadStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ ReadStream.prototype._transform = function (chunk, encoding, next) {
pkg.from = data.readUInt16BE(0);
pkg.to = data.readUInt16BE(2) + pkg.from - 1;
pkg.items = [];
for (var i = 4; i < data.length; i++) {

for (var i = 5; i < data.length; i++) {
for (var j = 0; j < 8; j++) {
pkg.items.push((data[i] >> j) & 0x1);
if (pkg.items.length >= pkg.to - pkg.from + 1) {
Expand Down
5 changes: 3 additions & 2 deletions lib/protocol/WRITE_MULTIPLE_COILS.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ var pack = require("./tools").pack2uint16;

exports.request = function (transactionId, unitId, startAddress, endAddress, status) {
var bits = packbits(status);
var buf = new Buffer(bits.length + 4);
var buf = new Buffer(bits.length + 5);

buf.writeUInt16BE(startAddress, 0);
buf.writeUInt16BE(endAddress - startAddress + 1, 2);
bits.copy(buf, 4);
buf.writeUInt8(Math.ceil((endAddress - startAddress + 1) / 8), 4);
bits.copy(buf, 5);

return new Package(
transactionId,
Expand Down

0 comments on commit 8e04035

Please sign in to comment.