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.
Usage
Add serial as a dependency in Cargo.toml:
[]
= "0.2.0"
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 and SerialPortExt traits. By
depending on the traits, your code will support future implementations of serial ports, including
custom implementations.
extern crate serial;
extern crate time;
use env;
use io;
use Duration;
use *;
use *;
Cross-Compiling
Some of the serial crate's dependencies use the gcc crate in their build scripts, which requires
setting environment variables to ensure they compile properly. Compiling without the environment
variables set causes the following error when linking with the dependencies: could not read symbols: File format not recognized.
To cross-compile correctly, it's necessary to set CC or CC_<target> to an appropriate
cross-compiler in addition to providing the --target option to cargo build. The following is an
example of cross-compiling for arm-unknown-linux-gnueabihf (Raspberry Pi):
CC_arm_unknown_linux_gnueabihf=arm-linux-gnueabihf-gcc cargo build --target=arm-unknown-linux-gnueabihf
See the gcc crate's README for details.
Contributors
License
Copyright © 2015 David Cuddeback
Distributed under the MIT License.