modbus-rtu

Crates.iomodbus-rtu
lib.rsmodbus-rtu
version0.1.1
sourcesrc
created_at2024-09-12 07:42:37.385639
updated_at2024-10-08 06:10:59.526213
descriptionCreate standard Modbus RTU request packets
homepage
repository
max_upload_size
id1372556
size32,136
박지수 (foolkat)

documentation

README

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...
}
Commit count: 0

cargo fmt