16 releases

Uses old Rust 2015

0.4.0 Jul 2, 2017
0.3.4 Jun 2, 2016
0.3.3 Mar 20, 2016
0.3.2 Nov 6, 2015
0.0.2 Mar 29, 2015

#541 in Hardware support

Download history 3671/week @ 2023-06-07 3572/week @ 2023-06-14 4038/week @ 2023-06-21 3151/week @ 2023-06-28 3637/week @ 2023-07-05 4268/week @ 2023-07-12 3267/week @ 2023-07-19 3694/week @ 2023-07-26 3508/week @ 2023-08-02 3325/week @ 2023-08-09 3185/week @ 2023-08-16 3617/week @ 2023-08-23 3119/week @ 2023-08-30 3881/week @ 2023-09-06 3007/week @ 2023-09-13 2810/week @ 2023-09-20

13,338 downloads per month
Used in fewer than 54 crates

MIT license

631 lines


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.


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)


Add serial as a dependency in Cargo.toml:

serial = "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 std::env;
use std::io;
use std::time::Duration;

use std::io::prelude::*;
use serial::prelude::*;

fn main() {
    for arg in env::args_os().skip(1) {
        let mut port = serial::open(&arg).unwrap();
        interact(&mut port).unwrap();

fn interact<T: SerialPort>(port: &mut T) -> io::Result<()> {
    try!(port.reconfigure(&|settings| {


    let mut buf: Vec<u8> = (0..255).collect();

    try!(port.read(&mut buf[..]));



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


Copyright © 2015 David Cuddeback

Distributed under the MIT License.