summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2007-11-08 23:43:58 +0000
committercliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2007-11-08 23:43:58 +0000
commitf1559d086c096ae6751880f90955f87554f27290 (patch)
tree1951e2a8445e8dc1309e0f05fc3507b377043cc1
parent4569bac3c45e825cbe74f751890b0324b9adda8c (diff)
downloadpyserial-git-f1559d086c096ae6751880f90955f87554f27290.tar.gz
fall back to internal baud rate constants if the termios module hasn't one. happens for large baudrates on some systems
-rw-r--r--pyserial/serial/serialposix.py41
1 files changed, 39 insertions, 2 deletions
diff --git a/pyserial/serial/serialposix.py b/pyserial/serial/serialposix.py
index 4d6f36a..61252e2 100644
--- a/pyserial/serial/serialposix.py
+++ b/pyserial/serial/serialposix.py
@@ -13,7 +13,7 @@
import sys, os, fcntl, termios, struct, select, errno
from serialutil import *
-VERSION = "$Revision: 1.33 $".split()[1] #extract CVS version
+VERSION = "$Revision: 1.34 $".split()[1] #extract CVS version
#Do check the Python version as some constants have moved.
if (sys.hexversion < 0x020100f0):
@@ -121,6 +121,40 @@ TIOCM_zero_str = struct.pack('I', 0)
TIOCM_RTS_str = struct.pack('I', TIOCM_RTS)
TIOCM_DTR_str = struct.pack('I', TIOCM_DTR)
+baudrate_constants = {
+ 0: 0000000, # hang up
+ 50: 0000001,
+ 75: 0000002,
+ 110: 0000003,
+ 134: 0000004,
+ 150: 0000005,
+ 200: 0000006,
+ 300: 0000007,
+ 600: 0000010,
+ 1200: 0000011,
+ 1800: 0000012,
+ 2400: 0000013,
+ 4800: 0000014,
+ 9600: 0000015,
+ 19200: 0000016,
+ 38400: 0000017,
+ 57600: 0010001,
+ 115200: 0010002,
+ 230400: 0010003,
+ 460800: 0010004,
+ 500000: 0010005,
+ 576000: 0010006,
+ 921600: 0010007,
+ 1000000: 0010010,
+ 1152000: 0010011,
+ 1500000: 0010012,
+ 2000000: 0010013,
+ 2500000: 0010014,
+ 3000000: 0010015,
+ 3500000: 0010016,
+ 4000000: 0010017
+}
+
class Serial(SerialBase):
"""Serial port class POSIX implementation. Serial port configuration is
@@ -180,7 +214,10 @@ class Serial(SerialBase):
try:
ispeed = ospeed = getattr(TERMIOS,'B%s' % (self._baudrate))
except AttributeError:
- raise ValueError('Invalid baud rate: %r' % self._baudrate)
+ try:
+ ispeed = ospeed = baudrate_constants[self._baudrate]
+ except KeyError:
+ raise ValueError('Invalid baud rate: %r' % self._baudrate)
#setup char len
cflag &= ~TERMIOS.CSIZE
if self._bytesize == 8: