Impact Acquire SDK C++
Getting A Single Image

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;
// Get a pointer to the first device found
Device* pDev = devMgr[0];
// initialise it(this step is optional as this will be done automatically from
// all other wrapper classes that accept a device pointer):
pDev->open();

Step 2: Request The Acquisition Of An Image

// create an instance of the function interface for this device
// (this would also initialise a device if necessary)
FunctionInterface fi(pDev);
// send the request for one image down to the driver
fi.imageRequestSingle();

A live acquisition (running inside a thread function) could be implemented as follows:

//-----------------------------------------------------------------------------
void threadFn( Device* pDev )
//-----------------------------------------------------------------------------
{
// pre-fill the capture queue. There can be more than 1 queue for some devices, but for this sample
// we will work with the default capture queue. If a device supports more than one capture or result
// queue, this will be stated in the manual. If nothing is mentioned about it, the device supports one
// queue only. Request as many images as possible. If there are no more free requests 'DEV_NO_FREE_REQUEST_AVAILABLE'
// will be returned by the driver.
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;
}
}
// run thread loop
const Request* pRequest = 0;
int requestNr = -1;
while( !boTerminated )
{
// wait for results from the default capture queue
requestNr = fi.imageRequestWaitFor( 500 );
if( fi.isRequestNrValid( requestNr ) )
{
pRequest = fi.getRequest(requestNr);
if( pRequest->isOK() )
{
// display/process/store or do whatever you like with the image here
}
else
{
cout << "Error: Request result " << pRequest->requestResult.readS() << endl;
}
// unlock the buffer in order to allow the driver to use it again.
// Afterwards the image buffer data becomes invalid for the user!
fi.imageRequestUnlock( requestNr );
// send a new request down to the driver.
fi.imageRequestSingle();
}
else
{
cout << "Error: There has been no request in the queue!" << endl;
}
}
// free resources, clear all queues of the acquisition engine
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 ) )
{
// processing, displaying whatever
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!