pub fn serial(path: impl AsRef<Path>, baud: u32) -> Result<File, OpenError>Expand description
The serial port a USB card’s bridge answers on, opened raw.
A CDC-ACM device such as /dev/ttyACM0 is a terminal as far as the kernel is concerned,
and a terminal echoes, translates line endings, and buffers by line, every one of which
would mangle a binary protocol. This opens the port and turns all of that off: eight data
bits, no parity, one stop bit, no flow control, and a read that returns once at least one
byte has arrived. Whatever the card sent before anyone was listening is dropped.
The speed is nominal, since a USB serial port has none, but the port has to be given one.
§Arguments
path- the device file.baud- the nominal speed, one of the standard rates from 9600 to 921600.
§Returns
The open port, which reads and writes bytes.
§Errors
OpenError::Serial when the file cannot be opened, the rate is not a standard one, or
the terminal settings cannot be read or applied.
§Examples
use pamoja_hal::linux;
let port = linux::serial("/dev/ttyACM0", 115_200)?;