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 {