Serial Port communication

Peter Hansen peter at engcorp.com
Fri Sep 22 01:11:42 EDT 2000


pehr anderson wrote:
> ...
> As for what would be the right long term solution...
> Is there a best-in-class serial API that should be cloned?
> What do people think of the RXTX package for Java?
> 
>         -pehr
> 
> Warren Postma wrote:
> >
> > "Grant Edwards" <nobody at nowhere.nohow> wrote in message
> > news:slrn8s2t3j.88s.nobody at isis.visi.com...
> > > In article <8pric7$bn2 at news.or.intel.com>, Brian Geddes wrote:
> > >
> > > >All - I'm looking for a way to communicate through the serial port from
> > > >inside of a Python script.  Ideally, I'd be able to open it and treat it
> > > >like a file stream...anyone know how to do this?
> > >
> > > Serial port stuff under Python is OS-specific.  Which OS are you using?
> > >
> >
> > Anyone else think this is bad? I would like a standard serial module for
> > both Unix and Win32 for starters.
> > Anyone done this already?

I agree this is bad, and have thought so since I encountered the same
problem with Java, early on.  At the time, and I think perhaps still
now, nobody had yet created anything that would be a deserving candidate
for the title "standard serial module for both Unix and Win32".  I made
a very crufty one for Win32, in the process learning many
Windows-specific things which I still shudder over as I recall.  Hideous
problems with lost characters when run from a DOS window, for example,
but not when run from Windows directly.  (This in spite of the hefty
buffering the interrupt should have been doing.)

The solution Sun developed for Java was, IMHO, rather nice, although
some people seemed to object to the event-driven nature of some of the
API.  And I don't recall if it is available on non-Win32 versions.  If
it is, I would consider it a possible "best-in-class".  (Hmmm... might
even consider wrapping the DLL if that would work, using calldll or
something.)

For Python use, we wrapped the win32 routines with a very rough Python
wrapper "class SerialPort(Port):" which works okay, but doesn't support
read/write from separate threads, which might be considered a
requirement for a "best-in-class".  I didn't like the existing
alternatives.

-- 
Peter Hansen



More information about the Python-list mailing list