Impact Acquire SDK C
ContinuousCapture.c

The ContinuousCapture program is a simple example for a continuous acquisition.

Program location
The source file ContinuousCapture.c can be found under:
%INSTALLDIR%\apps\ContinuousCapture_C\
Note
If you have installed the package without example applications, this file will not be available. On Windows® the sample application can be installed or removed from the target system at any time by simply restarting the installation package.
ContinuousCapture example:
  1. Opens a Balluff device.
  2. Snaps images continuously (without display using Linux).
Console Output
[0]: BF000306 (mvBlueFOX-202C, Family: mvBlueFOX, interface layout: DeviceSpecific)

Please enter the number in front of the listed device followed by [ENTER] to open it: 0
Using device number 0.
Press [ENTER] to end the application
Initialising the device. This might take some time...
Info from BF000306: FramesPerSecond: 28.655660, ErrorCount: 0, CaptureTime_s: 0.104195
Info from BF000306: FramesPerSecond: 28.655636, ErrorCount: 0, CaptureTime_s: 0.104017
Info from BF000306: FramesPerSecond: 28.655659, ErrorCount: 0, CaptureTime_s: 0.104153
Info from BF000306: FramesPerSecond: 28.655636, ErrorCount: 0, CaptureTime_s: 0.104072
Info from BF000306: FramesPerSecond: 28.655660, ErrorCount: 0, CaptureTime_s: 0.104234
How it works

The continuous acquisition is similar to the single capture. There is only one difference, this capture is implemented inside a thread.

DMR_Init( &hDMR );
DMR_GetDevice( &hDevice, dmdsmSerial, "*", 0, '*' );
DMR_OpenDevice( hDevice, &hDrv );
@ 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

Then you have to send requests to the request queue:

while( ( result = DMR_ImageRequestSingle( hDrv, 0, 0 ) ) == DMR_NO_ERROR );
{
printf( "DMR_ImageRequestSingle: Unexpected error(code: %d(%s))\n", result, DMR_ErrorCodeToString( result ) );
}
@ 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
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 const char *DMR_CALL DMR_ErrorCodeToString(int errorCode)
Returns a string representation of a given error code.
Definition mvDeviceManager.cpp:5383

Sending multiple request buffers to the driver has the advantage that while the application is busy processing a frame the driver can already capture the next one in the background.

Waiting for a buffer to become ready works by calling the DMR_ImageRequestWaitFor function:

