pub struct Arbiter { /* private fields */ }Expand description
§Serial Port Arbiter
This is a Linux-only serial port library that offers the following benefits
over directly using /dev/tty:
- Opens the
/dev/ttyfile with flags for non-blocking access. - Sets the
termiosflags to use the TTY in raw mode. - Prevents deadlocks caused by input buffer starvation.
- Prevents data garbling by implementing transaction arbitration.
- Gracefully handles interrupts and timeout errors.
- Gracefully handles connection errors and automatically reconnects.
- Provides a more convenient API than the raw
io::Readandio::Write.
This is an “async-less” library, and it is intended to remain that way.
If you need asynchronous behavior, you can easily make it async-compatible in your own code.
Implementations§
Source§impl Arbiter
impl Arbiter
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new arbiter which will handle a serial port connection defined by the given serial port builder.
Sourcepub fn clear_rx_buff(&self) -> Result<()>
pub fn clear_rx_buff(&self) -> Result<()>
Clear the Rx buffer of the serial port.
Sourcepub fn transmit(&self, tx_bytes: Arc<[u8]>, deadline: Instant) -> Result<()>
pub fn transmit(&self, tx_bytes: Arc<[u8]>, deadline: Instant) -> Result<()>
Transmits data to the serial port.
Sourcepub fn transmit_str(
&self,
str: impl AsRef<str>,
deadline: Instant,
) -> Result<()>
pub fn transmit_str( &self, str: impl AsRef<str>, deadline: Instant, ) -> Result<()>
Transmits a string to the serial port. Returns any bytes received during transmission.
Sourcepub fn receive(
&self,
until: Option<u8>,
deadline: Option<Instant>,
) -> Result<Option<Vec<u8>>>
pub fn receive( &self, until: Option<u8>, deadline: Option<Instant>, ) -> Result<Option<Vec<u8>>>
Receives data from the serial port
Sourcepub fn receive_string(
&self,
until: Option<u8>,
deadline: Option<Instant>,
) -> Result<Option<String>>
pub fn receive_string( &self, until: Option<u8>, deadline: Option<Instant>, ) -> Result<Option<String>>
Receives data from the serial port and converts to a String
Sourcepub fn set_cooloff_duration(&self, cooloff: Option<Duration>)
pub fn set_cooloff_duration(&self, cooloff: Option<Duration>)
Change the duration of cooloff after disconnecting due to an error and before a new connection attempt is made. If set to None then another connect attepmpt is tried without any artificial delays.