Skip to content

RTU sync client always waits for timeout (with possible solution) #76

@Planet911

Description

@Planet911

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions