Skip to content

Commit bf89a33

Browse files
committed
fix: Fixes #2
1 parent f2766c5 commit bf89a33

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
@@ -414,7 +414,7 @@ void Modbus::readCoils (word startreg, word numregs) {
414414
byte bitn = 0;
415415
word totregs = numregs;
416416
word i;
417-
while (numregs--) {
417+
while (numregs) {
418418
i = (totregs - numregs) / 8;
419419
if (coil (startreg)) {
420420
bitSet (_frame[2 + i], bitn);
@@ -423,12 +423,10 @@ void Modbus::readCoils (word startreg, word numregs) {
423423
bitClear (_frame[2 + i], bitn);
424424
}
425425
//increment the bit index
426-
bitn++;
427-
if (bitn == 8) {
428-
bitn = 0;
429-
}
426+
bitn = (bitn + 1) % 8;
430427
//increment the register
431428
startreg++;
429+
numregs--;
432430
}
433431

434432
_reply = MB_REPLY_NORMAL;

0 commit comments

Comments
 (0)