Skip to content

Commit 954a622

Browse files
nskartoredjoNando Kartoredjo
andauthored
Fix write timeout for COM ports (#158)
* Fix write timeout for COM ports * Add the fix to the changelog --------- Co-authored-by: Nando Kartoredjo <[email protected]>
1 parent 5d66560 commit 954a622

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ project adheres to [Semantic Versioning](https://semver.org/).
1212
### Fixed
1313
* Fixes a bug where `available_ports()` returned disabled devices on Windows.
1414
[#144](https://github.com/serialport/serialport-rs/pull/144)
15+
* Fixes a bug on Windows where the `WriteTotalTimeoutConstant` field hasn't been
16+
configured properly when the `set_timeout` method is called.
17+
[#124](https://github.com/serialport/serialport-rs/issues/124)
1518

1619
### Removed
1720

src/windows/com.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,14 @@ impl SerialPort for COMPort {
240240
}
241241

242242
fn set_timeout(&mut self, timeout: Duration) -> Result<()> {
243-
let milliseconds = timeout.as_secs() * 1000 + timeout.subsec_nanos() as u64 / 1_000_000;
243+
let milliseconds = timeout.as_millis();
244244

245245
let mut timeouts = COMMTIMEOUTS {
246246
ReadIntervalTimeout: 0,
247247
ReadTotalTimeoutMultiplier: 0,
248248
ReadTotalTimeoutConstant: milliseconds as DWORD,
249249
WriteTotalTimeoutMultiplier: 0,
250-
WriteTotalTimeoutConstant: 0,
250+
WriteTotalTimeoutConstant: milliseconds as DWORD,
251251
};
252252

253253
if unsafe { SetCommTimeouts(self.handle, &mut timeouts) } == 0 {

0 commit comments

Comments
 (0)