Skip to content

Commit 13bc434

Browse files
committed
fix: Fixes #1 Issue
Modbus::readInputStatus() numregs decrementation was wrong.
1 parent 5c20c02 commit 13bc434

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/Modbus.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ void Modbus::readInputStatus (word startreg, word numregs) {
486486
byte bitn = 0;
487487
word totregs = numregs;
488488
word i;
489-
while (numregs--) {
489+
while (numregs) {
490490
i = (totregs - numregs) / 8;
491491
if (ists (startreg)) {
492492
bitSet (_frame[2 + i], bitn);
@@ -495,12 +495,10 @@ void Modbus::readInputStatus (word startreg, word numregs) {
495495
bitClear (_frame[2 + i], bitn);
496496
}
497497
//increment the bit index
498-
bitn++;
499-
if (bitn == 8) {
500-
bitn = 0;
501-
}
498+
bitn = (bitn + 1) % 8;
502499
//increment the register
503500
startreg++;
501+
numregs--;
504502
}
505503

506504
_reply = MB_REPLY_NORMAL;

0 commit comments

Comments
 (0)