eterey / pymodbus3

A full Modbus protocol written in Python 3.
http://uzumaxy.github.io/pymodbus3/
BSD 3-Clause "New" or "Revised" License
39 stars 11 forks source link

Defect in Modbus RTU handling #4

Closed tomkcook closed 7 years ago

tomkcook commented 7 years ago

In transaction.py, at line 494, header_size is set to 0x01. This length is used in ModbusTransactionManager.handle_message_framing as the number of bytes that have to be read before the header can be decoded. For the 'Read holding registers' message, the result of this is that the call to pdu_class.calculate_rtu_frame_size fails because not enough data has been read to calculate how big the frame is. Then when line 112 of transaction.py is reached, not enough of the frame is read to decode it all.

I'm not sure if there's any particular downside to changing line 494 to set header_size to 3? Are there any messages shorter than that?

tomkcook commented 7 years ago

I'm working on a fix, BTW, so when I get it working I'll submit a pull request. Setting the header_size to 3 fixes my immediate issue, but there are further problems decoding the response that I haven't had a chance to look into yet.

eterey commented 7 years ago

Merged your pull-request: https://github.com/uzumaxy/pymodbus3/pull/5 Thanks!