summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2013-10-11 14:02:26 +0000
committercliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2013-10-11 14:02:26 +0000
commit080191f5522c51ca3bac8f5fce0261affda01c80 (patch)
treeb94f2a5a59a3f4a70ec53a40f80c609a2b8b6b55
parent1e6b5960285500ba044a18b059ea70ada121a7f2 (diff)
downloadpyserial-080191f5522c51ca3bac8f5fce0261affda01c80.tar.gz
[Patch pyserial:28] Accept any speed on Linux
git-svn-id: http://svn.code.sf.net/p/pyserial/code/trunk/pyserial@469 f19166aa-fa4f-0410-85c2-fa1106f25c8a
-rw-r--r--CHANGES.txt1
-rw-r--r--serial/serialposix.py23
2 files changed, 12 insertions, 12 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 5af51af..8aa344f 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -443,6 +443,7 @@ Version 2.7 2012-nn-nn
flowControlOut function
- rfc2217: zero polls value (baudrate, data size, stop bits, parity) (Erik
Lundh)
+- Posix: [Patch pyserial:28] Accept any speed on Linux
Bugfixes:
diff --git a/serial/serialposix.py b/serial/serialposix.py
index 65e865b..8d93c59 100644
--- a/serial/serialposix.py
+++ b/serial/serialposix.py
@@ -36,26 +36,25 @@ if plat[:5] == 'linux': # Linux (confirmed)
def device(port):
return '/dev/ttyS%d' % port
- ASYNC_SPD_MASK = 0x1030
- ASYNC_SPD_CUST = 0x0030
+ TCGETS2 = 0x802C542A
+ TCSETS2 = 0x402C542B
+ BOTHER = 0o010000
def set_special_baudrate(port, baudrate):
+ # right size is 44 on x86_64, allow for some growth
import array
- buf = array.array('i', [0] * 32)
+ buf = array.array('i', [0] * 64)
# get serial_struct
- FCNTL.ioctl(port.fd, TERMIOS.TIOCGSERIAL, buf)
-
- # set custom divisor
- buf[6] = buf[7] / baudrate
-
- # update flags
- buf[4] &= ~ASYNC_SPD_MASK
- buf[4] |= ASYNC_SPD_CUST
+ FCNTL.ioctl(port.fd, TCGETS2, buf)
+ # set custom speed
+ buf[2] &= ~TERMIOS.CBAUD
+ buf[2] |= BOTHER
+ buf[9] = buf[10] = baudrate
# set serial_struct
try:
- res = FCNTL.ioctl(port.fd, TERMIOS.TIOCSSERIAL, buf)
+ res = FCNTL.ioctl(port.fd, TCSETS2, buf)
except IOError:
raise ValueError('Failed to set custom baud rate: %r' % baudrate)