ljean / modbus-tk

Create Modbus app easily with Python
Other
566 stars 212 forks source link

Do not rely on receive timeout of serial port #109

Closed kcl93 closed 5 years ago

kcl93 commented 5 years ago

With Windows 10 and Arduino MEGA and DUE as ModbusRTU slaves I have experienced that the serial receive timeout is not reliable. In many cases it immediately returns instead of waiting the set timeout time. This leads to errors even tough the slave answered immediately. Additionally handling the receive timeout in the python script fixed this issue with unreliable driver implementations for me.

ljean commented 5 years ago

Thanks for this proposal. If my understanding is correct, you don't set the timeout for the serial port and use the time calculation.

It looks good to me but it should not be activated by default otherwise it may breaks the current behavior.

Can you please implement it as an optional argument of RtuMaster?

kcl93 commented 5 years ago

Breaking the current behavior may indeed be a risk. I have updated the code to use an optional argument in the set_timeout function to enable or disable the software timeout. Standard behavior is disabled.