Okay, after posting my previous patch to the list, I read some older
messages and saw that the python code has been reorganized into a new
directory. So, here is basically the same patch as last time, but
it's against the python/msp430/serial directory instead of the
pybsl/serial directory.

  - Made it a non-fatal error if it can't figure out how to
    convert an integer to a device file name. On unixlike systems,
    the normal way to specify a serial port is by its entry
    in /dev (since there isn't necessarily a fixed or agreed-upon
    numbering of serial devices).
  - Changed the baudrate enum code to avoid using a fixed
    table of possible baud rates.
  - Changed the openbsd case so that it does the expected thing
    if you're running on PC hardware (com1 --> /dev/tty00, etc.)
  - Deleted unused symbols from the module after initialization.
  - Simplified some of the termios arithmetic slightly.

Wim.

Index: python/msp430/serial/__init__.py
===================================================================
RCS file: /cvsroot/mspgcc/python/msp430/serial/__init__.py,v
retrieving revision 1.1
diff -c -r1.1 __init__.py
*** python/msp430/serial/__init__.py    29 Feb 2004 23:06:36 -0000      1.1
--- python/msp430/serial/__init__.py    11 Apr 2004 00:38:01 -0000
***************
*** 5,12 ****
  # (C)2001-2002 Chris Liechti <cliec...@gmx.net>
  # this is distributed under a free software license, see license.txt
  
! import sys, os, string
! VERSION = string.split("$Revision: 1.1 $")[1]     #extract CVS version
  
  #chose an implementation, depending on os
  if os.name == 'nt': #sys.platform == 'win32':
--- 5,12 ----
  # (C)2001-2002 Chris Liechti <cliec...@gmx.net>
  # this is distributed under a free software license, see license.txt
  
! import os
! VERSION = "$Revision: 1.1 $".split()[1]     #extract CVS version
  
  #chose an implementation, depending on os
  if os.name == 'nt': #sys.platform == 'win32':
***************
*** 16,21 ****
  elif os.name == 'java':
      from serialjava import *
  else:
!     raise "Sorry no implementation for your platform available."
  
! #no "mac" implementation. someone want's to write it? i have no access to a 
mac.
--- 16,26 ----
  elif os.name == 'java':
      from serialjava import *
  else:
!     raise "Sorry: no serial implementation for platform '%s'" % os.name
  
! # no "mac" implementation. someone want's to write it? i have no access
! # to a mac. [cliechti]
! 
! # note that macos 10 is a posix system and will work with the serialposix
! # implementation, only version 9 and older need a mac-specific implementation
! # [wiml]
Index: python/msp430/serial/serialposix.py
===================================================================
RCS file: /cvsroot/mspgcc/python/msp430/serial/serialposix.py,v
retrieving revision 1.1
diff -c -r1.1 serialposix.py
*** python/msp430/serial/serialposix.py 29 Feb 2004 23:06:36 -0000      1.1
--- python/msp430/serial/serialposix.py 11 Apr 2004 00:38:02 -0000
***************
*** 10,16 ****
  #  ftp://ftp.visi.com/users/grante/python/PosixSerial.py
  # references: http://www.easysw.com/~mike/serial/serial.html
  
! import sys, os, fcntl, termios, struct, select
  from serialutil import *
  
  VERSION = "$Revision: 1.1 $".split()[1]     #extract CVS version
--- 10,16 ----
  #  ftp://ftp.visi.com/users/grante/python/PosixSerial.py
  # references: http://www.easysw.com/~mike/serial/serial.html
  
! import sys, os, fcntl, termios, struct, select, re
  from serialutil import *
  
  VERSION = "$Revision: 1.1 $".split()[1]     #extract CVS version
***************
*** 39,45 ****
  
  elif plat     == 'openbsd3': #BSD (confirmed)
      def device(port):
!         return '/dev/ttyp%d' % port
  
  elif plat[:3] == 'bsd' or  \
       plat[:6] == 'netbsd' or \
--- 39,45 ----
  
  elif plat     == 'openbsd3': #BSD (confirmed)
      def device(port):
!         return '/dev/tty%02d' % (port - 1)
  
  elif plat[:3] == 'bsd' or  \
       plat[:6] == 'netbsd' or \
***************
*** 62,84 ****
          return '/dev/tty%c' % (ord('a')+port)
  
  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:
  
  %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...
! """
!     #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.
!     def device(portum):
!         return '/dev/ttyS%d' % portnum
!     #~ raise Exception, "this module does not run on this platform, sorry."
  
  #whats up with "aix", "beos", ....
  #they should work, just need to know the device names.
--- 62,82 ----
          return '/dev/tty%c' % (ord('a')+port)
  
  else:
!     # unknown platform; we don't know how to convert an integer to a /dev 
entry
      info = "sys.platform = %r\nos.name = %r\nserialposix.py version = %s" % 
(sys.platform, os.name, VERSION)
!     def device(port, info=info):
!         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
  
  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'
! """ % info
!         raise Exception, "can't handle numeric serial ports on this platform"
!     del info
  
  #whats up with "aix", "beos", ....
  #they should work, just need to know the device names.
***************
*** 87,102 ****
  # 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.
--- 85,99 ----
  # construct dictionaries for baud rate lookups
  baudEnumToInt = {}
  baudIntToEnum = {}
! baudEnumPattern = re.compile('^B([0-9]+)$')
! for baudEnumName in dir(TERMIOS):
!     match = baudEnumPattern.match(baudEnumName)
!     if match:
!         rate = int(match.group(1))
!         baudEnumValue = getattr(TERMIOS, baudEnumName)
!         baudEnumToInt[baudEnumValue]=rate
!         baudIntToEnum[rate] = baudEnumValue
! del baudEnumPattern, baudEnumName, baudEnumValue, rate, match
  
  
  #load some constants for later use.
***************
*** 165,174 ****
          lflag &= 
~(TERMIOS.ICANON|TERMIOS.ECHO|TERMIOS.ECHOE|TERMIOS.ECHOK|TERMIOS.ECHONL|
                            
TERMIOS.ECHOCTL|TERMIOS.ECHOKE|TERMIOS.ISIG|TERMIOS.IEXTEN) #|TERMIOS.ECHOPRT
          oflag &= ~(TERMIOS.OPOST)
          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)
          #setup baudrate
          try:
              ispeed = ospeed = baudIntToEnum[self._baudrate]
--- 162,170 ----
          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.IUCLC)
          #setup baudrate
          try:
              ispeed = ospeed = baudIntToEnum[self._baudrate]
***************
*** 385,387 ****
--- 381,388 ----
      print repr(s.read(5))
      print s.inWaiting()
      del s
+ 
+ # remove unused references from the module
+ del sys, re
+ del plat
+ 

Reply via email to