Skip to main content

Crate serialport_stream

Crate serialport_stream 

Source
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 newSerialPortStreamBuilder.open(). Line settings, DTR, and buffer clearing are applied at open time.

§Features

§Read paths

PlatformAsyncRead (no stream)AsyncRead + Stream (stream feature)
UnixDirect async-io poll on the port fdShared poll-based background thread → FIFO
WindowsOverlapped ReadFile + windows thread-poolShared 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§

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).