Cross platform serial library?

Paul Duffin pduffin at mailserver.hursley.ibm.com
Fri May 21 09:50:14 EDT 1999


Cameron Laird wrote:
> 
> In article <14145.26380.455559.698878 at amarok.cnri.reston.va.us>,
> Andrew M. Kuchling <akuchlin at cnri.reston.va.us> wrote:
> >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.
>                         .
>                         .
>                         .
> The Tcl <URL:http://starbase.neosoft.com/~claird/comp.lang.tcl/
> tcl-examples.html#serial> and Perl <URL:http://language.perl.com/
> newdocs/pod/perlfaq8.html#How_do_I_read_and_write_the_seri>
> people have covered much of the same territory in this direction.
> Both have half-abstracted serial communications; you can write
> useful programs, but only if you know your operating system.
> 
> I'm optimistic that an effort to write a cross-platform library
> would win support--maybe even workers!--from several camps, perhaps
> including also PHP and Lua.  I don't think this would have happened
> six months ago, but now more developers seem to understand that
> syntax is secondary.

A cross platform / cross language library would have to be split into
two parts.
	Language independent / platform independent layer
	Language interface

Getting the top one right would obviously be harder work than just
implementing a language specific interface but should be possible.

-- 
Paul Duffin
DT/6000 Development	Email: pduffin at hursley.ibm.com
IBM UK Laboratories Ltd., Hursley Park nr. Winchester
Internal: 7-246880	International: +44 1962-816880




More information about the Python-list mailing list