-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Serial write stalls application on some Windows machines #124
Comments
To give some context: this is my code, with different timeouts specified, all of which stalling the program: use serialport::new;
use std::io;
fn main() {
let mut port = new("COM8", 38400)
.timeout(std::time::Duration::from_millis(100))
.open()
.expect("Failed to open port");
let mut serial_buf: Vec<u8> = vec![0; 100];
loop {
println!("Reading");
let mut s = String::new();
let res = io::stdin().read_line(&mut s);
match res {
Ok(_) => {
println!("Read {} bytes from stdin", s.len());
println!("Content: {}", s);
let s = s.as_bytes();
port.write(s).expect("Write failed");
//^^^^^^^^ stalls here
println!("Wrote {} bytes to Serial", s.len());
}
Err(e) => eprintln!("{:?}", e),
}
}
} |
I'm having the same issue. I have two threads for reading and writing using a clone of the serial port. I can't write anything on the port because the read is blocking and waiting for a response. This is not an issue on my Linux machine. |
That's actually a different issue than mine. This is about the write function. You should be able to use the fork by LukaOber that I linked above. It fixes the read function. In this case, it's the write function that stalls separately from the read function. I've had stalled reads on mine too, but they were resolved when I just used the fork (there's already a merge request for this fork). |
After I changed my crate to the fork by LukaOber it worked great! I had to change some code, but this solution works for me. Thanks for sharing! |
So.... is this fixed now ? |
For different reasons, I reinstalled Windows on my PC. Since then, it works. I don't think there was a bug fix related to this, so AFAIK it's not fixed |
I've encountered a similar issue, and with a bit of digging, it turns out that the write timeout is never set for Windows machines. I've created a pull request to resolve the issue |
Apart from the issue that on some Windows machines (both my laptop and my PC),
read
just blocks the program, also thewrite
function blocks the program on my laptop. It works fine on my PC, but on my Laptop it also doesn't write. I tried setting the timeout to 0, still it stalls.I tried using the fork by LukaOber, and that fork fixes the read function, but not the write function. I have verified that the write function is not just broken in that fork, but also in this one.
By "blocking" or "stalling" I mean, that the write function (and in this repo also the read function, as already discussed in #29 ) never returns, not even an error. The program will just stall, regardless of the set timeout.
The text was updated successfully, but these errors were encountered: