AdvancedClimateSystems / uModbus

Python implementation of the Modbus protocol.
Mozilla Public License 2.0
211 stars 82 forks source link

rtu.send_message should not read more bytes than needed. #49

Closed OrangeTux closed 6 years ago

OrangeTux commented 7 years ago

Currrently rtu.send_message() is to greedy when reading response from the serial port. uModbus will fail when a server appends a response with for example a few nul bytes. The function should not read more bytes than needed.

Often the length of the response can be calculated. For response on function codes 1, 2, 3, 4,15 and 16 the 2nd byte of the PDU contains the byte count. That is how many bytes are left in the PDU.

The response of function code 5 en 6 is of the same length as the request PDU.

In case of an error the response is only 2 bytes.