Expand description
A wired M-Bus master, sans-I/O (EN 13757-2/-3): the frames a master sends, a readout that handles the frame count bit and multi-telegram replies, and a secondary-address search.
Nothing here opens a port or reads a clock. Each state machine says what to send and
how long to wait for a reply (Request); you write the bytes, wait, and hand back
what arrived (Readout::reply, Search::reply) or that nothing did
(Readout::timeout, Search::timeout).
use mbus_kit::master::{Event, Readout, Target};
let mut readout = Readout::new(Target::Primary(5));
while let Some(request) = readout.next_request() {
// port.write(request.bytes()); wait up to request.timeout_ms(Baud::B2400) for a frame …
let reply: &[u8] = replies.next().unwrap();
match readout.reply(reply) {
Event::Telegram(app) => {
for r in app.records().into_iter().flatten() {
println!("{}", r.unwrap());
}
}
Event::NeedMore => { /* read more bytes and call reply() again */ }
_ => {}
}
}
assert!(readout.is_complete()); // or readout.outcome(): why it is notHand reply exactly one frame (wired::scan finds it behind noise or an echo).
A readout delivers only telegrams from the meter it addresses and says how it ended
(Outcome): a telegram limit or a broken page is never “complete”.
Modules§
- ci
- CI values a master sends (EN 13757-3, m-bus.com 6.1).
Structs§
- Readout
- Read every telegram of one meter:
SND_NKE(primary) or selection (secondary), thenREQ_UD2with the frame count bit toggled until no more records follow, then deselection (secondary). A request without a valid reply is repeated with the same FCB,RETRIEStimes. When it is over,Readout::outcomesays whether every telegram was read, or why not. - Request
- A frame to send and how long to wait for its reply.
- Search
- A secondary-address search (wildcard scan): finds every meter on the bus.
- Secondary
Address - A secondary address to select, each part optional (a wildcard).
Enums§
- Baud
- Baud rates of wired M-Bus.
- Event
- What happened when a reply (or its absence) was handed to a state machine.
- Outcome
- How a readout ended: see
Readout::outcome. - Target
- Whom a readout reads.
Constants§
- RETRIES
- The default number of repetitions of a request that got no valid reply.
Functions§
- application_
reset - Reset a slave’s application layer (CI
50), optionally only one telegram type (the subcode: upper nibble the type, e.g.1xuser data, lower nibble the subtelegram). Also drops a readout selection back to the standard telegram. - deselect
- Deselect:
SND_NKEto the network-layer address. - link_
reset SND_NKE: reset the link layer of a slave (and its FCB); toNETWORK_LAYER, deselect.- request_
all_ data - Ask for all data in the next
REQ_UD2(global readout request, DIF7F). - response_
timeout_ ms - The response timeout at
baud: 330 bit times plus 50 ms (EN 13757-2 via m-bus.com 5.4), in milliseconds rounded up: 188 ms at 2400 Bd, 85 ms at 9600 Bd. - select
- Select a slave by secondary address (
SND_UDto addressFD, CI52, FCB = 1 as for every selection). A slave that matches answersE5and is then reached atNETWORK_LAYERuntil deselected; every other slave deselects itself. - select_
enhanced - Enhanced selection: also match the fabrication number (record
0C 78, 8 BCD digits;Nonewildcards it). For two meters that share an identification number. A slave that does not support it does not answer. - set_
baud - Switch a slave to another baud rate (CI
B8–BF). The slave acknowledges at the old rate and listens at the new one. - set_
primary_ address - Set a slave’s primary address (
SND_UD, CI51, record01 7A new).Nonefor the reserved addresses 251–255. Make sure first that nothing answers atnew(link_resetto it times out): two slaves on one address cannot be read. - set_
time - Set a slave’s clock (CI
51, record04 6Ddate and time, type F).