Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix write timeout for COM ports #158

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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();
nskartoredjo marked this conversation as resolved.
Show resolved Hide resolved

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