important bugfix: added serial flushing
This commit is contained in:
+1
-1
@@ -5,6 +5,6 @@ edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
thiserror = "2"
|
||||
serialport = { version = "4.8.2-alpha.0", git = "https://github.com/us-irs/serialport-rs.git", branch = "add-vmin-vtime-and-non-blocking-support" }
|
||||
serialport = { version = "4" }
|
||||
cobs = "0.5"
|
||||
log = "0.4"
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use cobs::CobsDecoderOwned;
|
||||
use serialport::ReadMode;
|
||||
|
||||
use crate::transport::PacketTransport;
|
||||
|
||||
@@ -27,12 +26,10 @@ impl PacketTransportSerialCobs {
|
||||
baud_rate: u32,
|
||||
max_rx_packet_size: usize,
|
||||
) -> Result<Self, std::io::Error> {
|
||||
#[cfg(target_os = "linux")]
|
||||
let mut serial = serialport::new(port_name, baud_rate).open_native()?;
|
||||
#[cfg(target_os = "linux")]
|
||||
serial.set_read_mode(ReadMode::Immediate)?;
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
let mut serial = serialport::new(port_name, baud_rate).open()?;
|
||||
let serial = serialport::new(port_name, baud_rate).open_native()?;
|
||||
// Not merged yet in upstream..
|
||||
//#[cfg(target_os = "linux")]
|
||||
//serial.set_read_mode(ReadMode::Immediate)?;
|
||||
Ok(Self::new(
|
||||
Box::new(serial),
|
||||
CobsDecoderOwned::new(max_rx_packet_size),
|
||||
@@ -61,6 +58,7 @@ impl PacketTransportSerialCobs {
|
||||
let encoded = cobs::encode_vec_including_sentinels(packet);
|
||||
log::debug!("sending COBS encoded packet: {:?}", encoded);
|
||||
self.serial.write_all(&encoded)?;
|
||||
self.serial.flush()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -82,6 +82,7 @@ impl PacketTransportTcpWithCobs {
|
||||
}
|
||||
}
|
||||
|
||||
/// Close the connection by shutting down the TCP stream.
|
||||
pub fn close(&mut self) -> std::io::Result<()> {
|
||||
self.tcp_stream.shutdown(std::net::Shutdown::Both)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user