Struct serial_port::SerialPort
source · pub struct SerialPort { /* private fields */ }
Expand description
A serial port abstraction with support for interrupt-based data receival.
Implementations§
source§impl SerialPort
impl SerialPort
sourcepub fn new(serial_port: SerialPortBasic) -> SerialPort
pub fn new(serial_port: SerialPortBasic) -> SerialPort
Initialize this serial port by giving it ownership and control of
the given basic serial_port
.
sourcepub fn register_interrupt_handler(
serial_port: Arc<IrqSafeMutex<SerialPort>>,
interrupt_number: InterruptNumber,
interrupt_handler: InterruptHandler
) -> Result<(), &'static str>
pub fn register_interrupt_handler( serial_port: Arc<IrqSafeMutex<SerialPort>>, interrupt_number: InterruptNumber, interrupt_handler: InterruptHandler ) -> Result<(), &'static str>
Register the interrupt handler for this serial port and spawn a deferrent interrupt task to handle its data receival.
sourcepub fn set_data_sender(
&mut self,
sender: Sender<DataChunk>
) -> Result<(), DataSenderAlreadyExists>
pub fn set_data_sender( &mut self, sender: Sender<DataChunk> ) -> Result<(), DataSenderAlreadyExists>
Tells this SerialPort
to push received data bytes
onto the given sender
channel.
If a sender already exists for this serial port, the existing sender is not replaced and an error is returned.
Methods from Deref<Target = SerialPortBasic>§
pub fn enable_interrupt(
&mut self,
event: SerialPortInterruptEvent,
enable: bool
)
pub fn enable_interrupt( &mut self, event: SerialPortInterruptEvent, enable: bool )
Enable or disable interrupts on this serial port for various events.
pub fn acknowledge_interrupt(&mut self, _event: SerialPortInterruptEvent)
pub fn acknowledge_interrupt(&mut self, _event: SerialPortInterruptEvent)
Clears an interrupt in the serial port controller
pub fn out_str(&mut self, s: &str)
pub fn out_str(&mut self, s: &str)
Write the given string to the serial port, blocking until data can be transmitted.
Special characters
Because this function writes strings, it will transmit a carriage return '\r'
after transmitting a line feed (new line) '\n'
to ensure a proper new line.
pub fn out_byte(&mut self, byte: u8)
pub fn out_byte(&mut self, byte: u8)
Write the given byte to the serial port, blocking until data can be transmitted.
This writes the byte directly with no special cases, e.g., new lines.
pub fn out_bytes(&mut self, bytes: &[u8])
pub fn out_bytes(&mut self, bytes: &[u8])
Write the given bytes to the serial port, blocking until data can be transmitted.
This writes the bytes directly with no special cases, e.g., new lines.
pub fn in_byte(&mut self) -> u8
pub fn in_byte(&mut self) -> u8
Read one byte from the serial port, blocking until data is available.
pub fn in_bytes(&mut self, buffer: &mut [u8]) -> usize
pub fn in_bytes(&mut self, buffer: &mut [u8]) -> usize
Reads multiple bytes from the serial port into the given buffer
, non-blocking.
The buffer will be filled with as many bytes as are available in the serial port. Once data is no longer available to be read, the read operation will stop.
If no data is immediately available on the serial port, this will read nothing and return 0
.
Returns the number of bytes read into the given buffer
.
pub fn ready_to_transmit(&self) -> bool
pub fn ready_to_transmit(&self) -> bool
Returns true
if the serial port is ready to transmit a byte.
pub fn data_available(&self) -> bool
pub fn data_available(&self) -> bool
Returns true
if the serial port has data available to read.
pub fn base_port_address(&self) -> SerialPortAddress
Trait Implementations§
source§impl Deref for SerialPort
impl Deref for SerialPort
source§impl DerefMut for SerialPort
impl DerefMut for SerialPort
source§impl Read for SerialPort
impl Read for SerialPort
A non-blocking implementation of [core2::io::Read
] that will read bytes into the given buf
so long as more bytes are available.
The read operation will be completed when there are no more bytes to be read,
or when the buf
is filled, whichever comes first.
Because it’s non-blocking, a [core2::io::ErrorKind::WouldBlock
] error is returned
if there are no bytes available to be read, indicating that the read would block.
source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
§fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
buf
. Read more§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf
. Read more§unsafe fn initializer(&self) -> Initializer
unsafe fn initializer(&self) -> Initializer
Read
er can work with buffers of uninitialized
memory. Read more§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf
. Read more§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere Self: Sized,
Read
. Read moresource§impl Write for SerialPort
impl Write for SerialPort
A blocking implementation of [core2::io::Write
] that will write bytes from the given buf
to the SerialPort
, waiting until it is ready to transfer all bytes.
The flush()
function is a no-op, since the SerialPort
does not have buffering.
source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
source§impl Write for SerialPort
impl Write for SerialPort
Forward the implementation of core::fmt::Write
to the inner SerialPortBasic
.