LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-13-2007, 07:33 PM   #1
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
libieee1284 exclusive access


I hope this isn't too esoteric but I'm pretty well at wits end on this.

I am trying to use the ieee1284 library to build a tool for accessing parallel ports in some non-standard ways. The docs are fairly clear and my code builds cleanly, but I cannot get around the problem of exclusive access denial.
I set the environment variable LIBIEEE1284_DEBUG="1", and run th following code as root:
Code:
#include    <stdio.h>
#include    <stdlib.h>
#include    <sys/types.h>
#include    <sys/stat.h>
#include    <fcntl.h>

#include    <ieee1284.h>

int     main( int argc, char * argv[] ){

int     lp;

unsigned char byte;
unsigned int  baseAddr;
int         i;

struct parport_list lpList;
struct parport    * port;

int           capabilities;
int           portStatus;


    if( argc < 2 ){
        printf( "No output byte\n" );
        exit(1);
    }

    sscanf( argv[1], "%i", &byte );
    printf( "Outp byte: %02X\n", byte );
    
    ieee1284_find_ports( &lpList, 0 );
    for( i = 0; i < lpList.portc; i++ ){
        port = lpList.portv[i];
        printf( "      Name[%d] = %s\n",   i, port -> name );
        printf( "  BaseAddr[%d] = %04X\n", i, port -> base_addr );
        printf( "hiBaseAddr[%d] = %04X\n", i, port -> hibase_addr );
        printf( "  Filename[%d] = %s\n\n", i, port -> filename );
    
    }      
    
    if( lpList.portc ){
        port = lpList.portv[0];
        baseAddr = port -> base_addr;
    }
    else{
        printf( "No ieee1284 port\n" );
        exit(1);
    }
    
    /*
    **  Exclusive access fails at ieee1284_claim....
    **
    ** portStatus = ieee1284_open( port, 0, &capabilities );
    */
    portStatus = ieee1284_open( port, F1284_EXCL, &capabilities );
    
    printf( "Open Status: %d\n", portStatus );
    printf( "Open Capabilities: %04X\n", capabilities );
    if( capabilities & CAP1284_RAW ){
        printf( "CAP1284_RAW, " );
    }
    if( capabilities & CAP1284_NIBBLE ){
        printf( "CAP1284_NIBBLE, " );
    }
    if( capabilities & CAP1284_BYTE ){
        printf( "CAP1284_BYTE, " );
    }
    if( capabilities & CAP1284_COMPAT ){
        printf( "CAP1284_COMPAT, " );
    }
    if( capabilities & CAP1284_ECP ){
        printf( "CAP1284_ECP, " );
    }
    if( capabilities & CAP1284_ECPRLE ){
        printf( "CAP1284_ECPRLE, " );
    }
    if( capabilities & CAP1284_ECPSWE ){
        printf( "CAP1284_ECPSWE, " );
    }
    if( capabilities & CAP1284_BECP ){
        printf( "CAP1284_BECP, " );
    }
    if( capabilities & CAP1284_EPP ){
        printf( "CAP1284_EPP, " );
    }
    if( capabilities & CAP1284_EPPSWE ){
        printf( "CAP1284_EPPSWE, " );
    }
    if( capabilities & CAP1284_IRQ ){
        printf( "CAP1284_IRQ, " );
    }
    if( capabilities & CAP1284_DMA ){
        printf( "CAP1284_DMA, " );
    }
    printf( "\n" );

    /* Something on the net said try this, but it makes no diff...
    */
    ieee1284_free_ports( &lpList );


    portStatus = ieee1284_claim( port );
    printf( "Claim Status: %d\n", portStatus );
    if( portStatus & E1284_SYS ){
        perror( "ieee1284 Claim: " );
        exit(1);
    }
    

    ieee1284_write_data( port, byte );
    printf( "WriteData Status: %d\n", portStatus );
    if( portStatus & E1284_SYS ){
        perror( "ieee1284 WriteData: " );
        exit(1);
    }


    ieee1284_release( port );
    printf( "Release Status: %d\n", portStatus );
    if( portStatus & E1284_SYS ){
        perror( "ieee1284 Release: " );
        exit(1);
    }


    
    portStatus = ieee1284_close( port );
    printf( "\nClose Status: %d\n", portStatus );

    
    exit(0);
}
As far as I can tell, I start out with no loadable modules that would want to access the parallel port, so I don't see where there should be any contention for the hardware or device file (/dev/parport0)

The output from the code, including the driver debug output:
Code:
./lptTest2 0x0ff
Outp byte: FF
/dev/parport0 is accessible
We can use ioperm()
/dev/port is accessible
/dev/lp0 is accessible
This system has /proc/sys/dev/parport
      Name[0] = parport0
  BaseAddr[0] = 0378
hiBaseAddr[0] = 0778
  Filename[0] = /dev/parport0

==> ieee1284_open
==> init_port
Got 0 from ppdev init
<== 0
Open Status: 0
Open Capabilities: 01EE
CAP1284_NIBBLE, CAP1284_BYTE, CAP1284_COMPAT, CAP1284_ECP, CAP1284_ECPRLE, CAP1284_ECPSWE, CAP1284_EPP,
==> claim
<== E1284_SYS
Claim Status: -8
ieee1284 Claim: : No such device or address
Interestingly, lsmod now shows a bunch of modules related to parallel ports.
Code:
/sbin/lsmod
Module                  Size  Used by
lp                     14893  0
parport_pc             27777  1
ppdev                  12613  0
parport                37256  3 lp,parport_pc,ppdev

(more unrelated stuff omitted....)
Who can explain what I'm seeing, and how to gain exclusive access?

uname -a
Linux 2.6.9-42.0.3.ELhugemem #1 SMP Thu Oct 5 15:24:32 CDT 2006 i686 i686 i386 GNU/Linux

Thanks.

--- rod.

Last edited by theNbomr; 04-13-2007 at 07:37 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Question About Exclusive File Access jkoz Programming 1 01-18-2007 07:34 AM
Cannot get exclusive lock apokryphos Linux - Newbie 3 12-02-2004 07:22 AM
exclusive lock on cd burning rosscopeeko Red Hat 2 09-01-2003 01:22 PM
exclusive lock on cd burning rosscopeeko Linux - Software 0 08-30-2003 07:39 AM
FTP exclusive directory access allancondino Linux - General 3 05-02-2002 06:15 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration