diff options
author | zsquareplusc <cliechti@gmx.net> | 2018-05-08 02:04:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-08 02:04:10 +0200 |
commit | 27b7c8b3c275fa126b6aa6604dff3207ff2bfd67 (patch) | |
tree | 9896f451f0c6ccfdf12ac2f4ef98c4601aa3e5cc | |
parent | bafd19682794c7e85d74df1cf76ca6667672138e (diff) | |
parent | 1b2658a0522fc79a34eda5a52f6342d84cc66e44 (diff) | |
download | pyserial-git-27b7c8b3c275fa126b6aa6604dff3207ff2bfd67.tar.gz |
Merge pull request #290 from jabdoa2/low_latency_mode
option for low latency mode on linux
-rw-r--r-- | serial/serialposix.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/serial/serialposix.py b/serial/serialposix.py index 82fe59a..9eec8a7 100644 --- a/serial/serialposix.py +++ b/serial/serialposix.py @@ -51,6 +51,9 @@ class PlatformSpecificBase(object): def _set_rs485_mode(self, rs485_settings): raise NotImplementedError('RS485 not supported on this platform') + def set_low_latency_mode(self, low_latency_settings): + raise NotImplementedError('Low latency not supported on this platform') + # some systems support an extra flag to enable the two in POSIX unsupported # paritiy settings for MARK and SPACE @@ -115,6 +118,24 @@ if plat[:5] == 'linux': # Linux (confirmed) # noqa 4000000: 0o010017 } + def set_low_latency_mode(self, low_latency_settings): + buf = array.array('i', [0] * 32) + + try: + # get serial_struct + fcntl.ioctl(self.fd, termios.TIOCGSERIAL, buf) + + # set or unset ASYNC_LOW_LATENCY flag + if low_latency_settings: + buf[4] |= 0x2000 + else: + buf[4] &= ~0x2000 + + # set serial_struct + fcntl.ioctl(self.fd, termios.TIOCSSERIAL, buf) + except IOError as e: + raise ValueError('Failed to update ASYNC_LOW_LATENCY flag to {}: {}'.format(low_latency_settings, e)) + def _set_special_baudrate(self, baudrate): # right size is 44 on x86_64, allow for some growth buf = array.array('i', [0] * 64) |