[][src]Struct usbd_serial::SerialPort

pub struct SerialPort<'a, B, RS = DefaultBufferStore, WS = DefaultBufferStore> where
    B: UsbBus,
    RS: BorrowMut<[u8]>,
    WS: BorrowMut<[u8]>, 
{ /* fields omitted */ }

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.

Methods

impl<'_, B> SerialPort<'_, B> where
    B: UsbBus
[src]

pub fn new(
    alloc: &UsbBusAllocator<B>
) -> SerialPort<B, DefaultBufferStore, DefaultBufferStore>
[src]

Creates a new USB serial port with the provided UsbBus and 128 byte read/write buffers.

impl<'_, B, RS, WS> SerialPort<'_, B, RS, WS> where
    B: UsbBus,
    RS: BorrowMut<[u8]>,
    WS: BorrowMut<[u8]>, 
[src]

pub fn new_with_store(
    alloc: &UsbBusAllocator<B>,
    read_store: RS,
    write_store: WS
) -> SerialPort<B, RS, WS>
[src]

Creates a new USB serial port with the provided UsbBus and buffer backing stores.

pub fn line_coding(&self) -> &LineCoding[src]

Gets the current line coding.

pub fn dtr(&self) -> bool[src]

Gets the DTR (data terminal ready) state

pub fn rts(&self) -> bool[src]

Gets the RTS (ready to send) state

pub fn write(&mut self, data: &[u8]) -> Result<usize>[src]

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.

pub fn read(&mut self, data: &mut [u8]) -> Result<usize>[src]

Reads bytes from the port into data and returns the number of bytes read.

Errors

Other errors from usb-device may also be propagated.

pub fn flush(&mut self) -> Result<()>[src]

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

impl<'_, B, RS, WS> UsbClass<B> for SerialPort<'_, B, RS, WS> where
    B: UsbBus,
    RS: BorrowMut<[u8]>,
    WS: BorrowMut<[u8]>, 
[src]

fn get_string(&self, index: StringIndex, lang_id: u16) -> Option<&str>[src]

Gets a class-specific string descriptor. Read more

fn poll(&mut self)[src]

Called whenever the UsbDevice is polled.

fn endpoint_setup(&mut self, addr: EndpointAddress)[src]

Called when endpoint with address addr has received a SETUP packet. Implementing this shouldn't be necessary in most cases, but is provided for completeness' sake. Read more

fn endpoint_out(&mut self, addr: EndpointAddress)[src]

Called when endpoint with address addr has received data (OUT packet). Read more

impl<'_, B, RS, WS> Write<u8> for SerialPort<'_, B, RS, WS> where
    B: UsbBus,
    RS: BorrowMut<[u8]>,
    WS: BorrowMut<[u8]>, 
[src]

type Error = UsbError

Write error

impl<'_, B, RS, WS> Read<u8> for SerialPort<'_, B, RS, WS> where
    B: UsbBus,
    RS: BorrowMut<[u8]>,
    WS: BorrowMut<[u8]>, 
[src]

type Error = UsbError

Read error

Auto Trait Implementations

impl<'a, B, RS, WS> Unpin for SerialPort<'a, B, RS, WS> where
    RS: Unpin,
    WS: Unpin

impl<'a, B, RS, WS> Sync for SerialPort<'a, B, RS, WS> where
    RS: Sync,
    WS: Sync

impl<'a, B, RS, WS> Send for SerialPort<'a, B, RS, WS> where
    RS: Send,
    WS: Send

Blanket Implementations

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]