smarmengol / Modbus-Master-Slave-for-Arduino

Modbus Master-Slave library for Arduino
GNU Lesser General Public License v2.1
473 stars 328 forks source link

Incorrect lenght of the shortest frame for Modbus Master #65

Open aleksander1084 opened 2 years ago

aleksander1084 commented 2 years ago

https://github.com/smarmengol/Modbus-Master-Slave-for-Arduino/blob/df2fc9b6a14aa872bac24ab5255ba15ab43498e9/ModbusRtu.h#L668

Hi, while reading your library I have noticed that in a poll method for master module you have defined shortest possible frame as 6 bytes. What is correct but only for correct responses, for the error responses it should be 5 (including CRC).

For example error response for command 0x01 will look like: [Address] [Function code] [exception] [CRC HI] [CRC LO]

so even though you are later validating answer to be an error in validateAnswer it will never come true since those frames are prevously eliminated due to the lenght.

Part of the Modbus 1.1b documentation: image