#include #include #include #include #include #define LPT_DATA 0x378 #define LPT_STATUS 0x379 #define LPT_CONTROL 0x37a main(int argc, char *argv[]) { int devIOHandle,arg; u_char d,s,c; /* enable direct ports I/O */ devIOHandle = open("/dev/io", O_RDONLY/*O_RDWR*/); if (devIOHandle == -1){ printf("ERROR: Can not get IO permission (%s)", strerror(errno)); exit(1); } int a=0,b=0,bb=0,b0=0,b1=0,strob=0,w=200; while ((arg = getopt(argc, argv, "hsd:c:w:")) != -1) { switch (arg) { case 'w': w=atoi(optarg); break; case 'd': a=atoi(optarg); // printf("send to data=%d\n",a); outb(LPT_DATA,a); break; case 's': strob=1; break; case 'c': bb=1; b=atoi(optarg); break; case 'h': default: fprintf(stderr, "LPT1 data send program\nUsage: lptsend [-s] [-d data] [-c control] [-w wait_ms]\n\t-d data\t\tWrite byte data to LPT_DATA port\n\t-c control\tWrite byte control to LPT_CONTROL port\n\t-s\t\tWrite data with strob C0\n\t-w wait_ms\tStrob (ms)\n"); exit(1); } } if(strob==1) { b0=b & 254; b1=b | 1; // printf("send to control b1=%d, b0=%d, b1=%d\n",b1,b0,b1); outb(LPT_CONTROL,b1); outb(LPT_CONTROL,b0); usleep(w*1000); outb(LPT_CONTROL,b1); } else if (bb==1) { // printf("send to control=%d\n",b); outb(LPT_CONTROL,b); } d=inb(LPT_DATA); s=inb(LPT_STATUS); c=inb(LPT_CONTROL); printf("%d %d %d\n",d,s,c); /* disable direct ports I/O */ close(devIOHandle); }