We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f2766c5 commit bf89a33Copy full SHA for bf89a33
src/Modbus.cpp
@@ -414,7 +414,7 @@ void Modbus::readCoils (word startreg, word numregs) {
414
byte bitn = 0;
415
word totregs = numregs;
416
word i;
417
- while (numregs--) {
+ while (numregs) {
418
i = (totregs - numregs) / 8;
419
if (coil (startreg)) {
420
bitSet (_frame[2 + i], bitn);
@@ -423,12 +423,10 @@ void Modbus::readCoils (word startreg, word numregs) {
423
bitClear (_frame[2 + i], bitn);
424
}
425
//increment the bit index
426
- bitn++;
427
- if (bitn == 8) {
428
- bitn = 0;
429
- }
+ bitn = (bitn + 1) % 8;
430
//increment the register
431
startreg++;
+ numregs--;
432
433
434
_reply = MB_REPLY_NORMAL;
0 commit comments