serial_frame

Crates.ioserial_frame
lib.rsserial_frame
version0.3.0
sourcesrc
created_at2019-12-03 10:04:31.026692
updated_at2020-01-21 09:54:00.206382
descriptionSends byte chunks over a channel, split using given delimiter
homepage
repositoryhttps://github.com/TotalKrill/serial_frame
max_upload_size
id186102
size28,354
(TotalKrill)

documentation

README

SerialFrame

Latest version License

Simple serialport frame reciever, that asynchrounous sends chunks of bytes over an mpsc channel. the chunks are sent with the chosen delimiter.

Can be used to recieve lines over serialports in an asynchronous manner, or to recieve cobs messages, or custom parsing to whatever type you want from the chunks

See the example for an example usage for just receiving lines

Example

use serialport::prelude::*;
use simple_logger;

use std::time::Duration;

use serial_frame::{create_line_sender};

fn main() {
    // Setup the serialport to act on
    let serialport: Box<dyn SerialPort> = init();

    // get a Reciever for strings that all end with a newline
    let (rx, linestop) = create_line_sender(serialport).unwrap();

    // Recieve the lines, stop if timeout
    while let Ok(line) = rx.recv_timeout(Duration::from_secs(2)) {
        // Inspect the received line
        println!("line is: {}", line);
    }
    // This will end the thread if it not stopped
    let e = linestop.stop();
    println!("Stop: {:?}", e);
}

fn init() -> Box<dyn SerialPort> {
    simple_logger::init_with_level(log::Level::Debug).unwrap();

    let mut settings: SerialPortSettings = Default::default();
    settings.timeout = Duration::from_millis(100);
    let baudrate = 115200;
    settings.baud_rate = baudrate;
    let serialport = serialport::open_with_settings("/dev/ttyACM0", &settings).unwrap();
    serialport
}

Commit count: 3

cargo fmt