I kept getting exception code 2 on reading input registers despite everything else working out. finally on inspection of the library code I found the culprit on line 185 of ModbusRTUSlave.cpp. The line reads
else if (quantity > _numDiscreteInputs || startAddress > (_numInputRegisters - quantity)) _exceptionResponse(2);
how ever changing it to
else if (quantity > _numInputRegisters || startAddress > (_numInputRegisters - quantity)) _exceptionResponse(2);
fixed the issue for me and the library is working perfectly now.
Someone else recently reported the same issue and recommended the same fix (see Issue #23).
This fix has since been incorporated into the library.
Thank you for your feedback.
I kept getting exception code 2 on reading input registers despite everything else working out. finally on inspection of the library code I found the culprit on line 185 of ModbusRTUSlave.cpp. The line reads
else if (quantity > _numDiscreteInputs || startAddress > (_numInputRegisters - quantity)) _exceptionResponse(2);
how ever changing it to
else if (quantity > _numInputRegisters || startAddress > (_numInputRegisters - quantity)) _exceptionResponse(2);
fixed the issue for me and the library is working perfectly now.