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

Resolve Mac OS setting Prolific Technology adapter #194

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
18 changes: 12 additions & 6 deletions src/posix/termios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,21 @@ pub(crate) fn get_termios(fd: RawFd) -> Result<Termios> {
}

#[cfg(any(target_os = "ios", target_os = "macos",))]
pub(crate) fn set_termios(fd: RawFd, termios: &libc::termios, baud_rate: u32) -> Result<()> {
let res = unsafe { libc::tcsetattr(fd, libc::TCSANOW, termios) };
nix::errno::Errno::result(res)?;
pub(crate) fn set_termios(fd: RawFd, termios: &mut libc::termios, baud_rate: u32) -> Result<()> {

// Note: attempting to set the baud rate on a pseudo terminal via this ioctl call will fail
// with the `ENOTTY` error.
let mut ispeed_res = 0;
let mut ospeed_res = 0;
if baud_rate > 0 {
crate::posix::ioctl::iossiospeed(fd, &(baud_rate as libc::speed_t))?;
unsafe {
ispeed_res = libc::cfsetispeed(&mut *termios, baud_rate as libc::speed_t);
ospeed_res = libc::cfsetospeed(&mut *termios, baud_rate as libc::speed_t);
}
}
nix::errno::Errno::result(ispeed_res)?;
nix::errno::Errno::result(ospeed_res)?;

let res = unsafe { libc::tcsetattr(fd, libc::TCSANOW, termios) };
nix::errno::Errno::result(res)?;

Ok(())
}
Expand Down
10 changes: 5 additions & 5 deletions src/posix/tty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl TTYPort {
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
termios::set_baud_rate(&mut termios, builder.baud_rate);
#[cfg(any(target_os = "ios", target_os = "macos"))]
termios::set_termios(fd.0, &termios, builder.baud_rate)?;
termios::set_termios(fd.0, &mut termios, builder.baud_rate)?;
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
termios::set_termios(fd.0, &termios)?;

Expand Down Expand Up @@ -646,7 +646,7 @@ impl SerialPort for TTYPort {
let mut termios = termios::get_termios(self.fd)?;
termios::set_flow_control(&mut termios, flow_control);
#[cfg(any(target_os = "ios", target_os = "macos"))]
return termios::set_termios(self.fd, &termios, self.baud_rate);
return termios::set_termios(self.fd, &mut termios, self.baud_rate);
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
return termios::set_termios(self.fd, &termios);
}
Expand All @@ -655,7 +655,7 @@ impl SerialPort for TTYPort {
let mut termios = termios::get_termios(self.fd)?;
termios::set_parity(&mut termios, parity);
#[cfg(any(target_os = "ios", target_os = "macos"))]
return termios::set_termios(self.fd, &termios, self.baud_rate);
return termios::set_termios(self.fd, &mut termios, self.baud_rate);
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
return termios::set_termios(self.fd, &termios);
}
Expand All @@ -664,7 +664,7 @@ impl SerialPort for TTYPort {
let mut termios = termios::get_termios(self.fd)?;
termios::set_data_bits(&mut termios, data_bits);
#[cfg(any(target_os = "ios", target_os = "macos"))]
return termios::set_termios(self.fd, &termios, self.baud_rate);
return termios::set_termios(self.fd, &mut termios, self.baud_rate);
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
return termios::set_termios(self.fd, &termios);
}
Expand All @@ -673,7 +673,7 @@ impl SerialPort for TTYPort {
let mut termios = termios::get_termios(self.fd)?;
termios::set_stop_bits(&mut termios, stop_bits);
#[cfg(any(target_os = "ios", target_os = "macos"))]
return termios::set_termios(self.fd, &termios, self.baud_rate);
return termios::set_termios(self.fd, &mut termios, self.baud_rate);
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
return termios::set_termios(self.fd, &termios);
}
Expand Down
Loading