pub struct Serial(/* private fields */);Expand description
Represents the generic serial interface of a smart port.
Implementations§
Source§impl Serial
impl Serial
Sourcepub unsafe fn new(port: u8, baudrate: i32) -> Result<Self, Error>
pub unsafe fn new(port: u8, baudrate: i32) -> Result<Self, Error>
Constructs a new generic serial port.
§Safety
This function is unsafe because it allows the user to create multiple
mutable references to the same smart port interface. You likely want to
implement Robot::new() instead.
Sourcepub fn set_baudrate(&mut self, baudrate: i32) -> Result<(), Error>
pub fn set_baudrate(&mut self, baudrate: i32) -> Result<(), Error>
Changes the baudrate of the serial port.
Sourcepub fn get_read_avail(&self) -> Result<usize, Error>
pub fn get_read_avail(&self) -> Result<usize, Error>
Gets the number of bytes available to read in the input buffer of the serial port.
Sourcepub fn get_write_free(&self) -> Result<usize, Error>
pub fn get_write_free(&self) -> Result<usize, Error>
Gets the number of bytes free in the output buffer of the serial port.
Sourcepub fn peek_byte(&self) -> Result<u8, Error>
pub fn peek_byte(&self) -> Result<u8, Error>
Reads the next available byte in the input buffer of the serial port without removing it.
Sourcepub fn read_byte(&mut self) -> Result<u8, Error>
pub fn read_byte(&mut self) -> Result<u8, Error>
Reads the next available byte in the input buffer of the serial port.
Sourcepub fn write_byte(&mut self, byte: u8) -> Result<(), Error>
pub fn write_byte(&mut self, byte: u8) -> Result<(), Error>
Writes the given byte to the output buffer of the serial port.
Sourcepub fn read(&mut self, buffer: &mut [u8]) -> Result<usize, Error>
pub fn read(&mut self, buffer: &mut [u8]) -> Result<usize, Error>
Reads as many bytes as possible from the input buffer of the serial port into the given buffer, returning the number read.