Skip to main content

Module serial

Module serial 

Source
Available on crate feature std only.
Expand description

A blocking wired master over a real port (feature std): the sans-I/O state machines of master, driven over anything that is Read + Write.

That is a serial device of an M-Bus level converter (opened at 8E1 with a short read timeout, e.g. 10 ms, by any serial crate or stty), a TcpStream to an Ethernet M-Bus gateway, or a test double. The driver writes each request, reads until the state machine has a complete frame or the response timeout has passed, removes a converter’s echo of the request, and keeps collecting while bytes still arrive (a long frame at 2400 Bd takes more than a second).

use mbus_kit::master::{Baud, Target};
use mbus_kit::serial::Bus;

let mut bus = Bus::new(open(), Baud::B2400);
for telegram in bus.readout(Target::Primary(1))? {
    for record in telegram.application()?.records().into_iter().flatten() {
        println!("{}", record?);
    }
}

The port must not block forever on a read: give it a read timeout, or reads that return TimedOut, WouldBlock or Ok(0) when nothing arrived.

Structs§

Bus
A wired M-Bus behind a port.
Found
What a search found.
Telegram
One telegram of a readout, as received (a long frame).

Enums§

Error
What can go wrong on a real bus.