modbus-rtu
This crate provides helpers for building and decoding standard Modbus RTU request and response packets.
Usage
Sending
First, construct the function you want to issue.
The following example reads four input registers starting at address 0x1234.
use Function;
let starting_address: u16 = 0x1234;
let quantity: usize = 4;
let function = ReadInputRegisters ;
Next, build the request with the target device information and timeout.
use ;
...
let modbus_id: u8 = 1;
let timeout: Duration = from_millis;
let request = new;
Finally, convert the request into a Modbus RTU frame.
...
let packet: = request.to_bytes.expect;
Sending the bytes to an actual device is not yet implemented in this crate.
Receiving
Receiving bytes from a physical device is also outside the scope of this crate. This example assumes you already obtained the raw response bytes.
With the original request available, attempt to decode the response bytes as shown below.
use Response;
...
let bytes: & = ... ; // user-implemented receive logic
let response = from_bytes.expect;
match response