Skip to content

Commit

Permalink
Merge pull request #30 from matheuswhite/bug-windows
Browse files Browse the repository at this point in the history
Fixes bug in windows
  • Loading branch information
matheuswhite authored Feb 8, 2024
2 parents a3c4ff0 + 8675f9f commit 609a55e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/serial.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::messages::{SerialRxData, UserTxData};
use chrono::Local;
use serialport::SerialPort;
use serialport::{self, SerialPort};
use std::io::{Read, Write};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::{channel, Receiver, RecvError, Sender, TryRecvError};
Expand All @@ -23,7 +23,7 @@ impl Drop for SerialIF {
}

impl SerialIF {
const SERIAL_TIMEOUT: Duration = Duration::from_millis(10);
const SERIAL_TIMEOUT: Duration = Duration::from_millis(100);
const RECONNECT_INTERVAL: Duration = Duration::from_millis(200);

pub fn is_connected(&self) -> bool {
Expand Down Expand Up @@ -89,10 +89,14 @@ impl SerialIF {
is_connected: Arc<AtomicBool>,
) -> Box<dyn SerialPort> {
'reconnect: loop {
if let Ok(mut serial) = serialport::new(port, baudrate).open() {
serial
.set_timeout(SerialIF::SERIAL_TIMEOUT)
.expect("Cannot set serialport timeout");
if let Ok(serial) = serialport::new(port, baudrate)
.data_bits(serialport::DataBits::Eight)
.flow_control(serialport::FlowControl::Hardware)
.parity(serialport::Parity::None)
.stop_bits(serialport::StopBits::One)
.timeout(SerialIF::SERIAL_TIMEOUT)
.open()
{
is_connected.store(true, Ordering::SeqCst);
break 'reconnect serial;
}
Expand Down

0 comments on commit 609a55e

Please sign in to comment.