Cross platform serial library?

Andrew M. Kuchling akuchlin at cnri.reston.va.us
Tue May 18 09:27:20 EDT 1999


Richard Wall writes:
>Anyway, looking through the lib docs, I am unable to find a serial
>communications library that will work across platforms. Am I just looking in
>the wrong place, or is this something python does not have. I would like it

	I'm not aware of any cross-platform interface for serial
comms, but it would be a very good idea to invent one.  Probably we
should arrive at an interface, and then implement it for every
different platform; on Windows it would use the sio module; I have a
simple serial port class for Unix; I don't know how you'd do it on the
MacOS, but Pythonmac probably has some support for serial I/O.

	Here's an impromptu proposal:

port = SerialPort( devicename, speed = 9600, stop_bits = 1, parity = 'N' )

Create a serial port instance. 
devicename is a string like '/dev/ttyS0' or 'COM1:'.
speed is the baud rate, and is one of [300, 1200, 2400, 9600, 57600, ...]
stop_bits: # of stop bits (0, 1, or 2)
Parity: 'N' for none, 'O' for odd, (XXX isn't there a third mode?)

Missing things: buffering mode (line-by-line, or character by
character?)

Serial ports should imitate file objects as much as possible, so
they'll have .close(), .read(), .write(), .readline(), etc.  .tell()
and .seek() would raise exceptions.

I've only implemented the bits of serial I/O that I needed at the
time, so I'm sure there are serial port capabilities missing from this
interface.

-- 
A.M. Kuchling			http://starship.python.net/crew/amk/
Apparently, to implement this ominous mess, *two* committees have been
"impaneled". At first glance, I read this as "impaled" (wishful thinking).
    -- Stan Kelly-Bootle, _The Computer Contradictionary_





More information about the Python-list mailing list