Skip to content
Open
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
16 changes: 9 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ default = []
libudev = ["serialport/libudev"]
serde = ["serialport/serde"]

[dependencies]
windows-sys = { version = ">=0.59.0,<0.62", features = [
"Win32_Devices_Communication",
"Win32_Storage_FileSystem",
"Win32_Foundation",
# required for CreateFileW to be available in 0.59 & 0.60
"Win32_Security",
] }

[dependencies.mio]
version = "1"
features = ["os-poll", "os-ext"]
Expand All @@ -34,13 +43,6 @@ version = "0.4"
[target.'cfg(unix)'.dependencies]
nix = { version = "0.29", features = ["term"] }

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = [
"commapi",
"handleapi",
"winbase",
"std",
] }

[dev-dependencies.env_logger]
version = "0.11"
Expand Down
17 changes: 9 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ mod os_prelude {
pub use std::os::windows::io::{FromRawHandle, RawHandle};
pub use std::path::Path;
pub use std::ptr;
pub use winapi::um::commapi::SetCommTimeouts;
pub use winapi::um::fileapi::*;
pub use winapi::um::handleapi::INVALID_HANDLE_VALUE;
pub use winapi::um::winbase::{COMMTIMEOUTS, FILE_FLAG_OVERLAPPED};
pub use winapi::um::winnt::{
FILE_ATTRIBUTE_NORMAL, GENERIC_READ, GENERIC_WRITE, HANDLE,

pub use windows_sys::Win32::Devices::Communication::{SetCommTimeouts, COMMTIMEOUTS};
pub use windows_sys::Win32::Foundation::{
GENERIC_READ, GENERIC_WRITE, HANDLE, INVALID_HANDLE_VALUE,
};
pub use windows_sys::Win32::Storage::FileSystem::{
CreateFileW, FILE_ATTRIBUTE_NORMAL, FILE_FLAG_OVERLAPPED, OPEN_EXISTING,
};
}
use os_prelude::*;
Expand Down Expand Up @@ -792,7 +793,7 @@ mod sys {
/// Overrides timeout value set by serialport-rs so that the read end will
/// never wake up with 0-byte payload.
pub(crate) fn override_comm_timeouts(handle: RawHandle) -> StdIoResult<()> {
let mut timeouts = COMMTIMEOUTS {
let timeouts = COMMTIMEOUTS {
// wait at most 1ms between two bytes (0 means no timeout)
ReadIntervalTimeout: 1,
// disable "total" timeout to wait at least 1 byte forever
Expand All @@ -803,7 +804,7 @@ mod sys {
WriteTotalTimeoutConstant: 0,
};

let r = unsafe { SetCommTimeouts(handle, &mut timeouts) };
let r = unsafe { SetCommTimeouts(handle, &timeouts) };
if r == 0 {
return Err(io::Error::last_os_error());
}
Expand Down