parport problem
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > parport problem




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    parport problem  
FrenKy


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-26-07 06:36 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...





[ Post a follow-up to this message ]



    Re: parport problem  
Tarkin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-26-07 06:36 AM

On Mar 25, 10:56 pm, FrenKy <fre...@foo.com> wrote:
> 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,TRISTA
TE,EPP]
> [17179591.400000] lp0: using parport0 (interrupt-driven).
> [17183898.736000] ppdev: user-space parallel port driver
> [17184446.412000] ppdev0: registered pardevice
>
> Any help appreciated...

Here's a dumb shot-in-the-dark:

> [17184446.412000] ppdev0: registered pardevice

Isn't that the device you want? I'm only guessing but:
parport0 is the physical device the kernel sees;
lp0 is the printer port the kernel would hand to say, cups;
ppdev0 is the abstracted port for user use?

HTH,
Tarkin






[ Post a follow-up to this message ]



    Re: parport problem  
FrenKy


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-26-07 06:36 AM

Tarkin wrote:
> On Mar 25, 10:56 pm, FrenKy <fre...@foo.com> wrote: 
>
> Here's a dumb shot-in-the-dark:
> 
>
> Isn't that the device you want? I'm only guessing but:
> parport0 is the physical device the kernel sees;
> lp0 is the printer port the kernel would hand to say, cups;
> ppdev0 is the abstracted port for user use?
>
> HTH,
>   Tarkin
>
Hi,
Thanks for answer, but I don't understand what you mean...

Are you saying that I should have /dev/ppdev0? I do not have such device...
If I load 'lp' driver I have /dev/lp0, and if I load 'ppdev' driver I
have /dev/parport0 parallel device.
In either case, I do not have /dev/ppdev0.

Br,
FrenKy





[ Post a follow-up to this message ]



    Re: parport problem  
Tarkin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-26-07 01:20 PM

On Mar 26, 6:30 am, FrenKy <fre...@foo.com> wrote:
> Tarkin wrote: 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
>
> Hi,
> Thanks for answer, but I don't understand what you mean...
>
> Are you saying that I should have /dev/ppdev0? I do not have such device..
.
> If I load 'lp' driver I have /dev/lp0, and if I load 'ppdev' driver I
> have /dev/parport0 parallel device.
> In either case, I do not have /dev/ppdev0.
>
> Br,
> FrenKy

As I said, it was a stab in the dark looking at the output
of what you had.

Some quick Googling turns up:

Some notes on writing a parport driver:
http://www.linux.com/guides/khg/Hyp...s/parport.shtml

A bunch o' documentation from RedHat on ppdev:
http://people.redhat.com/twaugh/parport/html/ppdev.html

The latter says you were on the right track, accessing through
/dev/parport0 - my guess was both ignorant &wrong   :^(

There is a mailing list here (or least directions on how to subscribe
to it):
http://www.torque.net/linux-pp.html

HTH,
Tarkin






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 07:22 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register