Skip to content

Commit 27b7c8b

Browse files
authored
Merge pull request pyserial#290 from jabdoa2/low_latency_mode
option for low latency mode on linux
2 parents bafd196 + 1b2658a commit 27b7c8b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

serial/serialposix.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ def _set_special_baudrate(self, baudrate):
5151
def _set_rs485_mode(self, rs485_settings):
5252
raise NotImplementedError('RS485 not supported on this platform')
5353

54+
def set_low_latency_mode(self, low_latency_settings):
55+
raise NotImplementedError('Low latency not supported on this platform')
56+
5457

5558
# some systems support an extra flag to enable the two in POSIX unsupported
5659
# paritiy settings for MARK and SPACE
@@ -115,6 +118,24 @@ class PlatformSpecific(PlatformSpecificBase):
115118
4000000: 0o010017
116119
}
117120

121+
def set_low_latency_mode(self, low_latency_settings):
122+
buf = array.array('i', [0] * 32)
123+
124+
try:
125+
# get serial_struct
126+
fcntl.ioctl(self.fd, termios.TIOCGSERIAL, buf)
127+
128+
# set or unset ASYNC_LOW_LATENCY flag
129+
if low_latency_settings:
130+
buf[4] |= 0x2000
131+
else:
132+
buf[4] &= ~0x2000
133+
134+
# set serial_struct
135+
fcntl.ioctl(self.fd, termios.TIOCSSERIAL, buf)
136+
except IOError as e:
137+
raise ValueError('Failed to update ASYNC_LOW_LATENCY flag to {}: {}'.format(low_latency_settings, e))
138+
118139
def _set_special_baudrate(self, baudrate):
119140
# right size is 44 on x86_64, allow for some growth
120141
buf = array.array('i', [0] * 64)

0 commit comments

Comments
 (0)