pub struct Line { /* private fields */ }Expand description
Several servers on one simulated line, as devices share an RS485 pair: every frame reaches all of them, the one it is addressed to answers, and each carries out a broadcast write.
A line is a Peer, so a
SerialPort::simulated port with a line on
the far end is a bus of devices a Client polls. Each server is kept
behind a shared handle, so a program looks at what a write did to it afterward.
§Examples
use pamoja_hal::port::{Parity, SerialPort, Settings};
use pamoja_modbus::{Client, Line, Server};
let mut line = Line::new();
let meter = line.attach(Server::new(17)?.with_input_registers(0, &[2301]));
let pump = line.attach(Server::new(18)?.with_coils(0, &[false]));
let settings = Settings::new(19_200).with_parity(Parity::Even);
let mut client = Client::new(SerialPort::simulated(settings, line));
assert_eq!(client.read_input_registers(17, 0, 1)?, [2301]);
client.write_single_coil(18, 0, true)?;
assert_eq!(pump.lock().unwrap().coil(0), Some(true));
assert_eq!(meter.lock().unwrap().served(), 1);Implementations§
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Line
impl RefUnwindSafe for Line
impl Send for Line
impl Sync for Line
impl Unpin for Line
impl UnsafeUnpin for Line
impl UnwindSafe for Line
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more