Controlling the Parallel Port
Cary O'Brien
cobrien at Radix.Net
Wed Dec 27 14:36:44 EST 2000
In article <mvuj4tkmn22gbth1a6t8fag39902qeeu9l at 4ax.com>,
Simon Faulkner <News at Titanic.co.uk> wrote:
>Is it easy to control (read/write) the Parallel Port in linux using
>Python?
>
>I am hoping to use it to drive some simple electronics
>
You need to do two things to access the parallel port from
a user program.
1) call ioperm() to get permissions to access the ports. man ioperm
should provide the gory details. Requires root access.
2) use the inb() macro to read, and the outb() macro to write. See
man outb for the gory details. Pay attension to the note about using
-O or -O2 on the compile command line. They matter.
Now to access this from python, you can either
a) write C extensions for ioperm() and inb/outb (and run as root)
b) write C extensions for ioperm() and inb/outb and hack the kernel
to let user programs execute ioperm()
c) write a C program that does the ioperm and low level read/write and access it
from python, like say using popen2. If you make the C program suid-root, you
don't have to run python as root.
d) Write a device driver for your device.
Much as I like b), I use c). Well, to be honest I access the C program
from TCL, but it is the same idea. Works great.
Is this a microwire device? I.E. a serial eeprom? If so, drop me a line,
I have a program that may do the trick.
-- cary
More information about the Python-list
mailing list