Skip to content

Commit

Permalink
Merge pull request #45 from de-vri-es/fix-verifying-applied-settings-…
Browse files Browse the repository at this point in the history
…on-apple

Fix the way applied settings are verified on Apple systems.
  • Loading branch information
de-vri-es authored Nov 10, 2024
2 parents 4b9413d + c455f6e commit e824bd7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Unreleased
- [fix][minor] Fix verification of applied settings on iOS and macOS.

# Version 0.2.27 - 2024-09-13
- [fix][minor] Allow for a 2.5% deviation in actual baud rate when applying settings on Unix.
- [add][minor] Implement `Debug` for `SerialPort` showing the underlying file descriptor (Unix) or handle (Windows).
Expand Down
24 changes: 12 additions & 12 deletions src/sys/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,22 +164,22 @@ impl SerialPort {
// On iOS and macOS we set the baud rate with the IOSSIOSPEED ioctl.
// But we also need to ensure the `set_on_file()` doesn't fail.
// So fill in a safe speed in the termios struct which we will override shortly after.
#[cfg(any(target_os = "ios", target_os = "macos"))]
let (settings, baud_rate) = {
let baud_rate = settings.termios.c_ospeed;
let mut settings = settings.clone();
settings.termios.c_ispeed = 9600;
settings.termios.c_ospeed = 9600;
(settings, baud_rate)
};
#[cfg(any(target_os = "ios", target_os = "macos"))]
let settings = &settings;
cfg_if! {
if #[cfg(any(target_os = "ios", target_os = "macos"))] {
let mut apply_settings = settings.clone();
apply_settings.termios.c_ispeed = 9600;
apply_settings.termios.c_ospeed = 9600;
let apply_settings = &apply_settings;
} else {
let apply_settings = settings;
}
}

settings.set_on_file(&mut self.file)?;
apply_settings.set_on_file(&mut self.file)?;

// On iOS and macOS, override the speed with the IOSSIOSPEED ioctl.
#[cfg(any(target_os = "ios", target_os = "macos"))]
ioctl_iossiospeed(self.file.as_raw_fd(), baud_rate)?;
ioctl_iossiospeed(self.file.as_raw_fd(), settings.termios.c_ospeed)?;

let applied_settings = self.get_configuration()?;
if !applied_settings.matches_requested(settings) {
Expand Down

0 comments on commit e824bd7

Please sign in to comment.