#include #include #include #include #include #include #include #include #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; }