From 74e6b5c54c1a28642ab827b037e7c4e76c0329b2 Mon Sep 17 00:00:00 2001 From: "N. Kartoredjo" Date: Tue, 13 Feb 2024 20:25:51 +0000 Subject: [PATCH 1/2] Fix write timeout for COM ports --- src/windows/com.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 { From 24d2bffbbac8f7c30b1ee8b257a3e22457c639ec Mon Sep 17 00:00:00 2001 From: Nando Kartoredjo Date: Fri, 16 Feb 2024 00:37:21 +0100 Subject: [PATCH 2/2] Add the fix to the changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) 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