Dr.Alexander | 9 Dec 2011 10:09

How to get exclusive access to parports?

Hello list,

I'm trying to get access to the parallel port of a machine to do some signalling for data acquisition.

The machine runs with Xubuntu 10.04 and has one parallel port which gets listed as parport0.

Since the whole thing is somewhat time-critical, I'd like to prevent other processes from accessing the
port, and try to achieve this with the following code snippet:

int port = args(1).int_value(); //Passed from outside, usually 0.
int status, capabilities;

//This usually succeeds, so non-exclusive is never tried.
status = ieee1284_open( ports.portv [ port ], F1284_EXCL, &capabilities );
if ( status != E1284_OK ) {
	warning ( "Could not open the port in exclusive mode, trying non-exlusive mode" );

	status = ieee1284_open( ports.portv [ port ], 0, &capabilities );
}

//This usually never happens.
if ( status != E1284_OK )
	error ( "Could not open the port in non-exclusive mode!" );

	else if ( !capabilities & CAP1284_RAW )
	error ( "Cannot get raw access for parallel port!" );

//This fails regularly when F1284_EXCL is used.
else {
	status = ieee1284_claim( ports.portv [ port ] );
(Continue reading)


Gmane