Serial
The serial crate provides Rust programs with access to serial ports. Serial ports are defined as
traits to support extension through custom implementations. Unix TTY devices and Windows COM ports
are supported out of the box.
Compatibility
The serial crate is compatible with Windows and any Unix operating system that implements the
termios API. The following platforms are confirmed to be compatible:
- Linux (x86_64, armv6l)
- OS X (x86_64)
- FreeBSD (amd64)
- OpenBSD (amd64)
- Windows (x86_64)
Usage
Add serial as a dependency in Cargo.toml:
[]
= "0.4"
Import the serial crate and everything from the serial::prelude module. The traits in the
serial::prelude module are are useful to have in scope when working with serial ports, and they
are unlikely to conflict with other crates.
To open a serial port, call serial::open() with any type that's convertable to OsStr. With an
open serial port, you can interact with it using the SerialPort trait. By depending on the traits,
your code will support future implementations of serial ports, including custom implementations.
extern crate serial;
use env;
use io;
use Duration;
use *;
use *;
Cross-Compiling
Cross-compiling the serial crate requires only that the --target option is provided to cargo build. The following is an example of cross-compiling for arm-unknown-linux-gnueabihf (Raspberry
Pi):
cargo build --target=arm-unknown-linux-gnueabihf
License
Copyright © 2015 David Cuddeback
Distributed under the MIT License.