#include <stdio.h>
#include <sys/ioctl.h>
#include <linux/ppdev.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
/*
* Setbits.c <alarch@gmail.com>
*
* Program to open / close parallel port "data lines". In other words, to get
* voltage out from wanted pins.
*
* Borrowing some (well, 90% code from the Sochers' robot project.
*
* ( http://www.linuxfocus.org/English/May2001/article205.shtml#205lfindex6 )
*
* 7.1.2005 | Under GPL
* See http://www.gnu.org/copyleft/ for details.
*
*/
long bin2dec(char *s)
{
long r=0;
for (; *s; r = (r<<1) | (*s++ - '0'));
return r;
}
int claim_port(char *dev)
{
int fd;
fd = open(dev, O_RDWR);
if(fd < 0)
{
printf("Unable to open device\n");
exit(1);
}
return fd;
}
int setport(int fd,int bits)
{
int rc = ioctl(fd,PPWDATA,&bits);
return rc;
}
int main(int argc, char *argv[])
{
int fd = claim_port("/dev/parport0");
int bincmd = bin2dec(argv[1]);
//printf("%d",bincmd);
setport(fd,bincmd);
return 0;
}