Crate framed_serial [] [src]

Add frames to serial connections. Useful for embedded devices. Can be built with no_std.

The main type of interest is FramedConnection, which takes ownership of a serial connection and allows sending and receiving complete frames.

To use with the standard library, put this in your Cargo.toml:

framed-serial = "0.1"

To use in an embedded device with no_std, put this in your Cargo.toml:

framed-serial = {version = "0.1", default-features = false, features = ["collections"]}

Example usage:

#[cfg(feature = "std")]
extern crate serial;
extern crate framed_serial;
#[cfg(feature = "std")]
use serial::SerialPort;

#[cfg(feature = "std")]
fn wait_for_frame() -> Result<(),framed_serial::Error> {

    let device = match std::env::var("DEVICE") {
        Ok(val) => val,
        Err(_) => "/dev/ttyACM0".to_string(),
    println!("opening device {}", device);
    let mut raw = serial::open(&device).expect("open serial port");

    // Async processing depends on this being short.

    let my_ser = framed_serial::SerialWrap::new(raw);
    let mut conn = framed_serial::FramedConnection::new(my_ser);

    // Loop until we get a frame. This requires a connected device
    // sending with FramedConnection.
    loop {
        let tick_state = conn.tick()?;
        if tick_state.recv_is_done {
            let data = conn.get_frame()?;
            println!("{:?}", data);

// This example requires std to compile. To run successfully, it further requires a connected
// serial device on /dev/ttyACM0 implementing `FramedConnection`. Use conditional compilation
// to run only if the `device_connected` feature was specified at compile time.

#[cfg(feature = "device_connected")]
fn main() {
#[cfg(not(feature = "device_connected"))]
fn main() {
    // Do nothing if device is not connected.



Error type.


Wrapper around a serial port to provide framed connections.


Implment the traits required for a FramedConnection based on a serial::SerialPort.


The result of a tick(). Check for progress indication.



A marker which appears only rarely in stream, used to catch frame start.