Crates.io | modbus-robust |
lib.rs | modbus-robust |
version | 0.1.0 |
source | src |
created_at | 2023-12-25 11:08:30.585406 |
updated_at | 2023-12-25 11:08:30.585406 |
description | Layer over tokio-modbus to automatically reconnect on failure |
homepage | |
repository | https://github.com/bmerry/modbus-robust |
max_upload_size | |
id | 1080178 |
size | 15,661 |
This library is a layer on top of
tokio-modbus.
When a modbus call fails, it will automatically discard the current connection
and reconnect. This makes it robust to TCP connection failures, such as can be
caused by restarting mbusd
.
This is not a complete retry mechanism. For example, if reconnecting fails, the call will fail rather than making further attempts to connect. If multiple retries are desired, they can be layered on top of this library, without needing to worry about re-establishing failed connections as each call will automatically attempt to do so.
It also does not implement any form of timeout; again, this should be layered on top.
Finally, note that it is possible that a call may actually be received twice by the modbus device. For example, it could be that the command was successfully received by the reply failed to be delivered. This library should thus only be used if the calls are idempotent.
For simple use cases, use either [new_tcp_slave
] for TCP/IP or
[new_rtu_slave
] for serial. The latter is a shortcut for cases where only
the device path and baud rate need to be set for the serial port. If other
options (such as parity) need to be changed, use [new_sync
]: it takes a
factory function that produces a connection. It only works for synchronous
connection functions.
For more advanced use cases, implement the [SyncConnector
] trait to specify
how to establish a connection (asynchronously). Then pass the implementation
to [RobustClient::new_context
].