[Linux-parport] libieee1284 open/claim gives ppdev error

christian.braun at ch.abb.com christian.braun at ch.abb.com
Tue Mar 9 17:33:00 GMT 2004


Yes, I tried that. That's where I had the Idea from that the open function 
actually doesn't give back an error while the claim gives back the 
E1284_SYS.
By the way the "ppdev0: failed to register device!" appears on both machines, on the SuSE it's in the /var/log/messages... 
there it also talks about that it "cannot grant exclusive access for 
device ppdev0".

I've included the program output as well as my code down below, maybe that 
helps.

Thank you again very much!
Chris

===Below the Output of the program===
Searching for Ports...
/dev/parport0 is accessible
We can use ioperm()
/dev/port is accessible
/dev/lp0 is accessible
This system has /proc/sys/dev/parport
Found 1 port(s)!

Port no. 0:
Name: parport0


Details of the chosen port:

   Portname:     parport0
   Base address: 0x378
   ECR address:  0x778
   File name:    /dev/parport0
==> ieee1284_open
==> init_port
Got 0 from ppdev init
<== 0
Using port no. 0
==> claim
<== E1284_SYS
*** Error no. 8 in ieee1284_claim - "No such device or address"
*** parport0: Could not be claimed.
    Exiting...
=====================================

===The Program Code===
#include <stdio.h>
#include <string.h>
#include <errno.h>

#include <ieee1284.h>

/* Display the found portnames. */
static void display_ports (struct parport_list *pl)
{
        int i=0;

        printf("Found %d port(s)!\n",pl->portc);
        for(i = 0; i < pl->portc; i++)
        {
                printf("\nPort no. %d:\n", i);
                printf("Name: %s\n", pl->portv[i]->name);
        }
        printf("\n");
}


/* Display the details of the chosen port. */
int display_port_details(struct parport *port, int portno)
{
        printf("\nDetails of the chosen port (no. %d):\n", portno);
        printf("   Portname:      %s\n", port->name);
        printf("   Base address:  0x%x\n", port->base_addr);
        printf("   ECR address:   0x%x\n", port->hibase_addr);
        printf("   File name:     %s\n", port->filename);
        printf("\n");
}


/* Reading in the status lines of the opened and claimed port. */
int readin(struct parport *port)
{
        int status;

        status = ieee1284_read_status(port);
        if(status < 0)
        {
                printf("*** Error no. %d in ieee1284_read_status - 
\"%s\"\n", abs(status), strerror(errno));
                printf("*** %s's status lines could not be read.\n 
Exiting...\n", port->name);
                return -13; //Port status lines could not be read
        }

        //Print out status of the chosen port:
        printf("Status of Port %s is: %x\n", port->name, status);

}


/* Main Program */
int main ()
{
        int i=0;
        int status;
        int claim_state;
        int open_state;

        /* Specify here the serial port to use!     **
        ** Set PORT_TO_USE to x for parallel port x */
        const int PORT_TO_USE=0;

        struct parport_list pl;

        printf("Searching for Ports...\n");
        ieee1284_find_ports (&pl, 0);
        display_ports (&pl);

        if(pl.portc=0)
        {
                printf("*** No ports found.\n    Exiting...\n");
                return -14; //No ports found
        }

        struct parport *port = pl.portv[PORT_TO_USE]; //set pointer port 
to the chosen parport structure
        unsigned int cap;

        display_port_details(port, PORT_TO_USE);

        open_state = ieee1284_open(port, F1284_EXCL, &cap);
        if(open_state<0)
        {
                printf("Chosen port is No. %d\n", PORT_TO_USE);
                printf("*** Error no. %d in ieee1284_open - \"%s\"\n", 
abs(open_state), strerror(errno));
                printf("*** %s: inaccessible\n    Exiting...\n", 
port->name);
                return -11; //Port inaccessible
        }
        printf("Using port no. %d\n", PORT_TO_USE);

        claim_state = ieee1284_claim(port);
        if(claim_state<0)
        {
                printf("*** Error no. %d in ieee1284_claim - \"%s\"\n", 
abs(claim_state), strerror(errno));
                printf("*** %s: Could not be claimed.\n    Exiting...\n", 
port->name);
                return -12; //Port could not be claimed
        }

        readin(port);

        //ieee1284_release(port); //undo the claim
        ieee1284_close(port); //undo the open

        return 0;
}
======================




Message from Tim Waugh <twaugh at redhat.com> received on 09.03.2004 17:07

09.03.2004 17:07



Tim Waugh <twaugh at redhat.com>





        To:     christian.braun at ch.abb.com
        cc:     Linux-parport at lists.infradead.org
        Subject:        Re: [Linux-parport] libieee1284 open/claim gives ppdev error

You can set the environment variable LIBIEEE1284_DEBUG (to anything)
to find out more about what the library is up to.

Tim.
*/

================Original Message================

Hello! 

I'm trying to write a program that reads in the status lines on the 
parallel port. For that I intend to use libieee1284... but my program 
fails when I try to use the libieee1284 function to claim the port. 
I do without the ieee1284_get_deviceid since I already know what port I 
will use (the device will be permanently connected) but otherwise I follow 
the sequence given in the libieee1284 Public interface description by Tim 
Waugh (find_ports, open, claim, (..., release, close)). 

The Problem is that when I try to claim the port, the program terminates 
with the Error E1284_SYS (-8), errno giving a 

"No such device or address". 

I actually have that problem on two computers here, one being a Intel PIII 
machine with standard SuSE Linux 8.1 (Kernel 2.4.21) and the other one an 
embedded PC-Board with an AMD ELAN520 processor running a 
Debian-Woody-based bud largely customized Linux distribution. On the SuSE 
there's that problem with no further error messages while on the Debian 
system additionally the message 

"ppdev0: failed to register device!" 

appears for both the open and the claim routine (but the open routine does 
not hand back an error while the claim routine fails). 

Can anybody help me? Any Ideas? 

Thanks a lot!
Christian Braun 
_______________________________________________
Linux-parport mailing list
Linux-parport at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-parport






More information about the Linux-parport mailing list