[Edu-sig] Converting from Qbasic

Seth David Schoen schoen@loyalty.org
Fri, 3 May 2002 15:37:53 -0700

Jeffrey Elkner writes:

> Hi all!
> My students are working on end of the year projects, and one of our best
> students, Nick Wheeler, is interested in converting a qbasic program
> that controls an electric motor through the parallel port into Python.
> The QBasic program is included below, but the main issues seem to me to
> be:
> 1. What are the Python equivalents of PEEK, POKE, and OUT? (how do you
> do something like:  
> pdata% = PEEK(&H408) + PEEK(&H409) * 256
> 2.  Alternatively, is there a more pythonic way to do such things.

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.)

The most canonical way to do it would be to write a module in C and
then call into it from Python.  It turns out that people have done


I hope that helps; it looks to me like it's what you're looking for.

When I had to do this, I wrote a separate stand-alone C program which
took arguments on the command line and then called into it using
os.system.  This is faster to write but much less efficient to use;
it's only practical if you want to do I/O at a very low data rate.
(In my case, it was precisely one byte per second, and so it was

I'd like to find some cheap digital I/O cards with simple and
well-documented interfaces and then try to get them working with
Python.  The parallel port is great, and widely available, but
it's not exactly state-of-the-art and not convenient for controlling
or accepting input from many devices at once.

Seth David Schoen <schoen@loyalty.org> | Reading is a right, not a feature!
     http://www.loyalty.org/~schoen/   |                 -- Kathryn Myronuk
     http://vitanuova.loyalty.org/     |