Skip to content
Snippets Groups Projects
Commit faccd959 authored by Federico Lolli's avatar Federico Lolli
Browse files

add timeout to reading (waiting 200ms before emitting error)

parent c5c3fe8c
Branches
No related tags found
No related merge requests found
...@@ -6,6 +6,7 @@ use std::{ ...@@ -6,6 +6,7 @@ use std::{
Arc, Arc,
}, },
thread::{self, JoinHandle}, thread::{self, JoinHandle},
time::Duration,
}; };
use hashbrown::HashMap; use hashbrown::HashMap;
...@@ -83,7 +84,11 @@ impl SerialQueue { ...@@ -83,7 +84,11 @@ impl SerialQueue {
/// Open the serial port and start a thread to write data as soon as it is /// Open the serial port and start a thread to write data as soon as it is
/// available (by using a channel) /// available (by using a channel)
fn open(port: &str, baudrate: u32) -> SResult<Self> { fn open(port: &str, baudrate: u32) -> SResult<Self> {
let serial = Arc::new(Mutex::new(serialport::new(port, baudrate).open()?)); let serial = Arc::new(Mutex::new(
serialport::new(port, baudrate)
.timeout(Duration::from_millis(200))
.open()?,
));
let (tx, rx) = channel::<Vec<u8>>(); let (tx, rx) = channel::<Vec<u8>>();
let ser = Arc::clone(&serial); let ser = Arc::clone(&serial);
let _handle = thread::spawn(move || { let _handle = thread::spawn(move || {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment