summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Kantert <jan-mpf@kantert.net>2018-05-07 21:17:37 +0200
committerJan Kantert <jan-mpf@kantert.net>2018-05-07 21:17:37 +0200
commit1b2658a0522fc79a34eda5a52f6342d84cc66e44 (patch)
tree6618417f421a26feb32705686da6a63a96f972e4
parent92d101613be41ecb2f2054c3f43a006fbe6f9966 (diff)
downloadpyserial-git-1b2658a0522fc79a34eda5a52f6342d84cc66e44.tar.gz
option for low latency mode on linux
-rw-r--r--serial/serialposix.py21
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)