CTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
// should work http://cscene.org // this little test program only sends data out the parallel port #include <stdio.h> #include <unistd.h> /* needed for ioperm() */ #include <asm/io.h> /* for outb() and inb() */ #include <curses.h> /* for reading characters without pressing "return" */ #define PORT 0x378 #define DATA 0x378 #define STATUS DATA+1 #define CONTROL DATA+2 int main(int argc, char **argv) { int i,n=0,toggleport,value=0; //int value = 0; for (i=1;i<argc-1;i++) { sscanf(argv[i],"%x",&n); //sscanf(argv[++i],"%x",&v); } if (ioperm(DATA,3,1)) { printf("Sorry, you were not able to gain access to the ports\n"); printf("You must be root to run this program\n"); exit(1); } outb(n,PORT); //outb(DATA, x); /* Sends 0011 0010 to the Data Port */ //outb(CONTROL, y^0x0b); /* SELECT_IN = 1, INIT = 0, /AUTO_FEED = 0, /STROBE = 0 */ // figure out what to send initscr(); cbreak(); while(1){ printw ("enter a output (1-8) you want to toggle; press 0 to turn them all off; q to quit \n"); // go to "curses" mode no std. unix I/O can be used here! toggleport=getch(); toggleport=toggleport-48; if (toggleport==65){ printw ("\n end \n "); break; } // scanf ("%d",&toggleport); while (toggleport<0||toggleport>=9){ printw("\n enter a number between 1 and 8 for the parallel port number you want to turn on or of; q to quit... you entered: %d \n", toggleport); toggleport=getch(); toggleport=toggleport-48; //scanf ("%d",&toggleport); if (toggleport==65){ printw ("\n end \n "); break; } } if (toggleport==0) { printw ("clearing port, all off"); value=0; outb(0,PORT); } else{ printw ("\n value was: %d...",toggleport); if (toggleport==1) value=value+1; if (toggleport==2) value=value+2; if (toggleport==3) value=value+4; if (toggleport==4) value=value+8; if (toggleport==5) value=value-1; if (toggleport==6) value=value-2; if (toggleport==7) value=value-4; if (toggleport==8) value=value-8; //send the data to PORT // ioperm(PORT,1,1); printw("sending to port %d \n",value); outb(value,PORT); //sleep(1); // outb(0,PORT); } //done printw("done\n\n"); // sleep(1); } endwin(); outb(0,PORT); printf("end \n"); return (0); }