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

DMR_Init( &hDMR );
DMR_GetDevice( &hDevice, dmdsmSerial, "*", 0, '*' );
DMR_OpenDevice( hDevice, &hDriverInterface );
@ dmdsmSerial
Searches for a device with a certain serial number.
Definition mvDeviceManager.h:528
MVDMR_API TDMR_ERROR DMR_CALL DMR_Init(HDMR *pHDmr)
Initialises the library.
Definition mvDeviceManager.cpp:1137
MVDMR_API TDMR_ERROR DMR_CALL DMR_OpenDevice(HDEV hDev, HDRV *pHDrv)
Initialises a device.
Definition mvDeviceManager.cpp:1516
MVDMR_API TDMR_ERROR DMR_CALL DMR_GetDevice(HDEV *pHDev, TDMR_DeviceSearchMode searchMode, const char *pSearchString, unsigned int devNr, char wildcard)
Tries to locate a certain device in the system which matches the input criteria.
Definition mvDeviceManager.cpp:1379

Step 2: Request The Acquisition Of An Image

DMR_ImageRequestSingle( hDriverInterface, 0, 0 );
\endif
A live acquisition (running inside a thread function) could be implemented as follows:
\code
//-----------------------------------------------------------------------------
HOBJ getProp( HDRV hDrv, TDMR_ListType lt, const char* pPropName, const char* pListName )
//-----------------------------------------------------------------------------
{
TDMR_ERROR dmrResult;
HOBJ hProp;
HLIST hList;
// First locate the setting list named 'Base', which is always present
if( ( dmrResult = DMR_FindList( hDrv, pListName, lt, 0, &hList ) ) == DMR_NO_ERROR )
{
// Now try to locate the property
if( ( objResult = OBJ_GetHandle( baseList, pPropName, & hProp ) ) != PROPHANDLING_NO_ERROR )
{
printf( "OBJ_GetHandle failed: %d Handle: %d\n", objResult, hProp );
}
}
else
{
printf( "DMR_FindList failed: %d\n", dmrResult );
}
return hProp;
}
//-----------------------------------------------------------------------------
void threadFn( HDRV hDriverInterface )
//-----------------------------------------------------------------------------
{
HOBJ hReqCnt, hPropFPS;
int result = DMR_NO_ERROR;
hReqCnt = getProp( hDriverInterface, dmltSystemSettings, "RequestCount", 0 );
hPropFPS = getProp( hDriverInterface, dmltStatistics, "FramesPerSecond", 0 );
// pre-fill the default capture queue
while( ( result = DMR_ImageRequestSingle( hDriverInterface, 0, 0 ) ) == DMR_NO_ERROR );
{
printf( "DMR_ImageRequestSingle: Unexpected error(code: %d(%s))\n", result, DMR_ErrorCodeToString( result ) );
}
while( !s_boTerminated )
{
result = DMR_ImageRequestWaitFor( hDriverInterface, 500, 0, &requestNr );
if( result == DMR_NO_ERROR )
{
frameCount = frameCount + 1;
if( ( frameCount % 100 ) == 0 )
{
OBJ_GetF( hPropFPS, &fps, 0 );
printf( "frames per second: %.5f\n", fps );
}
if( ( result = DMR_GetImageRequestBuffer( hDriverInterface, requestNr, &pIB ) ) == DMR_NO_ERROR )
{
mvDispSetImage( pDisp, pIB->vpData, pIB->iWidth, pIB->iHeight, pIB->pChannels[0].iPixelPitch*8, pIB->pChannels[0].iLinePitch );
mvDispUpdate( pDisp );
DMR_ImageRequestUnlock( hDriverInterface, requestNr );
DMR_ImageRequestSingle( hDriverInterface, 0, 0 );
}
else
{
printf( "DMR_GetImageRequestBuffer: ERROR! Code %d\n", result );
}
}
else
{
printf( "DMR_ImageRequestWaitFor: ERROR! Code %d\n", result );
}
}
DMR_ImageRequestReset( hDriverInterface, 0, 0 );
}
int iHeight
The height of the image in pixel or lines.
Definition mvImageBuffer.h:98
int iWidth
The width of the image in pixel.
Definition mvImageBuffer.h:100
int iLinePitch
The offset (in bytes) to the next line of this channel.
Definition mvImageBuffer.h:70
void * vpData
The starting address of the image.
Definition mvImageBuffer.h:157
ChannelData * pChannels
A pointer to an array of channel specific image data.
Definition mvImageBuffer.h:166
int iPixelPitch
The offset (in bytes) to the next pixel of this channel.
Definition mvImageBuffer.h:72
TDMR_ERROR
Errors reported by the device manager.
Definition mvDriverBaseEnums.h:2601
TDMR_ListType
Defines valid interface list types, which can be located using the function DMR_FindList().
Definition mvDeviceManager.h:585
@ DEV_NO_FREE_REQUEST_AVAILABLE
The user requested a new image, but no free Request object is available to process this request.
Definition mvDriverBaseEnums.h:2713
@ DMR_NO_ERROR
The function call was executed successfully.
Definition mvDriverBaseEnums.h:2603
@ dmltStatistics
Specifies the driver interface list containing statistical information.
Definition mvDeviceManager.h:611
@ dmltSystemSettings
Specifies the driver interface list containing properties, which influence the overall operation of t...
Definition mvDeviceManager.h:617
Fully describes a captured image.
Definition mvImageBuffer.h:94
MVDMR_API TDMR_ERROR DMR_CALL DMR_ImageRequestSingle(HDRV hDrv, int requestCtrl, int *pRequestUsed)
Sends an image request to the device driver.
Definition mvDeviceManager.cpp:2663
MVDMR_API TDMR_ERROR DMR_CALL DMR_ImageRequestReset(HDRV hDrv, int requestCtrl, int mode)
Deletes all requests currently queued for the specified request control.
Definition mvDeviceManager.cpp:2618
MVDMR_API TDMR_ERROR DMR_CALL DMR_ImageRequestUnlock(HDRV hDrv, int requestNr)
Unlocks the request for the driver again.
Definition mvDeviceManager.cpp:2727
MVDMR_API TDMR_ERROR DMR_CALL DMR_ReleaseImageRequestBufferDesc(ImageBuffer **ppBuffer)
frees the memory previously allocated for the specified ImageBuffer structure again.
Definition mvDeviceManager.cpp:4324
MVDMR_API TDMR_ERROR DMR_CALL DMR_FindList(HDRV hDrv, const char *pName, TDMR_ListType type, unsigned int flags, HLIST *phDevList)
Locates a specified list within the device drivers interface.
Definition mvDeviceManager.cpp:2295
MVDMR_API const char *DMR_CALL DMR_ErrorCodeToString(int errorCode)
Returns a string representation of a given error code.
Definition mvDeviceManager.cpp:5383
MVDMR_API TDMR_ERROR DMR_CALL DMR_GetImageRequestBuffer(HDRV hDrv, int requestNr, ImageBuffer **ppBuffer)
Returns the ImageBuffer of the desired request.
Definition mvDeviceManager.cpp:3732
MVDMR_API TDMR_ERROR DMR_CALL DMR_ImageRequestWaitFor(HDRV hDrv, int timeout_ms, int queueNr, int *pRequestNr)
Waits for a request object to become ready.
Definition mvDeviceManager.cpp:2767
void MV_DISPLAY_API_CALL mvDispSetImage(TDisp *pDisp, const void *pData, int width, int height, int bitsPerPixel, int pitch)
Sets the next image to display.
Definition mvDisplay.cpp:750
void MV_DISPLAY_API_CALL mvDispUpdate(TDisp *pDisp)
Immediately redraws the current image.
Definition mvDisplay.cpp:809
TPROPHANDLING_ERROR DMR_CALL OBJ_GetHandle(HLIST hList, const char *pPathAndPropName, HOBJ *phObj)
Retrieves an objects handle(deprecated).
Definition ObjectHandling.cpp:289
TPROPHANDLING_ERROR
Error codes of the module handling everything related to properties.
Definition mvPropHandlingDatatypes.h:382
MVDMR_API TPROPHANDLING_ERROR DMR_CALL OBJ_GetF(HOBJ hProp, double *pVal, int index)
Receives a property's value as a float value.
Definition ObjectHandling.cpp:2956
@ PROPHANDLING_NO_ERROR
The operation has been executed successfully.
Definition mvPropHandlingDatatypes.h:384
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

DMR_ImageRequestWaitFor( hDriverInterface, 500, 0, &requestNr );

Step 4: Unlock The Image Buffer Once The Image Has Been Processed:

DMR_ImageRequestReset( hDriverInterface, 0, 0 ) );
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!