Parallel port access trouble
I haven't been able to send information through the PC parallel port. I am using the following code to try to send data:
#include <stdio.h>
#include <asm/io.h>
#include <unistd.h>
int main(void){
ioperm( 0x378, 1, 1 );
outb( 0x378, 0xAA );
sleep( 2000 );
outb( 0x378, 0x55 );
sleep( 2000 );
outb( 0x378, 0x00 );
return 0;
}
Because it failed (for a reason that I am unaware of) I tried the following program which, I think, is equivalent to the previous one:
#include <asm/io.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
int main(void){
const int PORT = 0x378;
int fd = open("/dev/port", O_WRONLY, 0);
unsigned char val;
if( fd < 0 ){
printf("Error");
exit(1);
}
lseek(fd, PORT, SEEK_SET);
val = 0x50;
write(fd, &val, sizeof(val));
sleep(2000);
val = 0xA0;
write(fd, &val, sizeof(val));
sleep(2000);
val = 0x00;
write(fd, &val, sizeof(val));
close(fd);
return 0;
}
I'm running the program as the root user, so I have all priveleges. I am verifying the output with a bunch of LEDs that are supposed to turn on when I send a 1. I've already tried a similar code in Windows and it works as expected. Help or suggestions are warmly welcome.
__________________
History is the memory of humanity.