Expand description
Async serial port I/O as Stream, AsyncRead, and AsyncWrite.
Async runtime agnostic: this crate implements futures traits only and does not depend on
Tokio, async-std, or any other executor. Use it with any runtime that polls those futures
(Tokio, async-std, [futures_lite::future::block_on], etc.).
Configure and open ports with new → SerialPortStreamBuilder → .open().
Line settings, DTR, and buffer clearing are applied at open time.
POSIX termios on Unix; Win32 COMM APIs on Windows. Configuration types (DataBits,
Parity, StopBits, FlowControl, ClearBuffer) are defined in this crate.
Optional [tracing] logs (EAGAIN/EINTR retries, receive-buffer diagnostics) are enabled with
the tracing Cargo feature.
The first read poll starts a background thread that appends incoming bytes to an in-memory FIFO
shared by Stream and AsyncRead. There is no backpressure.
Stream / TryStreamExt::try_next drains the full FIFO per item; AsyncRead reads
partially and leaves the remainder cached. Use one read style per open port.
AsyncWriteExt, AsyncReadExt, and TryStreamExt are re-exported from futures.
use serialport_stream::{new, AsyncWriteExt, TryStreamExt};
let mut stream = new("/dev/ttyUSB0", 115200).open()?;
stream.write_all(b"PING\r\n").await?;
while let Some(chunk) = stream.try_next().await? {
println!("{chunk:?}");
}Modules§
Structs§
- Serial
Port Stream - An opened serial port for async reads and writes.
- Serial
Port Stream Builder - Builder for serial port path, line settings, and one-shot open options.
Enums§
- Clear
Buffer - Buffer(s) to clear.
- Data
Bits - Number of data bits per character.
- Flow
Control - Flow control mode.
- Parity
- Parity checking mode.
- Stop
Bits - Number of stop bits.
Traits§
- Async
Read - Read bytes asynchronously.
- Async
Read Ext - An extension trait which adds utility methods to
AsyncReadtypes. - Async
Write - Write bytes asynchronously.
- Async
Write Ext - An extension trait which adds utility methods to
AsyncWritetypes. - Stream
- A stream of values produced asynchronously.
- TryStream
Ext - Adapters specific to
Result-returning streams
Functions§
- new
- Creates a
SerialPortStreamBuilderwith default line settings (8N1, no flow control).