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

Custom Baudrate OSX #139

Open
saynono opened this issue Sep 28, 2016 · 2 comments
Open

Custom Baudrate OSX #139

saynono opened this issue Sep 28, 2016 · 2 comments

Comments

@saynono
Copy link

saynono commented Sep 28, 2016

Hi.
It seems that following line:441 in unix Serial::SerialImpl::reconfigurePort resets custom baudrates on OSX.

  // activate settings
  ::tcsetattr (fd_, TCSANOW, &options);

Setting custom baudrates after this line fixes this as far as I can tell.
Also for noobs as myself, might be helpfull mentioning to call this on OSX:

stty ospeed <custom_baudrate>
stty ispeed <custom_baudrate>

and on linux

sudo stty -F <port> <custom_baudrate>

My changes here:
saynono@c997027

@willemkempers
Copy link

willemkempers commented Jun 19, 2017

I had the same issue, but found adding the following block to line 343 a bit more elegant:

#if defined(MAC_OS_X_VERSION_10_4) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4)
  else {
      speed_t new_baud = static_cast<speed_t> (baudrate_);
      ::cfsetispeed(&options, new_baud);
      ::cfsetospeed(&options, new_baud);
  }
#endif

Tested this super quickly on my macbook running macOS 10.12

@atomiechen
Copy link
Contributor

atomiechen commented Mar 21, 2020

Setting custom baudrates after this line fixes this as far as I can tell.

@saynono This is correct as far as I can see. I look into source code of PySerial (in serialposix.py):

def _reconfigure_port(self, force_update=False):
    ...
    # activate settings
    if force_update or [iflag, oflag, cflag, lflag, ispeed, ospeed, cc] != orig_attr:
        termios.tcsetattr(
            self.fd,
            termios.TCSANOW,
            [iflag, oflag, cflag, lflag, ispeed, ospeed, cc])

    # apply custom baud rate, if any
    if custom_baud is not None:
        self._set_special_baudrate(custom_baud)

We need to set custom baudrate after calling tcsetattr. Since I can use PySerial to connect my Arduino by 250000 baudrate yet I cannot do this via this c++ serial library, I believe this is at least a big difference I can find. Same issue also showed up in other project and a similar solution here: Custom baud rate in OSX won't work #57, npat-efault/picocom.

In my scenario the problem is solved on macOS Mojave 10.14.4. My commit: 4773265

wjwwood pushed a commit that referenced this issue Jun 10, 2021
…Serial source code and #57 of github.com/npat-efault/picocom, we need to set custom baudrate after calling tcsetattr; tested on macOS Mojave 10.14.4 (#218)
rhulme pushed a commit to rhulme/serial that referenced this issue Nov 20, 2022
…d by PySerial source code and wjwwood#57 of github.com/npat-efault/picocom, we need to set custom baudrate after calling tcsetattr; tested on macOS Mojave 10.14.4 (wjwwood#218)
ccwanggl pushed a commit to CLNBG/serial that referenced this issue Jul 7, 2023
…d by PySerial source code and wjwwood#57 of github.com/npat-efault/picocom, we need to set custom baudrate after calling tcsetattr; tested on macOS Mojave 10.14.4 (wjwwood#218)
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

No branches or pull requests

3 participants