I solved the problem I asked about a few days ago, of writing raw data
to the parallel port. I'm writing this so that something remains in
the archives, should anyone meet the same problem in the future.
Corrections are welcome.
The task is of driving an I/O board attached to the parallel port
under Linux, and other x86-based *nix I guess.
There is no direct equivalent of C's low level outb().
Opening /dev/lp0 as a file does not work. Apparently, there is extra
processing involved in a /dev/lpxx device, and when you just write a
byte to it, it sits there waiting indefinitely.
It works by using /dev/port. (Log as root if you want to try the
following.)
p = open('/dev/port', 'w') # open /dev/port in write mode
p.sync = true # turn buffering off, write to the
# port as soon as it is requested
p.seek(0x378, IO::SEEK_SET) # move writing cursor to the parallel
# port address
p.putc(0b1) # write 00000001 to it and activate
# whatever on your I/O board is
# attached to the D0 pin
p.seek(0x378, IO::SEEK_SET) # back again to the port
p.putc(0b0) # write 00000000 and unset the D0 pin
Instead of turning sync on, you could also write normally to the port
and then use the flush method (p.flush) to force writing. (Thanks
Mathieu for poiting both methods out.)
If you want access /dev/port as a non-root users: as root, run `vigr'
and insert the user you want to grant access into the group of
/dev/port (on my system this is `kmem'), then give group write
permission to /dev/port with `chmod g+w /dev/port'. Keep in mind that
this is potentially much more harmful than giving a user access to a
/dev/lpxx device because virtually every port can be accessed through
/dev/port.
Useful pointer:
http://www.linuxdoc.org/HOWTO/mini/IO-Port-Programming.html
Massimiliano