Repository: serialport/serialport-rs (language: rust)

Issue:
Serial write stalls application on some Windows machines
Apart from the issue that on some Windows machines (both my laptop and my PC), `read` just blocks the program, also the `write` 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](https://github.com/LukaOber/serialport-rs), 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.


Discussion / hints:
To give some context: this is my code, with different timeouts specified, all of which stalling the program:
```rust
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.
> because the read is blocking

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

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 79ededc9..0f04b56c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,9 @@ project adheres to [Semantic Versioning](https://semver.org/).
 ### Fixed
 * Fixes a bug where `available_ports()` returned disabled devices on Windows.
   [#144](https://github.com/serialport/serialport-rs/pull/144)
+* Fixes a bug on Windows where the `WriteTotalTimeoutConstant` field hasn't been
+  configured properly when the `set_timeout` method is called.
+  [#124](https://github.com/serialport/serialport-rs/issues/124)
 
 ### Removed
 
diff --git a/src/windows/com.rs b/src/windows/com.rs
index 662cc196..5573ab77 100644
--- a/src/windows/com.rs
+++ b/src/windows/com.rs
@@ -240,14 +240,14 @@ impl SerialPort for COMPort {
     }
 
     fn set_timeout(&mut self, timeout: Duration) -> Result<()> {
-        let milliseconds = timeout.as_secs() * 1000 + timeout.subsec_nanos() as u64 / 1_000_000;
+        let milliseconds = timeout.as_millis();
 
         let mut timeouts = COMMTIMEOUTS {
             ReadIntervalTimeout: 0,
             ReadTotalTimeoutMultiplier: 0,
             ReadTotalTimeoutConstant: milliseconds as DWORD,
             WriteTotalTimeoutMultiplier: 0,
-            WriteTotalTimeoutConstant: 0,
+            WriteTotalTimeoutConstant: milliseconds as DWORD,
         };
 
         if unsafe { SetCommTimeouts(self.handle, &mut timeouts) } == 0 {


Test patch: