Jonathan Oxer
[Automation]
Automation > Code Snippets > Reading
Reading from the parallel port
Getting direct access to the parallel port from scripting languages like PHP, Perl and Python can sometimes be a pain. You can compile a trivial helper program in C that you can then call from your script to read the port.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/io.h>
#define portaddress 0x378
main(void)
{
int value;
ioperm(portaddress,3,1);
value = inb(portaddress + 1);
printf("%x\n", value);
}
Save that snippet into a file such as "lptin.c", then compile it like this:
gcc -O lptin.c -o lptin
Then run it with root privileges to read the current value of the port:
sudo ./lptin
[ Back to top ]