[Edu-sig] Converting from Qbasic

Dethe Elza delza@mac.com
Tue, 07 May 2002 09:33:36 -0700

On Friday, May 3, 2002, at 03:37  PM, Seth David Schoen wrote:

There isn't anything built in to Python which does port I/O.  Doing
port I/O is a low-level and platform-specific operation.  (For
example, it doesn't exist conceptually in Java at all.  It exists on
all PC operating systems, but on Linux and on Windows NT there is a
concept that the user running the code might not be permitted to
perform that operation.)

There may not be any built-in serial I/O in Python (well there is, but 
only for Posix, although PyWin gives access to the Windows serial access 
methods), but there are plenty of third party solutions, as a quick 
google discovered:

Universal Serial Port Python Library (windows/linux)
"Pure Python," wraps existing serial APIs to give a standard interface

Python Serial Port Extension (pySerial: linux/bsd(posix)/windows/jython)
"Pure Python," as above, but more ambitious in scope

Java also can access serial and parallel ports through the JavaComm API:
http://republika.pl/mho/java/comm/ (links to implementations for many 

This used to be a much harder problem.  I think Lego Mindstorms inspired 
a lot of people to solve it %-)

While Python can give access to serial, parallel, and joystick ports, I 
didn't find any standard libaries or APIs for USB or Firewire access.  
There were a couple of windows-only USB project, some python info in the 
general Linux-USB project, but not much else.  One Japanese page looked 
promising, with python info for accessing all kinds of hardware, 
including gameboys, etc., but my Japanese was never that good and it 
hasn't improved with years of neglect.

The good news is that, if your OS supports these interfaces, there's 
probably a way to call native system services to access them.  The bad 
news is that they haven't been wrapped in a convenient python API yet.

How can I be so sure there's a way to do it?  On windows there is a 
calldll python extension which allows you to, you guessed it, call any 
DLL, so the hardest part is finding accurate documentation on assembling 
the call.  On Linux everything is treated as a file, so if the kernel 
supports serial ports or USB (or whatever) you can generally access it 
via Posix calls (same with BSD/OS X and other Posix systems).  On older 
MacOS and less common systems (OS/2, BeOS, Amiga, etc.) you may be out 
of luck--at least I don't know of any common way to access the hardware 
on those systems (BeOS can probably do it through BMessages or 

Have fun!


(Seth, sorry about the duplicate, thought I was sending to the list).

"Melting down holy grails to make silver bullets for my .357 Panacea"
Dethe Elza (delza@burningtiger.com)
Chief Mad Scientist
Enfolding Systems (http://enfoldingsystems.com)
Weblog: http://livingcode.ca/