Skip to main content

Line

Struct Line 

Source
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§

Source§

impl Line

Source

pub fn new() -> Line

Makes a line with no devices on it.

Source

pub fn attach(&mut self, server: Server) -> Arc<Mutex<Server>> ⓘ

Puts a device on the line.

§Arguments
  • server - the device.
§Returns

A shared handle to it, for looking at it or changing its tables later.

Source

pub fn attach_shared(&mut self, server: Arc<Mutex<Server>>)

Puts a device the program already shares on the line.

§Arguments
  • server - the shared device.
Source

pub fn units(&self) -> Vec<u8> ⓘ

Returns the unit addresses on the line, in the order they were attached.

Trait Implementations§

Source§

impl Clone for Line

Source§

fn clone(&self) -> Line

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Line

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Line

Source§

fn default() -> Line

Returns the “default value” for a type. Read more
Source§

impl Peer for Line

Available on crate feature port only.
Source§

fn receive(&mut self, bytes: &[u8]) -> Vec<u8> ⓘ

Takes the bytes the port wrote and returns the bytes the device sends back. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.