CMB27 / ModbusRTUSlave

This is an Arduino library that implements the slave/server logic of the Modbus RTU protocol.
MIT License
58 stars 14 forks source link

Read Input registers request returning exception code 2 #26

Closed fs0711 closed 11 months ago

fs0711 commented 11 months ago

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.

CMB27 commented 11 months ago

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.