FrenKy
26-03-2007, 11:56 AM
Hi *,
I have one problem writing to parallel port...
From what I've tried, "outb(value, port);" works, but my problem is that
I have an app that accesses the port differently, using /dev/port
(parport0).
Now, I can't change the way the port is accessed (I'm not the author of
the app), it is huge and I do not want to rewrite it... I've managed to
recreate behavior with this simple code:
extern int errno;
int main( int argc, char **argv )
{
int fd;
char input[5];
errno = 0;
printf("Trying to open %s\n", argv[1] );
fd = open( argv[1] , O_RDWR | O_NONBLOCK );
if( fd < 0 ) {
fprintf( stderr, "Open failed with: " );
goto fail;
}
if ( strcmp(argv[2],"r")==0){
if ( read( fd, input, 5 ) < 0 ) {
fprintf( stderr, "Read failed with: " );
goto fail;
}else{
fprintf( stdout, "Read OK..\n" );
}
}else{
if ( write( fd, "hello\n", sizeof( "hello\n" ) ) < 0 ) {
fprintf( stderr, "Write failed with: " );
goto fail;
}else{
fprintf(stdout, "Write OK...");
}
}
close( fd );
exit(0);
fail:
fprintf( stderr, strerror( errno ) );
fprintf( stderr, "\n" );
close( fd );
exit(1);
}
for read i get in strace:
9114 fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 3), ...}) = 0
9114 mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
-1, 0) = 0xb7f30000
9114 write(1, "Trying to open /dev/parport0\n", 29) = 29
9114 open("/dev/parport0", O_RDWR|O_NONBLOCK) = 3
9114 read(3, 0xbfe4e553, 5) = -1 EINVAL (Invalid argument)
9114 write(2, "Read failed with: ", 18) = 18
9114 write(2, "Invalid argument", 16) = 16
and for write I get much the same thing:
9149 fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 3), ...}) = 0
9149 mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
-1, 0) = 0xb7f9c000
9149 write(1, "Trying to open /dev/parport0\n", 29) = 29
9149 open("/dev/parport0", O_RDWR|O_NONBLOCK) = 3
9149 write(3, "hello\n\0", 7) = -1 EINVAL (Invalid argument)
9149 write(2, "Write failed with: ", 19) = 19
9149 write(2, "Invalid argument", 16) = 16
I've tried all the commands as root.
bash# ls -l /dev/parport0
crw-rw---- 1 root lp 99, 0 2007-03-25 22:25 /dev/parport0
bash# grep ppdev /proc/devices
99 ppdev
bash# modprobe -l|grep ppdev
/lib/modules/2.6.17-11-generic/kernel/drivers/char/ppdev.ko
Port is set up as EPP in BIOS.
bash# dmesg |grep par
[17179590.040000] parport: PnPBIOS parport detected.
[17179590.040000] parport0: PC-style at 0x378, irq 7 [PCSPP,TRISTATE,EPP]
[17179591.400000] lp0: using parport0 (interrupt-driven).
[17183898.736000] ppdev: user-space parallel port driver
[17184446.412000] ppdev0: registered pardevice
Any help appreciated...
I have one problem writing to parallel port...
From what I've tried, "outb(value, port);" works, but my problem is that
I have an app that accesses the port differently, using /dev/port
(parport0).
Now, I can't change the way the port is accessed (I'm not the author of
the app), it is huge and I do not want to rewrite it... I've managed to
recreate behavior with this simple code:
extern int errno;
int main( int argc, char **argv )
{
int fd;
char input[5];
errno = 0;
printf("Trying to open %s\n", argv[1] );
fd = open( argv[1] , O_RDWR | O_NONBLOCK );
if( fd < 0 ) {
fprintf( stderr, "Open failed with: " );
goto fail;
}
if ( strcmp(argv[2],"r")==0){
if ( read( fd, input, 5 ) < 0 ) {
fprintf( stderr, "Read failed with: " );
goto fail;
}else{
fprintf( stdout, "Read OK..\n" );
}
}else{
if ( write( fd, "hello\n", sizeof( "hello\n" ) ) < 0 ) {
fprintf( stderr, "Write failed with: " );
goto fail;
}else{
fprintf(stdout, "Write OK...");
}
}
close( fd );
exit(0);
fail:
fprintf( stderr, strerror( errno ) );
fprintf( stderr, "\n" );
close( fd );
exit(1);
}
for read i get in strace:
9114 fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 3), ...}) = 0
9114 mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
-1, 0) = 0xb7f30000
9114 write(1, "Trying to open /dev/parport0\n", 29) = 29
9114 open("/dev/parport0", O_RDWR|O_NONBLOCK) = 3
9114 read(3, 0xbfe4e553, 5) = -1 EINVAL (Invalid argument)
9114 write(2, "Read failed with: ", 18) = 18
9114 write(2, "Invalid argument", 16) = 16
and for write I get much the same thing:
9149 fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 3), ...}) = 0
9149 mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
-1, 0) = 0xb7f9c000
9149 write(1, "Trying to open /dev/parport0\n", 29) = 29
9149 open("/dev/parport0", O_RDWR|O_NONBLOCK) = 3
9149 write(3, "hello\n\0", 7) = -1 EINVAL (Invalid argument)
9149 write(2, "Write failed with: ", 19) = 19
9149 write(2, "Invalid argument", 16) = 16
I've tried all the commands as root.
bash# ls -l /dev/parport0
crw-rw---- 1 root lp 99, 0 2007-03-25 22:25 /dev/parport0
bash# grep ppdev /proc/devices
99 ppdev
bash# modprobe -l|grep ppdev
/lib/modules/2.6.17-11-generic/kernel/drivers/char/ppdev.ko
Port is set up as EPP in BIOS.
bash# dmesg |grep par
[17179590.040000] parport: PnPBIOS parport detected.
[17179590.040000] parport0: PC-style at 0x378, irq 7 [PCSPP,TRISTATE,EPP]
[17179591.400000] lp0: using parport0 (interrupt-driven).
[17183898.736000] ppdev: user-space parallel port driver
[17184446.412000] ppdev0: registered pardevice
Any help appreciated...