pub struct SerialInterface { /* private fields */ }

Implementations§

source§

impl SerialInterface

source

pub fn new() -> Result<Self, SerialInterfaceError>

source

pub fn path(self, path: String) -> Self

source

pub fn bauds(self, bauds: BaudRate) -> Self

source

pub fn char_size(self, size: CharSize) -> Self

source

pub fn parity(self, parity: Parity) -> Self

source

pub fn stop_bits(self, stop_bits: StopBits) -> Self

source

pub fn flow_control(self, flow_control: FlowControl) -> Self

source

pub fn mode(self, mode: Mode) -> Result<Self, SerialInterfaceError>

source

pub fn modbus_id(self, modbus_id: u8) -> Self

source

pub fn silence(self, silence: Duration) -> Self

source

pub fn receiver(self, receiver: Receiver<SerialMessage>) -> Self

source

pub fn sender(self, sender: Sender<SerialMessage>) -> Self

source

pub fn set_mode(&mut self, m: Mode) -> Result<(), SerialInterfaceError>

source

pub fn get_mode(&self) -> &Mode

source

pub fn get_state(&self) -> &Status

source

pub fn list_ports() -> Result<Vec<String>, SerialInterfaceError>

source

pub fn open(&mut self) -> Result<(), SerialInterfaceError>

Open the serial port.

source

pub fn close(&mut self) -> Result<(), SerialInterfaceError>

Close the serial port.

source

pub async fn listen(&mut self) -> Result<Option<Mode>, SerialInterfaceError>

Sniffing feature: listen on serial line and send a SerialMessage::Receive() via mpsc channel for every serial request received, for every loop iteration, check if a SerialMessage is arrived via mpsc channel. If receive a SerialMessage::Send(), pause listen in order to send message then resume listening. Stop listening if receive SerialMessage::SetMode(Stop). Almost SerialMessage are handled silently by self.read_message().

source

pub async fn write_read( &mut self, data: Vec<u8>, timeout: &Duration ) -> Result<Option<SerialMessage>, SerialInterfaceError>

Master feature: write a request, then wait for response, when response received, stop listening. Returns early if receive SerialMessage::SetMode(Mode::Stop)). Does not accept SerialMessage::Send() as we already waiting for a response. Almost SerialMessage are handled silently by self.read_message().

source

pub async fn wait_for_request( &mut self ) -> Result<Option<SerialMessage>, SerialInterfaceError>

Slave feature: listen the line until request receive, then stop listening. Returns early if receive SerialMessage::SetMode(Mode::Stop) or SerialMessage::Send(). Almost SerialMessage are handled silently by self.read_message().

source

pub async fn start(&mut self)

Main loop

Auto Trait Implementations§

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.