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

MacOS Failed to apply some or all settings #44

Closed
DonavanMartin opened this issue Oct 28, 2024 · 12 comments · Fixed by #45
Closed

MacOS Failed to apply some or all settings #44

DonavanMartin opened this issue Oct 28, 2024 · 12 comments · Fixed by #45

Comments

@DonavanMartin
Copy link

DonavanMartin commented Oct 28, 2024

pub fn set_configuration(&mut self, settings: &Settings) -> std::io::Result<()> {

I'm unable to connect port with MacOS: "/dev/tty.usbserial-DK0I847P": "ValidationError: StdError(Custom { kind: Other, error: "failed to apply some or all settings" })"

I think their's something misconfigured with baud rate.

Windows and Debian are working properly.

@bailout00
Copy link

Same issue here, some notes here:

de-vri-es/serial2-tokio-rs#9

@bailout00
Copy link

A bit more info, definitely something around changing the baud rate. Changing any other settings seems to work normally, but changing the baud rate breaks it.

Seems like it might be related to this possibly?

#41

Serial port opened, settings: Settings { baud_rate: Ok(9600), char_size: Ok(Bits8), stop_bits: Ok(One), parity: Ok(None), flow_control: Ok(None) }
Error setting serial port settings: failed to apply some or all settings
Serial settings after set: Settings { baud_rate: Ok(115200), char_size: Ok(Bits8), stop_bits: Ok(One), parity: Ok(None), flow_control: Ok(None) }
match  SerialPort::open("/dev/tty.usbserial-16548", KeepSettings) {
        Ok(mut p) => {
            let mut settings = p.get_configuration().unwrap();
            debug!("Serial port opened, settings: {:?}", settings);
            settings.set_baud_rate(115200);
            let set_result = p.set_configuration(&settings);
            match set_result {
                Ok(_) => {
                    debug!("Serial port settings set: {:?}", settings);
                }
                Err(e) => {
                    println!("Error setting serial port settings: {}", e);
                    let mut settings = p.get_configuration().unwrap();
                    debug!("Serial settings after set: {:?}", settings);
                    
                }
            }
        }
        Err(e) => {
            println!("Error opening serial port {} {}", "/dev/tty.usbserial-14430", e);
        }
    }

Setting it back to 9600 DOES work but so far any other number fails

@de-vri-es
Copy link
Owner

Argh, I think it must be related to PR #39 (to fix issue #38).

Initial tests seemed to show that the custom speeds set that way are reported back in tcgetattr, but maybe this is not the case, and we read 9600 instead of the custom baud rate.

Sadly, if this is true, then there seems to be no way to retrieve the actual baud rate on OS X after we use the IOCTL_IOSSIOSPEED ioctl. And that means that using it will break get_configuration().

To verify this, you can create the serial port with baud rate 9600, and then change the configuration afterwards. While it will report failure, it might actually have set the baud rate, so you might still be able to use the serial port.

If that works, could you see what get_configuration() reports and what stty -F /dev/your-tty says, while you have your programming running with the serial port opened?

@bailout00
Copy link

You're correct

$ stty -f /dev/tty.usbserial-16548
speed 115200 baud;
lflags: -icanon -isig -iexten -echo
iflags: -icrnl -ixon -ixany -imaxbel -brkint
oflags: -opost -onlcr -oxtabs
cflags: cs8 -parenb

And also get_configuration does show the correct speed even after the error message

Yea for now I've ignored the error on macos, the target is linux and so far its fine there so not a huge deal but should maybe be addressed in the lib somehow.

@de-vri-es
Copy link
Owner

de-vri-es commented Nov 10, 2024

I agree. I wonder is how stty manages to get the correct speed. Is it possible to use something like strace (but mac OS equivalent) to see what syscalls stty is performing?

/edit: Nevermind, I think this was just an oversight in checking the desired and actual speed on Mac OS. I'll try to fix it now.

@de-vri-es
Copy link
Owner

Could one of you test #45 on an Apple machine? Sadly I don't have access to one :(

@bailout00
Copy link

That seems good to me 👍

@de-vri-es
Copy link
Owner

Did you check if it works as expected? I'm still nervous the speed might not be reported back correctly with tcgetattr.

@bailout00
Copy link

Well, I actually can't use it at all on macos. Not sure why but it blocks forever when trying to write a single byte to any usb adapter so not sure I'd be a great test. But it did succeed and stty says the speed changed.

@de-vri-es
Copy link
Owner

de-vri-es commented Nov 10, 2024

Does it at-least not report an error on opening the serial port or applying the baud rate anymore?

/edit: I also want to figure out that issue, but let's do one at a time 😄

@bailout00
Copy link

Correct, no longer throws an error

@de-vri-es
Copy link
Owner

Thanks for testing it! And thanks @DonavanMartin and @bailout00 for reporting the issue and providing information!

Released as v0.2.28. I will also bump serial2-tokio. 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants