Crate serialport5
source ·Expand description
serialport-rs is a cross-platform serial port library.
The goal of this library is to expose a cross-platform and platform-specific API for enumerating
and using blocking I/O with serial ports. This library exposes a similar API to that provided
by Qt’s QSerialPort
library.
§Feature Overview
The library provides a single SerialPort
type which works across the supported platforms. Some
platform-specific functionality is available through platform-specific extension traits provided
in the posix
and windows
modules, which can be imported when platform-specific functions are
needed.
To open a SerialPort
, create a builder with SerialPort::builder()
. The SerialPortBuilder
can be used to customize settings such as baud rate, number of data bits, flow control, parity
and timeouts before opening the port. Note that most of these settings can be changed after opening
as well, but they are provided on the builder for convenience.
For normal reading and writing, SerialPort
implements the standard Read
and
Write
traits.
use std::io::Read;
use serialport5::SerialPort;
let mut port = SerialPort::builder().baud_rate(115200).open("/dev/ttyUSB0")?;
let mut buf = [0u8; 1024];
let bytes_read = port.read(&mut buf[..])?;
println!("Read {} bytes: {:?}", bytes_read, &buf[..bytes_read]);
SerialPort
instances are thread-safe, and both read and write are implemeted for both
SerialPort
and &SerialPort
. This allows you to share a single SerialPort
instance
between threads without locking. This is primarily intended to allow having 1 thread for
reading and 1 thread for writing. It is also possible to get separate SerialPort instances
which have the same underlying serial device using try_clone
.
Modules§
- Provides unix-only extensions to the SerialPort type.
- Provides windows-only extensions to the SerialPort type.
Structs§
- An error type for serial port operations
- A Serial Port device.
- A struct containing all serial port settings
- A device-independent implementation of serial port information
- Contains all possible USB information about a
SerialPort
Enums§
- Specifies which buffer or buffers to purge when calling
clear
- Number of bits per character
- Categories of errors that can occur when interacting with serial ports
- Flow control modes
- Parity checking modes
- The physical type of a
SerialPort
- Number of stop bits
Functions§
- Returns a list of all serial ports on system
Type Aliases§
- A type for results generated by interacting with serial ports