Skip to content

Commit

Permalink
Fix write timeout for COM ports (#158)
Browse files Browse the repository at this point in the history
* Fix write timeout for COM ports

* Add the fix to the changelog

---------

Co-authored-by: Nando Kartoredjo <[email protected]>
  • Loading branch information
nskartoredjo and Nando Kartoredjo authored Feb 16, 2024
1 parent 5d66560 commit 954a622
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,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

Expand Down
4 changes: 2 additions & 2 deletions src/windows/com.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 954a622

Please sign in to comment.