Skip to main content

Crate serialport_stream

Crate serialport_stream 

Source
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 newSerialPortStreamBuilder.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§

line_settings

Structs§

SerialPortStream
An opened serial port for async reads and writes.
SerialPortStreamBuilder
Builder for serial port path, line settings, and one-shot open options.

Enums§

ClearBuffer
Buffer(s) to clear.
DataBits
Number of data bits per character.
FlowControl
Flow control mode.
Parity
Parity checking mode.
StopBits
Number of stop bits.

Traits§

AsyncRead
Read bytes asynchronously.
AsyncReadExt
An extension trait which adds utility methods to AsyncRead types.
AsyncWrite
Write bytes asynchronously.
AsyncWriteExt
An extension trait which adds utility methods to AsyncWrite types.
Stream
A stream of values produced asynchronously.
TryStreamExt
Adapters specific to Result-returning streams

Functions§

new
Creates a SerialPortStreamBuilder with default line settings (8N1, no flow control).