diff options
author | Jan Kantert <jan-mpf@kantert.net> | 2018-05-07 21:17:37 +0200 |
---|---|---|
committer | Jan Kantert <jan-mpf@kantert.net> | 2018-05-07 21:17:37 +0200 |
commit | 1b2658a0522fc79a34eda5a52f6342d84cc66e44 (patch) | |
tree | 6618417f421a26feb32705686da6a63a96f972e4 | |
parent | 92d101613be41ecb2f2054c3f43a006fbe6f9966 (diff) | |
download | pyserial-git-1b2658a0522fc79a34eda5a52f6342d84cc66e44.tar.gz |
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 3ac6283..769cb4b 100644 --- a/serial/serialposix.py +++ b/serial/serialposix.py @@ -49,6 +49,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 @@ -113,6 +116,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) |