-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
The RTU serial port client always waits for the port timeout value, e.g.;
client = ModbusClient(port = 'dev/ttyUSB0', ..... , timeout = 1)
will cause every request to take one second as the read size is always set to 1024 bytes, larger than an actual response. One possible solution is to read the first few bytes of the response and from that determine the complete response size. This is possible for all the common function codes.
This is a modified v1.2.0 /client/sync.py
All changes are in the last 128 lines of the file. Only affects RTU clients.
Only tested for holding register reads, which is all my hardware is set up for right now.
If the response is corrupted somehow the client will either return after reading too few bytes or timeout waiting for too many. A buffer flush would likely be required to recover from reading too few bytes, not sure where to implement that (I'm EEng not Python coder unfortunately).