diff --git a/src/serial.rs b/src/serial.rs index f81634111acfe4dc4b472b71a7f41760643d4275..950f1dcc9a9e377b08885a068c25bfe6b365df21 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -3,7 +3,7 @@ use std::{ ops::Deref, sync::Arc, thread::{self, JoinHandle}, - time::Duration, + time::{Duration, Instant}, }; use crossbeam_channel::{unbounded, Receiver, RecvTimeoutError, Sender}; @@ -67,13 +67,9 @@ impl SerialManager { let mut buf = vec![0; n]; // implement a read exact to allow better error messages let mut filled = 0; + let timeout = Instant::now() + port.read_timeout; while filled < n { - match port - .reader_ch - .as_ref() - .unwrap() - .recv_timeout(port.read_timeout) - { + match port.reader_ch.as_ref().unwrap().recv_deadline(timeout) { Ok(b) => { buf[filled] = b; filled += 1; @@ -136,8 +132,7 @@ impl SerialQueue { let ser = Arc::clone(&serial); handles.push(thread::spawn(move || { while let Ok(data) = wrx.recv() { - data.chunks(256) - .for_each(|chunk| ser.lock().as_mut().unwrap().write_all(chunk).unwrap()); + ser.lock().as_mut().unwrap().write_all(&data).unwrap(); } })); @@ -145,7 +140,7 @@ impl SerialQueue { let (rtx, rrx) = unbounded::<u8>(); let ser = Arc::clone(&serial); handles.push(thread::spawn(move || { - let mut buf = [0; 256]; + let mut buf = [0; 1024]; loop { match ser.lock().as_mut().map(|p| p.read(&mut buf)) { Some(Ok(n)) => {