diff options
author | cliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a> | 2004-04-20 02:40:28 +0000 |
---|---|---|
committer | cliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a> | 2004-04-20 02:40:28 +0000 |
commit | 895e8305bdd17683b448788e18484ef4856c60f1 (patch) | |
tree | c5277530d29948148dfa9e067045988a9d54b1ec | |
parent | 626116161311f6ade383f4f603c8250e12cc8321 (diff) | |
download | pyserial-git-895e8305bdd17683b448788e18484ef4856c60f1.tar.gz |
- dynamicaly lookup baudrates
- better messages
- cleanups
-rw-r--r-- | pyserial/serial/__init__.py | 5 | ||||
-rw-r--r-- | pyserial/serial/serialposix.py | 37 |
2 files changed, 14 insertions, 28 deletions
diff --git a/pyserial/serial/__init__.py b/pyserial/serial/__init__.py index 75bb07f..ac916bb 100644 --- a/pyserial/serial/__init__.py +++ b/pyserial/serial/__init__.py @@ -6,7 +6,7 @@ # this is distributed under a free software license, see license.txt import sys, os, string -VERSION = string.split("$Revision: 1.2 $")[1] #extract CVS version +VERSION = string.split("$Revision: 1.3 $")[1] #extract CVS version #chose an implementation, depending on os if os.name == 'nt': #sys.platform == 'win32': @@ -16,6 +16,5 @@ elif os.name == 'posix': elif os.name == 'java': from serialjava import * else: - raise "Sorry no implementation for your platform available." + raise Exception("Sorry: no implementation for your platform ('%s') available" % os.name) -#no "mac" implementation. someone want's to write it? i have no access to a mac. diff --git a/pyserial/serial/serialposix.py b/pyserial/serial/serialposix.py index a03622e..337d2b8 100644 --- a/pyserial/serial/serialposix.py +++ b/pyserial/serial/serialposix.py @@ -13,7 +13,7 @@ import sys, os, fcntl, termios, struct, select from serialutil import * -VERSION = "$Revision: 1.21 $".split()[1] #extract CVS version +VERSION = "$Revision: 1.22 $".split()[1] #extract CVS version #Do check the Python version as some constants have moved. if (sys.hexversion < 0x020100f0): @@ -63,16 +63,19 @@ elif plat[:5] == 'sunos': #Solaris/SunOS (confirmed) else: #platform detection has failed... - info = "sys.platform = %r\nos.name = %r\nserialposix.py version = %s" % (sys.platform, os.name, VERSION) - print """send this information to the author of the pyserial: + print """don't know how to number ttys on this system. +! Use an explicit path (eg /dev/ttyS1) or send this information to +! the author of this module: -%s +sys.platform = %r +os.name = %r +serialposix.py version = %s also add the device name of the serial port and where the counting starts for the first serial port. e.g. 'first serial port: /dev/ttyS0' and with a bit luck you can get this module running... -""" +""" % (sys.platform, os.name, VERSION) #no exception, just continue with a brave attempt to build a device name #even if the device name is not correct for the platform it has chances #to work using a string with the real device name as port paramter. @@ -84,21 +87,6 @@ and with a bit luck you can get this module running... #they should work, just need to know the device names. -# construct dictionaries for baud rate lookups -baudEnumToInt = {} -baudIntToEnum = {} -for rate in (0,50,75,110,134,150,200,300,600,1200,1800,2400,4800,9600, - 19200,38400,57600,115200,230400,460800,500000,576000,921600, - 1000000,1152000,1500000,2000000,2500000,3000000,3500000,4000000 - ): - try: - i = eval('TERMIOS.B'+str(rate)) - baudEnumToInt[i]=rate - baudIntToEnum[rate] = i - except: - pass - - #load some constants for later use. #try to use values from TERMIOS, use defaults from linux otherwise TIOCMGET = hasattr(TERMIOS, 'TIOCMGET') and TERMIOS.TIOCMGET or 0x5415 @@ -166,14 +154,13 @@ class Serial(SerialBase): lflag &= ~(TERMIOS.ICANON|TERMIOS.ECHO|TERMIOS.ECHOE|TERMIOS.ECHOK|TERMIOS.ECHONL| TERMIOS.ECHOCTL|TERMIOS.ECHOKE|TERMIOS.ISIG|TERMIOS.IEXTEN) #|TERMIOS.ECHOPRT oflag &= ~(TERMIOS.OPOST) + iflag &= ~(TERMIOS.INLCR|TERMIOS.IGNCR|TERMIOS.ICRNL|TERMIOS.IGNBRK) if hasattr(TERMIOS, 'IUCLC'): - iflag &= ~(TERMIOS.INLCR|TERMIOS.IGNCR|TERMIOS.ICRNL|TERMIOS.IUCLC|TERMIOS.IGNBRK) - else: - iflag &= ~(TERMIOS.INLCR|TERMIOS.IGNCR|TERMIOS.ICRNL|TERMIOS.IGNBRK) + iflag &= ~TERMIOS.IUCLC #setup baudrate try: - ispeed = ospeed = baudIntToEnum[self._baudrate] - except: + ispeed = ospeed = getattr(TERMIOS,'B%s' % (self._baudrate)) + except AttributeError: raise ValueError('Invalid baud rate: %r' % self._baudrate) #setup char len cflag &= ~TERMIOS.CSIZE |