result = DMR_ImageRequestWaitFor( hDrv, 500, 0, &requestNr );
if( result == DMR_NO_ERROR )
{
// check if the request contains a valid image
result = DMR_GetImageRequestResultEx( hDrv, requestNr, &requestResult, sizeof( requestResult ), 0, 0 );
if( ( result == DMR_NO_ERROR ) && ( requestResult.result == rrOK ) )
{
// this image has been captured without problems once we reach this branch in the code
@ rrOK
This image request has been processed successfully.
Definition mvDriverBaseEnums.h:4563
MVDMR_API TDMR_ERROR DMR_CALL DMR_GetImageRequestResultEx(HDRV hDrv, int requestNr, RequestResult *pResult, size_t resultSize, int reserved, int reserved2)
Retrieves the RequestResult of the desired request.
Definition mvDeviceManager.cpp:4844
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

Now you have the image and e.g. you can display it.

After processing the image you have to unlock the image buffer otherwise the driver will no longer be able to use it and send it back into the drivers request queue:

DMR_ImageRequestUnlock( hDrv, requestNr );
DMR_ImageRequestSingle( hDrv, 0, 0 );
MVDMR_API TDMR_ERROR DMR_CALL DMR_ImageRequestUnlock(HDRV hDrv, int requestNr)
Unlocks the request for the driver again.
Definition mvDeviceManager.cpp:2727

Helper functions that come as part of the example code are included via:

#include <apps/Common/exampleHelper_c.h>
Note
You also need to add apps/Common/exampleHelper_c.c to your makefile when using this code inside your own application.
Source code
/*
* @description: Example applications for Impact Acquire
* @copyright: Copyright (C) 2005 - 2023 Balluff GmbH
* @authors: APIs and drivers development team at Balluff GmbH
* @initial date: 2005-05-27
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <apps/Common/exampleHelper_C.h>
#include <mvDeviceManager/Include/mvDeviceManager.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef _WIN32
# include <conio.h>
# include <mvDisplay/Include/mvDisplayExtensions.h>
# include <mvDisplay/Include/mvDisplayWindow.h>
# include <process.h>
# include <windows.h>
# define USE_MV_DISPLAY_LIB // only available for Windows
# define LIVE_LOOP_CALL __stdcall
#elif defined(linux) || defined(__linux) || defined(__linux__) || defined(__APPLE__)
# include <string.h>
# include <unistd.h>
# define LIVE_LOOP_CALL
# if defined(__x86_64__) || defined(__powerpc64__) || defined(__aarch64__) // -m64 makes GCC define __powerpc64__
typedef uint64_t UINT_PTR;
# elif defined(__i386__) || defined(__arm__) || defined(__powerpc__) // and -m32 __powerpc__
typedef uint32_t UINT_PTR;
# else
# error unsupported target platform
# endif
#else
# error unsupported target platform
#endif // #ifdef _WIN32
#define BUF_SIZE (512) // should always be enough, but could be done nicer by checking if buffer too small is returned from a function and then perform a re-allocation...
static int s_boTerminated = 0;
//-----------------------------------------------------------------------------
typedef struct CaptureParameter
//-----------------------------------------------------------------------------
{
HDRV hDrv;
#ifdef USE_MV_DISPLAY_LIB
HDISP hDisp;
#endif // #ifdef USE_MV_DISPLAY_LIB
} CaptureParameter;
//-----------------------------------------------------------------------------
void checkDigitalIO_common( HDRV hDrv )
//-----------------------------------------------------------------------------
{
HOBJ hDigitalPins, hObj;
unsigned int pinCount;
char buf[BUF_SIZE];
hDigitalPins = getDriverList( hDrv, "DigitalInputs", 0, dmltIOSubSystem );
if( hDigitalPins == INVALID_ID )
{
printf( "Can't detect digital inputs. Test skipped.\n" );
}
else
{
objResult = OBJ_GetElementCount( hDigitalPins, &pinCount );
if( objResult == PROPHANDLING_NO_ERROR )
{
objResult = OBJ_GetFirstChild( hDigitalPins, &hObj );
while( ( objResult == PROPHANDLING_NO_ERROR ) && ( ( short )hObj != INVALID_ID ) )
{
objResult |= OBJ_GetName( hObj, buf, BUF_SIZE );
printf( "pin %s detected (handle: 0x%x).\n", buf, hObj );
objResult |= OBJ_GetNextSibling( hObj, &hObj );
}
}
}
hDigitalPins = getDriverList( hDrv, "DigitalOutputs", 0, dmltIOSubSystem );
if( hDigitalPins == INVALID_ID )
{
printf( "Can't detect digital outputs. Test skipped.\n" );
}
else
{
objResult = OBJ_GetElementCount( hDigitalPins, &pinCount );
if( objResult == PROPHANDLING_NO_ERROR )
{
objResult = OBJ_GetFirstChild( hDigitalPins, &hObj );
while( ( objResult == PROPHANDLING_NO_ERROR ) && ( ( short )hObj != INVALID_ID ) )
{
objResult |= OBJ_GetName( hObj, buf, BUF_SIZE );
printf( "pin %s detected (handle: 0x%x).\n", buf, hObj );
objResult |= OBJ_GetNextSibling( hObj, &hObj );
}
}
}
}
//-----------------------------------------------------------------------------
// this function will only work correctly for the mvBlueFOX as this stuff is
// highly device specific. Please look in the mvIMPACT_acquire.h file in the
// source code of the classes IOSubSystemBlueFOX or IOSubSystemFrameGrabber
// how to obtain handles to the digital inputs and outputs for various devices
void checkDigitalIO_mvBlueFOX( HDRV hDrv )
//-----------------------------------------------------------------------------
{
HOBJ hPropDigitalInputs, hPropDigitalOutputs;
unsigned int noOfDigitalPins, i;
int value;
hPropDigitalInputs = getIOSubSystemProp( hDrv, "DigitalInputs" );
if( hPropDigitalInputs == INVALID_ID )
{
printf( "Can't detect digital inputs. Test skipped.\n" );
}
else
{
objResult = OBJ_GetValCount( hPropDigitalInputs, &noOfDigitalPins );
if( objResult == PROPHANDLING_NO_ERROR )
{
for( i = 0; i < noOfDigitalPins; i++ )
{
OBJ_GetI( hPropDigitalInputs, &value, i );
printf( "pin %d: %d\n", i, value );
}
}
}
hPropDigitalOutputs = getIOSubSystemProp( hDrv, "DigitalOutputs" );
if( hPropDigitalOutputs == INVALID_ID )
{
printf( "Can't detect digital outputs. Test skipped.\n" );
}
else
{
objResult = OBJ_GetValCount( hPropDigitalOutputs, &noOfDigitalPins );
if( objResult == PROPHANDLING_NO_ERROR )
{
for( i = 0; i < noOfDigitalPins; i++ )
{
OBJ_SetI( hPropDigitalOutputs, 1, i );
printf( "setting pin %d to high\n", i );
}
}
}
}
//-----------------------------------------------------------------------------
void selectInputChannel( HDRV hDrv )
//-----------------------------------------------------------------------------
{
HOBJ hVideoChannel;
HOBJ hPinDescription;
int maxChannel;
int minChannel;
int channel;
char* pPinDescription;
int run = 1;
hVideoChannel = getSettingProp( hDrv, "Base", "Connector/VideoChannel" );
hPinDescription = getSettingProp( hDrv, "Base", "Connector/PinDescription" );
if( ( hVideoChannel == INVALID_ID ) || ( hPinDescription == INVALID_ID ) )
{
printf( "This device doesn't seem to offer multiple input channels.\n" );
return;
}
if( ( result = OBJ_GetI( hVideoChannel, &maxChannel, PROP_MAX_VAL ) ) != PROPHANDLING_NO_ERROR )
{
printf( "Failed to read max value from property 'VideoChannel'(code: %d(%s))\n", result, DMR_ErrorCodeToString( result ) );
return;
}
if( ( result = OBJ_GetI( hVideoChannel, &minChannel, PROP_MIN_VAL ) ) != PROPHANDLING_NO_ERROR )
{
printf( "Failed to read min value from property 'VideoChannel'(code: %d(%s))\n", result, DMR_ErrorCodeToString( result ) );
return;
}
while( run )
{
if( ( result = OBJ_GetI( hVideoChannel, &channel, 0 ) ) != PROPHANDLING_NO_ERROR )
{
printf( "Failed to read current value from property 'VideoChannel'(code: %d(%s))\n", result, DMR_ErrorCodeToString( result ) );
}
if( ( result = getStringValue( hPinDescription, &pPinDescription, 0 ) ) != PROPHANDLING_NO_ERROR )
{
printf( "Failed to read current value from property 'PinDescription'(code: %d(%s))\n", result, DMR_ErrorCodeToString( result ) );
}
printf( "Current input channel: %d(%s) [min: %d, max: %d].\n", channel, pPinDescription, minChannel, maxChannel );
free( pPinDescription );
printf( "Please enter the desired input channel for running this sample and -1 to leave this loop: " );
channel = getIntValFromSTDIn();
if( channel == -1 )
{
run = 0;
continue;
}
if( ( result = OBJ_SetI( hVideoChannel, channel, 0 ) ) != PROPHANDLING_NO_ERROR )
{
printf( "Failed to set value to property 'VideoChannel'(code: %d(%s))\n", result, DMR_ErrorCodeToString( result ) );
}
}
}
//-----------------------------------------------------------------------------
// this function will only work correctly for the mvBlueFOX as this stuff is
// highly device specific.
void longTimeIntegration_mvBlueFOX( CaptureParameter* pCapParams, int exposureTime_ms )
//-----------------------------------------------------------------------------
{
int requestNr = INVALID_ID;
ImageBuffer* pIB = 0;
HDRV hDrv = pCapParams->hDrv;
#ifdef USE_MV_DISPLAY_LIB
TDisp* pDisp = mvDispWindowGetDisplayHandle( pCapParams->hDisp );
#endif // #ifdef USE_MV_DISPLAY_LIB
HOBJ hPropTriggerMode = getSettingProp( hDrv, "Base", "TriggerMode" );
HOBJ hPropTriggerSource = getSettingProp( hDrv, "Base", "TriggerSource" );
HOBJ hPropDigitalOutputs = getIOSubSystemProp( hDrv, "DigitalOutputs" );
if( ( hPropTriggerMode == INVALID_ID ) || ( hPropTriggerSource == INVALID_ID ) || ( hPropDigitalOutputs == INVALID_ID ) )
{
printf( "Failed to obtain one or more features needed to configure the mvBlueFOX for user controlled long time integration mode.\n" );
printf( "Handle values: 0x%x, 0x%x, 0x%x.\n", hPropTriggerMode, hPropTriggerSource, hPropDigitalOutputs );
return;
}
if( ( propHandlingError = OBJ_SetI( hPropTriggerMode, ctmOnHighExpose, 0 ) ) != PROPHANDLING_NO_ERROR )
{
printf( "Failed to configure trigger mode(code: %d(%s))\n", propHandlingError, DMR_ErrorCodeToString( propHandlingError ) );
return;
}
if( ( propHandlingError = OBJ_SetI( hPropTriggerSource, ctsDigOut0, 0 ) ) != PROPHANDLING_NO_ERROR )
{
printf( "Failed to configure trigger source(code: %d(%s))\n", propHandlingError, DMR_ErrorCodeToString( propHandlingError ) );
return;
}
if( ( dmrError = DMR_ImageRequestSingle( hDrv, 0, 0 ) ) != DMR_NO_ERROR )
{
printf( "Failed to request an image(code: %d(%s))\n", dmrError, DMR_ErrorCodeToString( dmrError ) );
return;
}
// switch on digital output 0
if( ( propHandlingError = OBJ_SetI( hPropDigitalOutputs, 1, 0 ) ) != PROPHANDLING_NO_ERROR )
{
printf( "Failed to modify digital output(code: %d(%s))\n", propHandlingError, DMR_ErrorCodeToString( propHandlingError ) );
return;
}
#ifdef _WIN32
Sleep( exposureTime_ms );
#else
usleep( 1000 * exposureTime_ms );
#endif // #ifdef _WIN32
// switch off digital output 0
if( ( propHandlingError = OBJ_SetI( hPropDigitalOutputs, 0, 0 ) ) != PROPHANDLING_NO_ERROR )
{
printf( "Failed to modify digital output(code: %d(%s))\n", propHandlingError, DMR_ErrorCodeToString( propHandlingError ) );
return;
}
// wait should return immediately as the exposure period has elapsed already
dmrError = DMR_ImageRequestWaitFor( hDrv, 500, 0, &requestNr );
if( dmrError == DMR_NO_ERROR )
{
if( ( dmrError = DMR_GetImageRequestBuffer( hDrv, requestNr, &pIB ) ) == DMR_NO_ERROR )
{
#ifdef USE_MV_DISPLAY_LIB
// display the captured image
mvDispUpdate( pDisp );
#endif // #ifdef USE_MV_DISPLAY_LIB
}
else
{
printf( "DMR_GetImageRequestBuffer: ERROR(code: %d(%s))\n", dmrError, DMR_ErrorCodeToString( dmrError ) );
}
DMR_ImageRequestUnlock( hDrv, requestNr );
}
// restore previous values
OBJ_RestoreDefault( hPropTriggerMode );
OBJ_RestoreDefault( hPropTriggerSource );
}
//-----------------------------------------------------------------------------
unsigned int LIVE_LOOP_CALL liveLoop( void* pData )
//-----------------------------------------------------------------------------
{
#ifdef USE_MV_DISPLAY_LIB
TDisp* pDisp;
#endif // #ifdef USE_MV_DISPLAY_LIB
HDRV hDrv = INVALID_ID;
TDMR_ERROR result;
RequestResult ReqRes;
int frameCount;
HOBJ hPropFPS = INVALID_ID;
HOBJ hPropExpose_us = INVALID_ID;
HOBJ hPropWidth = INVALID_ID;
double fps;
int requestNr;
int lastRequestNr;
int expose_us;
int currentWidth;
int width;
hDrv = ( ( CaptureParameter* )pData )->hDrv;
#ifdef USE_MV_DISPLAY_LIB
pDisp = mvDispWindowGetDisplayHandle( ( ( CaptureParameter* )pData )->hDisp );
#endif // #ifdef USE_MV_DISPLAY_LIB
pIB = 0;
frameCount = 0;
fps = 0.0;
expose_us = 10000;
requestNr = -1;
currentWidth = 0;
width = 0;
// we always have to keep at least 2 images as the display module might want to repaint the image, thus we
// cannot free it unless we have a assigned the display to a new buffer.
lastRequestNr = -1;
// try to locate the frames per second property
if( ( hPropFPS = getStatisticProp( hDrv, "FramesPerSecond" ) ) == INVALID_ID )
{
printf( "Couldn't locate frames per second property! Unable to continue!\n" );
return 0;
}
// try to locate the expose time property
if( ( hPropExpose_us = getSettingProp( hDrv, "Base", "Expose_us" ) ) == INVALID_ID )
{
printf( "Couldn't locate expose property! Will not modify the exposure time!\n" );
}
// try to locate the Aoi/W property
if( ( hPropWidth = getSettingProp( hDrv, "Base", "Camera/Aoi/W" ) ) == INVALID_ID )
{
printf( "Couldn't locate width property!\n" );
}
else
{
OBJ_GetI( hPropWidth, &width, 0 );
}
// pre-fill the default capture queue
while( ( result = DMR_ImageRequestSingle( hDrv, 0, 0 ) ) == DMR_NO_ERROR );
{
printf( "DMR_ImageRequestSingle: Unexpected error(code: %d(%s))\n", result, DMR_ErrorCodeToString( result ) );
}
manuallyStartAcquisitionIfNeeded( hDrv );
// run thread loop
while( !s_boTerminated )
{
// please note, that the value stored in the property 'ImageRequestTimeout_ms' specifies the
// maximum time a request will remain in the queue. If no complete image has been taken until
// then, RequestResult.result will contain 'rrTimeout'. It's default value however results in an infinite timeout.
// To change this value in this sample call 'getSettingProp( hDrv, "Base", "ImageRequestTimeout_ms" )'
const int timeout_ms = 500;
int overallTimeWaited_ms = 0;
result = DMR_ImageRequestWaitFor( hDrv, timeout_ms, 0, &requestNr );
if( result == DMR_NO_ERROR )
{
// check if the request contains a valid image
result = DMR_GetImageRequestResultEx( hDrv, requestNr, &ReqRes, sizeof( ReqRes ), 0, 0 );
if( ( result == DMR_NO_ERROR ) && ( ReqRes.result == rrOK ) )
{
// display statistical information every 100th image
frameCount = frameCount + 1;
if( ( frameCount % 100 ) == 0 )
{
OBJ_GetF( hPropFPS, &fps, 0 );
if( hPropExpose_us != INVALID_ID )
{
expose_us = ( ( expose_us + 10000 ) % 30000 ) + 10000;
OBJ_SetI( hPropExpose_us, expose_us, 0 );
printf( "Current expose time(us): %d\n", expose_us );
}
if( hPropWidth != INVALID_ID )
{
OBJ_GetI( hPropWidth, &currentWidth, 0 );
if( currentWidth == width )
{
currentWidth = width / 2;
}
else
{
currentWidth = width;
}
OBJ_SetI( hPropWidth, currentWidth, 0 );
}
printf( "Frames per second: %.5f.\n", fps );
}
if( ( result = DMR_GetImageRequestBuffer( hDrv, requestNr, &pIB ) ) == DMR_NO_ERROR )
{
#ifdef USE_MV_DISPLAY_LIB
// display the captured image
mvDispUpdate( pDisp );
#endif // #ifdef USE_MV_DISPLAY_LIB
// do your processing here
}
else
{
printf( "DMR_GetImageRequestBuffer failed(code: %d(%s))\n", result, DMR_ErrorCodeToString( result ) );
}
}
else
{
// this can happen e.g. when a triggered acquisition timed out (missing trigger signal).
// By default a request does remain in the queue forever, but this can be is changed by changing the
// 'ImageRequestTimeout_ms' property before calling 'DMR_ImageRequestSingle'. If this timeout then elapses and no
// image has been captured, the RequestResult.result parameter will NOT contain 'rrOK' but e.g. 'rrTimeout', but the
// request still needs to be unlocked for the driver as it has been returned to the user.
printf( "DMR_GetImageRequestResult: ERROR! Return value: %d(%s), request result: %d.\n", result, DMR_ErrorCodeToString( result ), ReqRes.result );
}
if( lastRequestNr >= 0 )
{
// this image has been displayed thus the buffer is no longer needed...
DMR_ImageRequestUnlock( hDrv, lastRequestNr );
}
lastRequestNr = requestNr;
DMR_ImageRequestSingle( hDrv, 0, 0 );
}
else
{
overallTimeWaited_ms += timeout_ms;
printf( "DMR_ImageRequestWaitFor failed(code: %d(%s)), meaning no buffer became ready after %d ms\n", result, DMR_ErrorCodeToString( result ), overallTimeWaited_ms );
printf( "Please note that slow systems or interface technologies in combination with\n" );
printf( "high resolution sensors might need more time to transmit an image in %d ms.\n", timeout_ms );
printf( "If this is the case increase the timeout and rebuild this application or simply wait multiple times.\n" );
printf( "Once the camera is configured for triggered image acquisition and the timeout elapsed\n before the camera has been triggered this might happen as well.\n" );
}
#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__APPLE__)
s_boTerminated = waitForInput( 0, STDOUT_FILENO ) == 0 ? 0 : 1; // break by STDIN
#endif // #if defined(linux) || defined(__linux) || defined(__linux__) || defined(__APPLE__)
}
manuallyStopAcquisitionIfNeeded( hDrv );
#ifdef USE_MV_DISPLAY_LIB
// stop the display from showing freed memory
mvDispSetImage( pDisp, 0, 0, 0, 0, 0 );
#endif // #ifdef USE_MV_DISPLAY_LIB
// free the last potentially locked request
if( requestNr >= 0 )
{
DMR_ImageRequestUnlock( hDrv, requestNr );
}
// clear all queues
if( ( result = DMR_ImageRequestReset( hDrv, 0, 0 ) ) != DMR_NO_ERROR )
{
printf( "DMR_ImageRequestReset(code: %d(%s))\n", result, DMR_ErrorCodeToString( result ) );
}
// extract and unlock all requests that are now returned as 'aborted'
while( DMR_ImageRequestWaitFor( hDrv, 0, 0, &requestNr ) == DMR_NO_ERROR )
{
DMR_ImageRequestUnlock( hDrv, requestNr );
}
if( ( result = DMR_ReleaseImageRequestBufferDesc( &pIB ) ) != DMR_NO_ERROR )
{
printf( "DMR_ReleaseImageRequestBufferDesc(code: %d(%s))\n", result, DMR_ErrorCodeToString( result ) );
}
return 0;
}
//-----------------------------------------------------------------------------
void captureLoop( CaptureParameter* pCaptureParams )
//-----------------------------------------------------------------------------
{
#ifdef _WIN32
HANDLE hThread = NULL;
unsigned int threadID = 0;
#endif // #ifdef _WIN32
printf( "Press [ENTER] to end the continuous acquisition.\n" );
s_boTerminated = 0;
#ifdef _WIN32
hThread = ( HANDLE )_beginthreadex( 0, 0, liveLoop, ( LPVOID )( pCaptureParams ), 0, &threadID );
# ifdef __BORLANDC__ // is Borland compiler?
if( getch() == EOF ) // The Borland compiler is not aware of the newer ISO compliant name '_getch' or is it?
{
printf( "Calling 'getch' did return EOF...\n" );
}
# else
if( _getch() == EOF ) // This is the newer ISO compliant name of the 'getch' function. Visual Studio will warn if using 'getch'
{
printf( "Calling '_getch' did return EOF...\n" );
}
# endif // #ifdef __BORLANDC__ // is Borland compiler?
s_boTerminated = 1;
WaitForSingleObject( hThread, INFINITE );
CloseHandle( hThread );
#else
liveLoop( pCaptureParams );
#endif // #ifdef _WIN32
}
//-----------------------------------------------------------------------------
int main( int argc, char* argv[] )
//-----------------------------------------------------------------------------
{
HDMR hDMR = INVALID_ID;
HDRV hDrv = INVALID_ID;
HDEV hDevice = INVALID_ID;
CaptureParameter captureParameter;
unsigned int i = 0;
HOBJ hPropFamily = INVALID_ID;
char* pStringBuffer = NULL;
HOBJ hPropDeviceClass = INVALID_ID;
int deviceClass = dcGeneric;
// get rid of warnings
( void )argc;
( void )argv;
// try to initialise the library.
if( ( result = DMR_Init( &hDMR ) ) != DMR_NO_ERROR )
{
printf( "DMR_Init failed (code: %d(%s))\n", result, DMR_ErrorCodeToString( result ) );
END_APPLICATION;
}
getDeviceFromUserInput( &hDevice, 0, 0 );
if( ( hPropFamily = getDeviceProp( hDevice, "Family" ) ) == INVALID_ID )
{
printf( "Failed to obtain device family property for device %d.\n", i );
END_APPLICATION;
}
getStringValue( hPropFamily, &pStringBuffer, 0 );
// try to initialise this device
if( ( result = DMR_OpenDevice( hDevice, &hDrv ) ) != DMR_NO_ERROR )
{
printf( "DMR_OpenDevice failed (code: %d(%s))\n", result, DMR_ErrorCodeToString( result ) );
result = DMR_Close();
printf( "DMR_Close: (code: %d(%s))\n", result, DMR_ErrorCodeToString( result ) );
END_APPLICATION;
}
if( OBJ_GetHandleEx( hDevice, "DeviceClass", &hPropDeviceClass, 0, -1 ) == PROPHANDLING_NO_ERROR )
{
if( ( OBJ_GetI( hPropDeviceClass, &deviceClass, 0 ) == PROPHANDLING_NO_ERROR ) && ( deviceClass == dcFrameGrabber ) )
{
selectInputChannel( hDrv );
}
}
// "Base" is the default setting, that always exists. Other settings can be created by deriving
// a new setting from "Base" via DMR_CreateSetting()
// try to locate the trigger mode and source properties. These properties will not be available for every device
// as not every device will support external trigger signal inputs!
modifyEnumPropertyI( hDrv, "Base", "TriggerMode" );
modifyEnumPropertyI( hDrv, "Base", "TriggerSource" );
#ifdef USE_MV_DISPLAY_LIB
// create a window to display the captured images
captureParameter.hDisp = mvDispWindowCreate( "ContinuousCapture sample(plain 'C')" );
mvDispWindowShow( captureParameter.hDisp );
#endif // #ifdef USE_MV_DISPLAY_LIB
captureParameter.hDrv = hDrv;
if( strcmp( pStringBuffer, "mvBlueFOX" ) == 0 )
{
longTimeIntegration_mvBlueFOX( &captureParameter, 3000 );
checkDigitalIO_mvBlueFOX( hDrv );
}
else
{
checkDigitalIO_common( hDrv );
}
free( pStringBuffer );
pStringBuffer = 0;
captureLoop( &captureParameter );
#ifdef USE_MV_DISPLAY_LIB
mvDispWindowDestroy( captureParameter.hDisp );
#endif // #ifdef USE_MV_DISPLAY_LIB
if( ( result = DMR_CloseDevice( hDrv, hDevice ) ) != DMR_NO_ERROR )
{
printf( "DMR_CloseDevice: (code: %d(%s))\n", result, DMR_ErrorCodeToString( result ) );
}
if( ( result = DMR_Close() ) != DMR_NO_ERROR )
{
printf( "DMR_Close: (code: %d(%s))\n", result, DMR_ErrorCodeToString( result ) );
}
END_APPLICATION;
}
TRequestResult result
The result of this request.
Definition mvDeviceManager.h:224
TDMR_ERROR
Errors reported by the device manager.
Definition mvDriverBaseEnums.h:2601
@ dcGeneric
A generic device.
Definition mvDriverBaseEnums.h:2026
@ dcFrameGrabber
A frame grabber device.
Definition mvDriverBaseEnums.h:2032
@ dmltIOSubSystem
Specifies the driver interface list containing properties to work with any kind of I/O pin belonging ...
Definition mvDeviceManager.h:623
Fully describes a captured image.
Definition mvImageBuffer.h:94
Contains status information about the capture process.
Definition mvDeviceManager.h:218
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_Close(void)
Frees internal data structures and decreases the usage counter for this library.
Definition mvDeviceManager.cpp:1265
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_CloseDevice(HDRV hDrv, HDEV hDev)
Closes a device.
Definition mvDeviceManager.cpp:1585
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
@ ctsDigOut0
Uses digital output 0 as the source for the trigger signal (this allows a SW controlled trigger (or e...
Definition mvDriverBaseEnums.h:1586
@ ctmOnHighExpose
Start frame expose when the trigger input level rises above the trigger threshold and expose while th...
Definition mvDriverBaseEnums.h:1560
void MV_DISPLAY_API_CALL mvDispWindowDestroy(HDISP hDisp)
Closes a display window and frees allocated memory.
Definition mvDisplayWindow.cpp:315
TDisp *MV_DISPLAY_API_CALL mvDispWindowGetDisplayHandle(HDISP hDisp)
Returns a pointer to the internal object used for displaying the image data.
Definition mvDisplayWindow.cpp:353
HDISP MV_DISPLAY_API_CALL mvDispWindowCreate(const char *title)
Creates a new display window object.
Definition mvDisplayWindow.cpp:382
void MV_DISPLAY_API_CALL mvDispWindowShow(HDISP hDisp)
Shows the display window.
Definition mvDisplayWindow.cpp:436
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:345
void MV_DISPLAY_API_CALL mvDispSetImageFromImageBuffer(TDisp *pDisp, const ImageBuffer *pBuf)
Sets the next image to display.
Definition mvDisplayExtensions.cpp:154
void MV_DISPLAY_API_CALL mvDispUpdate(TDisp *pDisp)
Immediately redraws the current image.
Definition mvDisplay.cpp:404
const int INVALID_ID
A constant to check for an invalid ID returned from the property handling module.
Definition mvPropHandlingDatatypes.h:62
MVDMR_API TPROPHANDLING_ERROR DMR_CALL OBJ_GetNextSibling(HOBJ hObj, HOBJ *phNextSibling)
Moves to the next sibling of this object.
Definition ObjectHandling.cpp:836
MVDMR_API TPROPHANDLING_ERROR DMR_CALL OBJ_GetHandleEx(HLIST hList, const char *pObjName, HOBJ *phObj, unsigned int searchMode, int maxSearchDepth)
Retrieves an objects handle.
Definition ObjectHandling.cpp:343
TPROPHANDLING_ERROR
Error codes of the module handling everything related to properties.
Definition mvPropHandlingDatatypes.h:382
MVDMR_API TPROPHANDLING_ERROR DMR_CALL OBJ_SetI(HOBJ hProp, int val, int index)
Sets a property's value as an integer value.
Definition ObjectHandling.cpp:2583
MVDMR_API TPROPHANDLING_ERROR DMR_CALL OBJ_GetValCount(HOBJ hProp, unsigned int *pValCount)
Receives the current number of values stored by the property.
Definition ObjectHandling.cpp:3189
const int PROP_MIN_VAL
The index value to query the minimum value defined for this property.
Definition mvPropHandlingDatatypes.h:68
MVDMR_API TPROPHANDLING_ERROR DMR_CALL OBJ_GetElementCount(HLIST hList, unsigned int *pElementCount)
Receives the number of objects stored in a list.
Definition ObjectHandling.cpp:1451
const int PROP_MAX_VAL
The index value to query the maximum value defined for this property.
Definition mvPropHandlingDatatypes.h:66
MVDMR_API TPROPHANDLING_ERROR DMR_CALL OBJ_GetFirstChild(HOBJ hObj, HOBJ *phFirstChild)
Moves to the first child of this object(moves down one level).
Definition ObjectHandling.cpp:898
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
MVDMR_API TPROPHANDLING_ERROR DMR_CALL OBJ_GetI(HOBJ hProp, int *pVal, int index)
Receives a property's value as an integer value.
Definition ObjectHandling.cpp:2658
MVDMR_API TPROPHANDLING_ERROR DMR_CALL OBJ_RestoreDefault(HOBJ hObj)
Restores the default for the referenced object.
Definition ObjectHandling.cpp:1815
MVDMR_API TPROPHANDLING_ERROR DMR_CALL OBJ_GetName(HOBJ hObj, char *pBuf, size_t bufSize)
Retrieves the name of this object.
Definition ObjectHandling.cpp:101
@ PROPHANDLING_NO_ERROR
The operation has been executed successfully.
Definition mvPropHandlingDatatypes.h:384