81 lines
1.2 KiB
C
81 lines
1.2 KiB
C
|
|
#include <stdio.h>
|
|
#include <sys/ioctl.h>
|
|
#include <linux/parport.h>
|
|
#include <linux/ppdev.h>
|
|
#include <fcntl.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
#include <signal.h>
|
|
|
|
#define WAIT 100000
|
|
|
|
int running = 1;
|
|
|
|
void signalHandler(int sig)
|
|
{
|
|
running = 0;
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
int fd;
|
|
int result;
|
|
|
|
signal(SIGINT, signalHandler);
|
|
|
|
fd = open("/dev/parport0", O_RDWR);
|
|
|
|
if (fd == -1)
|
|
{
|
|
perror("Could not open parallel port");
|
|
return 1;
|
|
}
|
|
|
|
printf("Claiming parallel port\n");
|
|
if (ioctl(fd, PPCLAIM, NULL))
|
|
{
|
|
perror("Could not claim the parallel port!");
|
|
close(fd);
|
|
return 2;
|
|
}
|
|
|
|
int mode = IEEE1284_MODE_BYTE;
|
|
if (ioctl(fd, PPSETMODE, &mode))
|
|
{
|
|
perror("Could not set mode");
|
|
ioctl(fd, PPRELEASE);
|
|
close(fd);
|
|
return 3;
|
|
}
|
|
|
|
int dir = 0x00;
|
|
if (ioctl(fd, PPDATADIR, &dir))
|
|
{
|
|
perror("Could not set parallel port direction");
|
|
ioctl(fd, PPRELEASE);
|
|
close(fd);
|
|
return 4;
|
|
}
|
|
|
|
char dataH = 0xFF;
|
|
char dataL = 0x00;
|
|
|
|
for(;;)
|
|
{
|
|
ioctl(fd, PPWDATA, &dataH);
|
|
usleep(WAIT);
|
|
if (!running)
|
|
break;
|
|
ioctl(fd, PPWDATA, &dataL);
|
|
usleep(WAIT);
|
|
if (!running)
|
|
break;
|
|
}
|
|
|
|
printf("Releasing parallel port\n");
|
|
ioctl(fd, PPRELEASE);
|
|
close(fd);
|
|
return 0;
|
|
}
|