#modbus #packet #request #standard #generation #response #rtu

modbus-rtu

Create standard Modbus RTU request packets

2 releases

0.1.1 Oct 8, 2024
0.1.0 Sep 12, 2024

#414 in Hardware support

Download history 89/week @ 2024-09-07 39/week @ 2024-09-14 14/week @ 2024-09-21 5/week @ 2024-09-28 171/week @ 2024-10-05 21/week @ 2024-10-12

213 downloads per month

MIT license

32KB
446 lines

rust-modbus-rtu

Modbus RTU crate for rust

Note: This crate is not yet complete. Only packet generation works.

Usage

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

No runtime deps