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

Some fixes I had to do to make serialport-rs work on MacOS #49

Open
berkus opened this issue May 3, 2022 · 11 comments
Open

Some fixes I had to do to make serialport-rs work on MacOS #49

berkus opened this issue May 3, 2022 · 11 comments
Labels
posix This issue is specific to posix systems

Comments

@berkus
Copy link

berkus commented May 3, 2022

Here's the diff.

I'm not sending this as a PR because it's not a PR-quality code and just a quick patch of things that didn't work, like #22 and disabling IOSSIOSPEED that does not work on MacOS.

Maybe it helps you get some ideas for fixing it properly.

@jessebraham jessebraham added the posix This issue is specific to posix systems label May 19, 2022
@jesjos
Copy link

jesjos commented Dec 8, 2022

I had a project that failed to behave correctly (reading garbled bytes from a serial device) on macOS. I tried the patched code by @berkus and everything worked just fine.

@sirhcel
Copy link
Contributor

sirhcel commented Dec 11, 2022

Thank you very much for this issue report! I had a first look at this issue by

  • Receiving some data on macOS with receive_data sent from Minicom on Linux
  • Sending some data from macOS with transmit to Minicom on Linux

The first did not show any received data at all. The data sent from macOS to Linux showed up in Minicom without any issues. This is not the behavior I would have expected here.

But I did not receive any garbled data. @berkus and @jesjos could you give please some details on the scenario you are experiencing the problems with? Like communication settings, transmission directions, ...

@jesjos
Copy link

jesjos commented Dec 14, 2022

Thank you for your quick reply, @sirhcel !

I'm sorry I didn't provide a full bug report.

My setup is this:

  • Communicating with a serial device that uses a fixed baud rate of 115200
  • I set baudrate as expected using the serialport-rs
  • I read two bytes, I expect them to be little-endian 9
  • Instead, I get something like 0x9c

I can actually get the vanilla serialport code working if I use some other serial reading implementation to set the baud rate first. So in my case, I use a java library to read the correct two bytes, then I run my rust code and it works fine. But after restarting my rust code it goes back to the wrong baud rate. I suspect something is fishy with how the library sets baud rates, but my skills aren't enough to figure out exactly what.

I'm running macOS Monterey 12.6 on an Intel mac.

@DanielJoyce
Copy link

I looked into this long ago and there is another ticket open that says baud rate is ignored.

I remember looking at the code and seeing some of the settings specified in the constructor not making it into the lower level serial settings.

@sirhcel
Copy link
Contributor

sirhcel commented Dec 18, 2022

Thank you very much for your feedback! The last days before Christmas are quite busy and I will look into this afterwards. It looks like there is a need for some testing as well.

@berkus
Copy link
Author

berkus commented Dec 20, 2022

@sirhcel thanks for looking into it!

@Ali-Amir
Copy link

Ali-Amir commented May 25, 2023

I'm experiencing similar issues as #22 (ENOTTY when opening a socat/TTYPort::pair port on MacOS). Is there anything we could do to help with getting a fix? Please, never mind. With the latest version 4.2.1 and using baud rate 0 works when connecting to a virtual TTY port.

@jamesmunns
Copy link

Just noting that this issue still exists with M2 macs. I was previously using serialport 4.2.1, and switching to @berkus's branch made things work.

This was pretty reproducible, and I can debug things if necessary. @jessebraham is there anything I can do to get this to a mergeable state?

This was with 115200 8N1 serial, using a Sipeed RV-debugger-plus.

jamesmunns added a commit to tosc-rs/mnemos that referenced this issue Jul 1, 2023
This adds a small hack to allow using a patched version of the
`serialport` crate on macos

CC serialport/serialport-rs#49
eldruin pushed a commit that referenced this issue Dec 8, 2023
I don't understand why this works, but it resolves problematic behavior
(#49) on macOS. Bisecting history, I found commit
3d6c1b2, which removed flushing the IO
buffers for a TTY, was problematic on macOS. However, the test
`test_osx_pty_pair` which tests pseudo-ttys with baud_rate 0 on macOS
(introduced in b54264b) fails if I
simply reintroduced flushing. Therefore, this change now re-introduces
flushing the IO buffers upon opening a TTY, but only on macOS and only
when baud-rate is non-zero.

Thanks to @berkus for the original work.
@StonyBoy
Copy link

I have not yet tried the patch supplied in this issue, but I can confirm that the problem is also seen om intel based Macs (garbled characters or none at all).
For now I have just fixed my MacOS dependency to v3.3.0 as this works perfectly on my setup.

@astraw
Copy link
Contributor

astraw commented Apr 10, 2024

@StonyBoy this sounds like it might be the issue @KaSroka reported at #133 (comment).

With which version of serialport-rs are you experiencing the problem and can you please provide steps to reproduce it?

@StonyBoy
Copy link

StonyBoy commented Apr 10, 2024

Hi @astraw:

I was also using v4.3.0 initially and I also used the suggestion to set the baud rate explicitely as mentioned by @KaSroka, but that did not change the behaviour for me.

I am using serialport-rs in a unpublished serial client/server program that I am currently working on, but i am mainly just opening the port (connection to a Beaglebone Black over USB/UART) like this:

fn do_open(opts: &CmdLineConfig) -> Result<Box<dyn SerialPort>, serialport::Error> {
    serialport::new(opts.device.to_str().unwrap(), opts.baudrate).timeout(Duration::from_millis(100)).open()
}

and then looping in a receiver thread passing the received bytes to the other parts of the program:

            let mut serial_buf = vec![0; 32];
            match rxport.read(serial_buf.as_mut_slice()) {
                Ok(cnt) => {
                    info!("Received: {cnt}");

The baud rate used on the BBB is 115200 and N81...

BTW: That works fine in v4.3.0 when running on Linux.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
posix This issue is specific to posix systems
Projects
None yet
Development

No branches or pull requests

9 participants