MCPcopy Index your code
hub / github.com/de-vri-es/serial2-tokio-rs

github.com/de-vri-es/serial2-tokio-rs @v0.1.24

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.1.24 ↗ · + Follow
70 symbols 103 edges 6 files 19 documented · 27%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

serial2-tokio

Serial port communication for [tokio] using [serial2].

The serial2-tokio crate provides a cross-platform interface to serial ports. It aims to provide a simpler interface than other alternatives.

Currently supported features: * Simple interface: one [SerialPort] struct for all supported platforms. * List available ports. * Custom baud rates on all supported platforms except Solaris and Illumos. * Concurrent reads and writes from multiple tasks, even on Windows. * Purge the OS buffers (useful to discard read noise when the line should have been silent, for example). * Read and control individual modem status lines to use them as general purpose I/O. * Cross platform configuration of serial port settings: * Baud rate * Character size * Stop bits * Parity checks * Flow control * Read/write timeouts

You can open and configure a serial port in one go with [SerialPort::open()]. The second argument to open() must be a type that implements [IntoSettings]. In the simplest case, it is enough to pass a u32 for the baud rate. Doing that will also configure a character size of 8 bits with 1 stop bit and disables parity checks and flow control. For full control over the applied settings, pass a closure that receives the the current [Settings] and return the desired settings. If you do, you will almost always want to call [Settings::set_raw()] before changing any other settings.

The [SerialPort] struct implements the standard [tokio::io::AsyncRead] and [tokio::io::AsyncWrite] traits, as well as [read()][SerialPort::read()] and [write()][SerialPort::write()] functions that take &self instead of &mut self. This allows you to use the serial port concurrently from multiple tasks.

The [SerialPort::available_ports()] function can be used to get a list of available serial ports on supported platforms.

Example

This example opens a serial port and echoes back everything that is read.

use serial2_tokio::SerialPort;

// On Windows, use something like "COM1" or "COM15".
let port = SerialPort::open("/dev/ttyUSB0", 115200)?;
let mut buffer = [0; 256];
loop {
    let read = port.read(&mut buffer).await?;
    port.write_all(&buffer[..read]).await?;
}

Core symbols most depended-on inside this repo

with_raw
called by 13
src/inner/unix.rs
check_ret
called by 7
src/inner/unix.rs
read
called by 2
src/lib.rs
write
called by 2
src/lib.rs
with_raw
called by 2
src/inner/windows.rs
read
called by 2
src/inner/windows.rs
write
called by 2
src/inner/windows.rs
poll_write
called by 2
src/inner/windows.rs

Shape

Method 61
Function 6
Class 3

Languages

Rust100%

Modules by API surface

src/lib.rs32 symbols
src/inner/unix.rs17 symbols
src/inner/windows.rs16 symbols
examples/serial-cat.rs4 symbols
tests/pair.rs1 symbols

For agents

$ claude mcp add serial2-tokio-rs \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page