diff options
author | Tim Nordell <tim.nordell@nimbelink.com> | 2020-08-21 15:20:44 -0500 |
---|---|---|
committer | Tim Nordell <tim.nordell@nimbelink.com> | 2020-08-21 15:35:49 -0500 |
commit | 0085e1e1d55f6a5376e06ed5ff679b7c0f66b202 (patch) | |
tree | 8a9f786d55feb7276799200610692abeb3fef90f | |
parent | 3a6ae5a630589a29af8d8bd45616d7aadb2fb3db (diff) | |
download | pyserial-git-0085e1e1d55f6a5376e06ed5ff679b7c0f66b202.tar.gz |
linux: Fix custom baud rate to not temporarily set 38400 baud rates
When using a custom baud rate on Linux these lines of code caused it
to push a 38400 baud rate setting down into the serial driver (even
if temporarily). It would correct this moments later, but we can
simply set the BOTHER value at this point. If other platforms have
a different default value for ispeed and ospeed when using a custom baud
rate, they can define BOTHER as well.
-rw-r--r-- | serial/serialposix.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/serial/serialposix.py b/serial/serialposix.py index 334ba9f..8da40a1 100644 --- a/serial/serialposix.py +++ b/serial/serialposix.py @@ -405,8 +405,15 @@ class Serial(SerialBase, PlatformSpecific): ispeed = ospeed = self.BAUDRATE_CONSTANTS[self._baudrate] except KeyError: #~ raise ValueError('Invalid baud rate: %r' % self._baudrate) - # may need custom baud rate, it isn't in our list. - ispeed = ospeed = getattr(termios, 'B38400') + + # See if BOTHER is defined for this platform; if it is, use + # this for a speed not defined in the baudrate constants list. + try: + ispeed = ospeed = BOTHER + except NameError: + # may need custom baud rate, it isn't in our list. + ispeed = ospeed = getattr(termios, 'B38400') + try: custom_baud = int(self._baudrate) # store for later except ValueError: |