SerialFrame
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
Example
use serialport::*;
use serial_frame::SerialFrameSender;
use std::sync::mpsc::*;
use std::time::Duration;
use simple_logger;
fn main() {
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();
let linesend = SerialFrameSender::new(b'\n', serialport);
let (tx, rx) = channel();
let linestop = linesend.start(tx).unwrap();
while let Ok(line) = rx.recv_timeout(Duration::from_secs(2)) {
match line {
Ok(line) => {
println!("line is: {}", String::from_utf8_lossy(&line));
}
Err(e) => {
println!("Error: {:?}", e);
}
}
}
let e = linestop.stop();
println!("Stop: {:?}", e);
}