[Linux-parport] Need help with parallel port programming using ppdev

Manuel Reimer MReimer at despammed.com
Sat Aug 20 10:15:33 EDT 2005


Hello,

can someone *please* help me with finding out how to communicate via 
ppdev to an parallel port device? I've read several documentation 
about ppdev and I tried to write a small test program (see end of this 
mail). I'm sure that my ppdev runs and is working (XSane is able to 
scan via /dev/parport0). I've set the permissions of parport0 to 666. 
I've done "rmmod lp" to get sure that lp doesn't lock the port. If I 
run the test-program I've attached, then I get "PARPORT_STATUS_BUSY" 
in my "wait for ready"-loop. This causes my program to run in an 
endless loop as my parallel port seems to get never ready...

If I try to work with the port in this state, then nothing happens and 
after a few steps of communication I get an status value of "0x88" 
which should be something like "busy and error".

Can someone please tell me how I should rewrite my test program 
(perhaps it's even possible to simplify some things). Anything I want 
for the first is a working initialization routine to allow me to do 
further testing with ppdev.

Thank you *very* much in advance

Yours

Manuel


Test program follows:


#include <sys/ioctl.h>
#include <linux/parport.h>
#include <linux/ppdev.h>

#include <stdlib.h>
#include <stdio.h>
//#include <string.h>

#include <unistd.h>
#include <fcntl.h>

#include <inttypes.h>

int main(void) {
   int fd;
   int mode;

   printf("start");

   fd = open ("/dev/parport0", O_RDWR | O_NOCTTY | O_NONBLOCK);
   if (fd == -1) {
     perror("open");
     close(fd);
     return 1;
   }

   if (ioctl (fd, PPCLAIM)) {
     perror ("PPCLAIM");
     close (fd);
     return 1;
   }


   mode = IEEE1284_MODE_EPP;
   if (ioctl (fd, PPNEGOT, &mode)) {
     perror ("PPNEGOT");
     // A failing negot seems to be not critical
     //close (fd);
     //return 1;
   }

  if (ioctl (fd, PPSETMODE, &mode)) {
         perror("PPSETMODE");
         close(fd);
         return 1;
   }

   unsigned char status;
   unsigned char mask = (PARPORT_STATUS_ERROR
                         | PARPORT_STATUS_BUSY);
   unsigned char val = (PARPORT_STATUS_ERROR
                        | PARPORT_STATUS_BUSY);
   /* Wait for printer to be ready */
   for (;;) {
     ioctl (fd, PPRSTATUS, &status);

     printf("Error: val=0x%02x\n", status);

     if ((status & mask) == val)
       break;



     ioctl (fd, PPRELEASE);
     sleep (1);
     ioctl (fd, PPCLAIM);
   }

   printf("success");
   return 0;

}



More information about the Linux-parport mailing list