[Linux-parport] How to get exclusive access to parports?

Dr. Alexander Klein Alexander.Klein at math.uni-giessen.de
Fri Dec 9 04:09:22 EST 2011


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 ] );

	octave_stdout << status << std::endl;
	octave_stdout << strerror ( errno ) << std::endl;

	if ( status != E1284_OK )
		error ( "Could not claim port after opening!" );

//Other unrelated stuff snipped.

Opening the port with F1284_EXCL works, but claiming it afterwards fails with a status of -8 and "No such device or address" as the error string.

Opening the port WITHOUT F1284_EXCL works too, as does claiming it afterwards.

What else could be the reason for such strange behaviour?

Thank you in advance,

	Alex

-- 
          Dr. Alexander Klein, Diplom-Mathematiker

Physiologisches Institut       |               TransMIT Zentrum
Raum 543                       |        für Numerische Methoden
Aulweg 129                     |          Heinrich-Buff-Ring 44
35392 Giessen                  |                  35392 Giessen




More information about the Linux-parport mailing list