Crates.io | modbus-rtu |
lib.rs | modbus-rtu |
version | 0.1.1 |
source | src |
created_at | 2024-09-12 07:42:37.385639 |
updated_at | 2024-10-08 06:10:59.526213 |
description | Create standard Modbus RTU request packets |
homepage | |
repository | |
max_upload_size | |
id | 1372556 |
size | 32,136 |
Modbus RTU crate for rust
Note: This crate is not yet complete. Only packet generation works.
use modbus_rtu::packet::{Request, RequestError, Response};
fn main() {
// Create a new request
let read_sensor_req: Request = Request::ReadInputRegisters {
slave: 0x01,
base_address: 0x0001,
quantity: 1
};
// Generate packet from the request
let packet: Vec<u8> = read_sensor_req.to_bytes().expect("fail");
// Somewhere to read and write
let port = ...;
// Send packet
let _ = port.write_all(&packet);
// Read response
let mut response = Response::from_request(read_sensor_req).unwrap();
let _ = port.read_exact(&mut response.buffer);
// response.analyze() <- WIP...
}