[][src]Trait saberrs::SabertoothSerial

pub trait SabertoothSerial: Write + Read {
    fn set_timeout(&mut self, timeout: Duration) -> Result<()>;
fn timeout(&self) -> Duration;
fn set_baud_rate(&mut self, baud_rate: u32) -> Result<()>;
fn baud_rate(&self) -> Result<u32>;
fn clear_all(&self) -> Result<()>; }

Minimal serial port trait.

The Sabertooth interfaces will rely on this trait for low level communications. In most cases there is no need to handle this trait or its implementors manually, it is better to use an interface constructor directly, for ex. PacketSerial::new("/dev/ttyS0"). A case where it would be useful to manipulate this trait is when a particular serial setting is required.

Example

use std::time::Duration;
use saberrs::{Result, SabertoothSerial, SabertoothPort};
use saberrs::sabertooth2x32::PacketSerial;

// Open a serial port with secific baud rate and timeout.
let mut dev = SabertoothPort::new("/dev/ttyS2")?;
dev.set_baud_rate(19200)?;
dev.set_timeout(Duration::from_secs(5))?;

// Use it with a PacketSerial interface.
let mut saber = PacketSerial::from(dev);

Required methods

fn set_timeout(&mut self, timeout: Duration) -> Result<()>

Set the timeout of the serial port.

fn timeout(&self) -> Duration

Get the current timeout setting of the serial port.

fn set_baud_rate(&mut self, baud_rate: u32) -> Result<()>

Set the baud rate of the serial port.

fn baud_rate(&self) -> Result<u32>

Get the current baud rate setting of the serial port.

fn clear_all(&self) -> Result<()>

Clear the tx and rx buffer, remaining bytes will be lost.

Loading content...

Implementors

impl SabertoothSerial for SabertoothPort[src]

impl SabertoothSerial for SabertoothPortShared[src]

Loading content...