Expand description
Async serial port I/O as AsyncRead and AsyncWrite, with optional Stream support.
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.
§Features
stream(optional):Stream,TryStreamExt, andSerialPortStream::try_poll_next. Starts a background receive pump into an in-memory FIFO (poll-based thread on Unix,WaitCommEventthread on Windows). Withstreamenabled,AsyncReadandStreamshare that FIFO.tracing(optional): diagnostic logs.
§Read paths
| Platform | AsyncRead (no stream) | AsyncRead + Stream (stream feature) |
|---|---|---|
| Unix | Direct async-io poll on the port fd | Shared poll-based background thread → FIFO |
| Windows | Overlapped ReadFile + windows thread-pool | Shared background read thread → FIFO |
When stream is enabled, AsyncRead and Stream share the same background receive FIFO
(Unix and Windows).
§Write path
On Unix, AsyncWrite uses async-io. On Windows, overlapped
WriteFile with a windows thread-pool completion.
AsyncReadExt and AsyncWriteExt are re-exported from futures.
use serialport_stream::{new, AsyncReadExt, AsyncWriteExt};
let mut stream = new("/dev/ttyUSB0", 115200).open()?;
stream.write_all(b"PING\r\n").await?;
let mut buf = [0u8; 256];
let n = stream.read(&mut buf).await?;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).