At least four steps are necessary to capture a single image from a Balluff device. These steps are explained with the help of source examples from ImpactControlCenter.
Step 1: The Device Needs To Be Initialized
DeviceManager devMgr;
Device* pDev = devMgr[0];
pDev->open();
Step 2: Request The Acquisition Of An Image
FunctionInterface fi(pDev);
fi.imageRequestSingle();
A live acquisition (running inside a thread function) could be implemented as follows:
void threadFn( Device* pDev )
{
int result = DMR_NO_ERROR;
SystemSettings ss( pThreadParameter->pDev );
const int REQUEST_COUNT = ss.requestCount.read();
for( int i=0; i<REQUEST_COUNT; i++ )
{
result = fi.imageRequestSingle();
if( result != DMR_NO_ERROR )
{
cout << "Error while filling the request queue: " << ImpactAcquireException::getErrorCodeAsString( result ) << endl;
}
}
const Request* pRequest = 0;
int requestNr = -1;
while( !boTerminated )
{
requestNr = fi.imageRequestWaitFor( 500 );
if( fi.isRequestNrValid( requestNr ) )
{
pRequest = fi.getRequest(requestNr);
if( pRequest->isOK() )
{
}
else
{
cout << "Error: Request result " << pRequest->requestResult.readS() << endl;
}
fi.imageRequestUnlock( requestNr );
fi.imageRequestSingle();
}
else
{
cout << "Error: There has been no request in the queue!" << endl;
}
}
fi.imageRequestReset( 0, 0 );
}
- Note
- Images supplied to the user are locked for the driver. So if the user does not unlock the images, a permanent acquisition won't be possible as sooner or later all available requests will have been processed by the driver and have been returned to the user.
- See also
- Step 4.
Step 3: Wait Until The Image Has Been Captured
int requestNr = fi.imageRequestWaitFor( timeout_ms );
Step 4: Unlock The Image Buffer Once The Image Has Been Processed:
if( fi.isRequestNrValid( requestNr ) )
{
fi.imageRequestUnlock( requestNr );
}
- Note
- ImpactControlCenter acquires images with the help of a capture thread. In order to avoid performance losses, the image buffer is locked during either the live or single image acquisition.
So after displaying the image the unlock is necessary!