Struct usbd_serial::SerialPort
source · pub struct SerialPort<'a, B, RS = DefaultBufferStore, WS = DefaultBufferStore>{ /* private fields */ }
Expand description
USB (CDC-ACM) serial port with built-in buffering to implement stream-like behavior.
The RS and WS type arguments specify the storage for the read/write buffers, respectively. By default an internal 128 byte buffer is used for both directions.
Implementations§
source§impl<'a, B> SerialPort<'a, B>where
B: UsbBus,
impl<'a, B> SerialPort<'a, B>where
B: UsbBus,
sourcepub fn new<'alloc: 'a>(
alloc: &'alloc UsbBusAllocator<B>
) -> SerialPort<'a, B, DefaultBufferStore, DefaultBufferStore>
pub fn new<'alloc: 'a>( alloc: &'alloc UsbBusAllocator<B> ) -> SerialPort<'a, B, DefaultBufferStore, DefaultBufferStore>
Creates a new USB serial port with the provided UsbBus and 128 byte read/write buffers.
sourcepub fn new_with_interface_names<'alloc: 'a>(
alloc: &'alloc UsbBusAllocator<B>,
comm_if_name: Option<&'static str>,
data_if_name: Option<&'static str>
) -> SerialPort<'a, B, DefaultBufferStore, DefaultBufferStore>
pub fn new_with_interface_names<'alloc: 'a>( alloc: &'alloc UsbBusAllocator<B>, comm_if_name: Option<&'static str>, data_if_name: Option<&'static str> ) -> SerialPort<'a, B, DefaultBufferStore, DefaultBufferStore>
Same as SerialPort::new, but allows specifying the names of the interfaces
source§impl<'a, B, RS, WS> SerialPort<'a, B, RS, WS>
impl<'a, B, RS, WS> SerialPort<'a, B, RS, WS>
sourcepub fn new_with_store<'alloc: 'a>(
alloc: &'alloc UsbBusAllocator<B>,
read_store: RS,
write_store: WS
) -> SerialPort<'a, B, RS, WS>
pub fn new_with_store<'alloc: 'a>( alloc: &'alloc UsbBusAllocator<B>, read_store: RS, write_store: WS ) -> SerialPort<'a, B, RS, WS>
Creates a new USB serial port with the provided UsbBus and buffer backing stores.
sourcepub fn new_with_store_and_interface_names<'alloc: 'a>(
alloc: &'alloc UsbBusAllocator<B>,
read_store: RS,
write_store: WS,
comm_if_name: Option<&'static str>,
data_if_name: Option<&'static str>
) -> SerialPort<'a, B, RS, WS>
pub fn new_with_store_and_interface_names<'alloc: 'a>( alloc: &'alloc UsbBusAllocator<B>, read_store: RS, write_store: WS, comm_if_name: Option<&'static str>, data_if_name: Option<&'static str> ) -> SerialPort<'a, B, RS, WS>
Creates a new USB serial port with the provided UsbBus and buffer backing stores.
sourcepub fn line_coding(&self) -> &LineCoding
pub fn line_coding(&self) -> &LineCoding
Gets the current line coding.
sourcepub fn write(&mut self, data: &[u8]) -> Result<usize>
pub fn write(&mut self, data: &[u8]) -> Result<usize>
Writes bytes from data
into the port and returns the number of bytes written.
§Errors
WouldBlock
- No bytes could be written because the buffers are full.
Other errors from usb-device
may also be propagated.
sourcepub fn read(&mut self, data: &mut [u8]) -> Result<usize>
pub fn read(&mut self, data: &mut [u8]) -> Result<usize>
Reads bytes from the port into data
and returns the number of bytes read.
§Errors
WouldBlock
- No bytes available for reading.
Other errors from usb-device
may also be propagated.
sourcepub fn flush(&mut self) -> Result<()>
pub fn flush(&mut self) -> Result<()>
Sends as much as possible of the current write buffer. Returns Ok
if all data that has
been written has been completely written to hardware buffers Err(WouldBlock)
if there is
still data remaining, and other errors if there’s an error sending data to the host. Note
that even if this method returns Ok
, data may still be in hardware buffers on either side.
Trait Implementations§
source§impl<Bus: UsbBus, RS: BorrowMut<[u8]>, WS: BorrowMut<[u8]>> ErrorType for SerialPort<'_, Bus, RS, WS>
impl<Bus: UsbBus, RS: BorrowMut<[u8]>, WS: BorrowMut<[u8]>> ErrorType for SerialPort<'_, Bus, RS, WS>
source§impl<Bus: UsbBus, RS: BorrowMut<[u8]>, WS: BorrowMut<[u8]>> Read for SerialPort<'_, Bus, RS, WS>
impl<Bus: UsbBus, RS: BorrowMut<[u8]>, WS: BorrowMut<[u8]>> Read for SerialPort<'_, Bus, RS, WS>
source§fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>
source§fn read_exact(
&mut self,
buf: &mut [u8]
) -> Result<(), ReadExactError<Self::Error>>
fn read_exact( &mut self, buf: &mut [u8] ) -> Result<(), ReadExactError<Self::Error>>
buf
. Read moresource§impl<Bus: UsbBus, RS: BorrowMut<[u8]>, WS: BorrowMut<[u8]>> ReadReady for SerialPort<'_, Bus, RS, WS>
impl<Bus: UsbBus, RS: BorrowMut<[u8]>, WS: BorrowMut<[u8]>> ReadReady for SerialPort<'_, Bus, RS, WS>
source§impl<B, RS, WS> UsbClass<B> for SerialPort<'_, B, RS, WS>
impl<B, RS, WS> UsbClass<B> for SerialPort<'_, B, RS, WS>
source§fn get_configuration_descriptors(
&self,
writer: &mut DescriptorWriter<'_>
) -> Result<()>
fn get_configuration_descriptors( &self, writer: &mut DescriptorWriter<'_> ) -> Result<()>
writer
. The configuration descriptor itself will be written by
UsbDevice and shouldn’t be written by classes. Read moresource§fn get_string(&self, index: StringIndex, lang_id: LangID) -> Option<&str>
fn get_string(&self, index: StringIndex, lang_id: LangID) -> Option<&str>
source§fn endpoint_in_complete(&mut self, addr: EndpointAddress)
fn endpoint_in_complete(&mut self, addr: EndpointAddress)
addr
has completed transmitting data (IN packet). Read moresource§fn control_in(&mut self, xfer: ControlIn<'_, '_, '_, B>)
fn control_in(&mut self, xfer: ControlIn<'_, '_, '_, B>)
source§fn control_out(&mut self, xfer: ControlOut<'_, '_, '_, B>)
fn control_out(&mut self, xfer: ControlOut<'_, '_, '_, B>)
source§fn get_bos_descriptors(
&self,
writer: &mut BosWriter<'_, '_>
) -> Result<(), UsbError>
fn get_bos_descriptors( &self, writer: &mut BosWriter<'_, '_> ) -> Result<(), UsbError>
writer
. The BOS descriptor itself will be written by
UsbDevice and shouldn’t be written by classes.source§fn endpoint_setup(&mut self, addr: EndpointAddress)
fn endpoint_setup(&mut self, addr: EndpointAddress)
addr
has received a SETUP packet. Implementing this
shouldn’t be necessary in most cases, but is provided for completeness’ sake. Read moresource§fn endpoint_out(&mut self, addr: EndpointAddress)
fn endpoint_out(&mut self, addr: EndpointAddress)
addr
has received data (OUT packet). Read more