-
Notifications
You must be signed in to change notification settings - Fork 76
Open
Description
I am using tokio-serial in a project and I've found that on OSX i am getting incorrect bytes written out over the serial port i've yet to tracedown the cause of the issue exactly. I've confirmed that the same code run's completely fine on Linux/Windows and is only effecting the program on osx.
example code:
use std::time::Duration;
use anyhow::Result;
use tokio::io::{self, AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader};
use tokio_serial::{self, SerialPort, SerialPortBuilderExt};
#[tokio::main]
async fn main() -> Result<()> {
let mut port = tokio_serial::new("/dev/ttyUSB0", 38400).open_native_async()?;
let _ = port.set_exclusive(true);
let _ = port.set_parity(tokio_serial::Parity::None);
let _ = port.set_baud_rate(38400);
let _ = port.set_data_bits(tokio_serial::DataBits::Eight);
let _ = port.set_stop_bits(tokio_serial::StopBits::One);
let _ = port.set_flow_control(tokio_serial::FlowControl::None);
let written = port.write(&[3, 2, 14, 0]).await?;
let mut buffer: [u8; 5] = [0; 5];
tokio::time::sleep(Duration::from_millis(10)).await;
let read = port.read(&mut buffer).await?;
println!("{buffer:?}");
Ok(())
}
I explicitly set all of the parameters just in case there was an issue related to that but there was no change.
[package]
name = "client-testing"
version = "0.1.0"
edition = "2024"
[dependencies]
anyhow = "1.0.98"
tokio = { version = "1.45.0", features = ["full"] }
tokio-serial = { version = "5.4.1", features = ["bytes", "codec", "rt"] }Metadata
Metadata
Assignees
Labels
No labels