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 drops what is still waiting in the port, writes each request, removes a converter’s echo of it, and reads the reply until the line has been quiet for 40 ms (or the slack) plus three character times. Bytes behind a valid frame make the reply garbled: two slaves answered.

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. A TcpStream also reads Ok(0) once the gateway has closed it, which looks like a silent bus: wrap it if that must be an error.

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.