```c //gcc -opport pport.c #include <linux/ppdev.h> #include <linux/parport.h> #include <stropts.h> #include <stdio.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <sys/ioctl.h> #include <sys/select.h> #define PP_DEV_NAME "/dev/parport0" int main() { //Get a file descriptor for the parallel port int ppfd; ppfd = open(PP_DEV_NAME, O_RDWR); if(ppfd == -1) { printf("Unable to open parallel port!\n"); return 1; } //Have to claim the device if(ioctl(ppfd, PPCLAIM)) { printf("Couldn't claim parallel port!\n"); close(ppfd); return 1; } while(1) { //Set up the control lines for when an interrupt happens int int_count; int busy = PARPORT_STATUS_ACK | PARPORT_STATUS_ERROR; int acking = PARPORT_STATUS_ERROR; int ready = PARPORT_STATUS_ACK | PARPORT_STATUS_ERROR; unsigned char value; int dir = 1; ioctl(ppfd, PPDATADIR, &dir); // data port as inputs //Let ppdev know we're ready for interrupts ioctl(ppfd, PPWCONTROL, &ready); //Wait for an interrupt.................................................... fd_set rfds; FD_ZERO(&rfds); FD_SET(ppfd, &rfds); if(select(ppfd + 1, &rfds, NULL, NULL, NULL)) { printf("Received interrupt\n"); } else { printf("No interrupt\n"); continue; //Caught a signal }//......................................................................... //Read Data port ioctl(ppfd, PPRDATA, &value[i]); unsigned int int_value = value; printf("data = %i\n", int_value); //Clear the interrupt ioctl(ppfd, PPCLRIRQ, &int_count); if(int_count > 1) printf("Uh oh, missed %i interrupts!\n", int_count - 1); //Acknowledge the interrupt //ioctl(ppfd, PPWCONTROL, &acking); //usleep(2); //ioctl(ppfd, PPWCONTROL, &busy); } return 0; } ```
Interrupciones Puerto Paralelo en C
Ejemplo de uso, espera por una interrupciĆ³n, lee e imprime por pantalla el valor presente en el puerto de datos.
Fast linked list without list
If you need a very fast way to iterate over a list of objects and call the same method on all of them, then here is a posible solution. Der...
-
Sometimes is useful resizing a QListWidget to the size of its content. This is one way to do it. Don't forget resizing again when you...
-
Adding a submenu to a QMenu is really easy, and you add nested submenus if you want: ```c QMenu* mainMenu; QAction* action1 = mainMenu...