The continuous acquisition is similar to the single capture. There is only one difference, this capture is implemented inside a thread.
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:
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:
#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
# 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__)
typedef uint64_t UINT_PTR;
# elif defined(__i386__) || defined(__arm__) || defined(__powerpc__)
typedef uint32_t UINT_PTR;
# else
# error unsupported target platform
# endif
#else
# error unsupported target platform
#endif
#define BUF_SIZE (512)
static int s_boTerminated = 0;
typedef struct CaptureParameter
{
HDRV hDrv;
#ifdef USE_MV_DISPLAY_LIB
HDISP hDisp;
#endif
} CaptureParameter;
void checkDigitalIO_common( HDRV hDrv )
{
HOBJ hDigitalPins, hObj;
unsigned int pinCount;
char buf[BUF_SIZE];
{
printf( "Can't detect digital inputs. Test skipped.\n" );
}
else
{
{
{
printf( "pin %s detected (handle: 0x%x).\n", buf, hObj );
}
}
}
hDigitalPins = getDriverList( hDrv,
"DigitalOutputs", 0,
dmltIOSubSystem );
{
printf( "Can't detect digital outputs. Test skipped.\n" );
}
else
{
{
{
printf( "pin %s detected (handle: 0x%x).\n", buf, hObj );
}
}
}
}
void checkDigitalIO_mvBlueFOX( HDRV hDrv )
{
HOBJ hPropDigitalInputs, hPropDigitalOutputs;
unsigned int noOfDigitalPins, i;
int value;
hPropDigitalInputs = getIOSubSystemProp( hDrv, "DigitalInputs" );
{
printf( "Can't detect digital inputs. Test skipped.\n" );
}
else
{
{
for( i = 0; i < noOfDigitalPins; i++ )
{
OBJ_GetI( hPropDigitalInputs, &value, i );
printf( "pin %d: %d\n", i, value );
}
}
}
hPropDigitalOutputs = getIOSubSystemProp( hDrv, "DigitalOutputs" );
{
printf( "Can't detect digital outputs. Test skipped.\n" );
}
else
{
{
for( i = 0; i < noOfDigitalPins; 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" );
{
printf( "This device doesn't seem to offer multiple input channels.\n" );
return;
}
{
printf(
"Failed to read max value from property 'VideoChannel'(code: %d(%s))\n", result,
DMR_ErrorCodeToString( result ) );
return;
}
{
printf(
"Failed to read min value from property 'VideoChannel'(code: %d(%s))\n", result,
DMR_ErrorCodeToString( result ) );
return;
}
while( run )
{
{
printf(
"Failed to read current value from property 'VideoChannel'(code: %d(%s))\n", result,
DMR_ErrorCodeToString( result ) );
}
{
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;
}
{
printf(
"Failed to set value to property 'VideoChannel'(code: %d(%s))\n", result,
DMR_ErrorCodeToString( result ) );
}
}
}
void longTimeIntegration_mvBlueFOX( CaptureParameter* pCapParams, int exposureTime_ms )
{
HDRV hDrv = pCapParams->hDrv;
#ifdef USE_MV_DISPLAY_LIB
#endif
HOBJ hPropTriggerMode = getSettingProp( hDrv, "Base", "TriggerMode" );
HOBJ hPropTriggerSource = getSettingProp( hDrv, "Base", "TriggerSource" );
HOBJ hPropDigitalOutputs = getIOSubSystemProp( hDrv, "DigitalOutputs" );
{
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;
}
{
printf(
"Failed to configure trigger mode(code: %d(%s))\n", propHandlingError,
DMR_ErrorCodeToString( propHandlingError ) );
return;
}
{
printf(
"Failed to configure trigger source(code: %d(%s))\n", propHandlingError,
DMR_ErrorCodeToString( propHandlingError ) );
return;
}
{
return;
}
{
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
{
printf(
"Failed to modify digital output(code: %d(%s))\n", propHandlingError,
DMR_ErrorCodeToString( propHandlingError ) );
return;
}
{
{
#ifdef USE_MV_DISPLAY_LIB
#endif
}
else
{
printf(
"DMR_GetImageRequestBuffer: ERROR(code: %d(%s))\n", dmrError,
DMR_ErrorCodeToString( dmrError ) );
}
}
}
unsigned int LIVE_LOOP_CALL liveLoop( void* pData )
{
#ifdef USE_MV_DISPLAY_LIB
TDisp* pDisp;
#endif
int frameCount;
double fps;
int requestNr;
int lastRequestNr;
int expose_us;
int currentWidth;
int width;
hDrv = ( ( CaptureParameter* )pData )->hDrv;
#ifdef USE_MV_DISPLAY_LIB
#endif
pIB = 0;
frameCount = 0;
fps = 0.0;
expose_us = 10000;
requestNr = -1;
currentWidth = 0;
width = 0;
lastRequestNr = -1;
if( ( hPropFPS = getStatisticProp( hDrv,
"FramesPerSecond" ) ) ==
INVALID_ID )
{
printf( "Couldn't locate frames per second property! Unable to continue!\n" );
return 0;
}
if( ( hPropExpose_us = getSettingProp( hDrv,
"Base",
"Expose_us" ) ) ==
INVALID_ID )
{
printf( "Couldn't locate expose property! Will not modify the exposure time!\n" );
}
if( ( hPropWidth = getSettingProp( hDrv,
"Base",
"Camera/Aoi/W" ) ) ==
INVALID_ID )
{
printf( "Couldn't locate width property!\n" );
}
else
{
}
{
printf(
"DMR_ImageRequestSingle: Unexpected error(code: %d(%s))\n", result,
DMR_ErrorCodeToString( result ) );
}
manuallyStartAcquisitionIfNeeded( hDrv );
while( !s_boTerminated )
{
const int timeout_ms = 500;
int overallTimeWaited_ms = 0;
{
{
frameCount = frameCount + 1;
if( ( frameCount % 100 ) == 0 )
{
{
expose_us = ( ( expose_us + 10000 ) % 30000 ) + 10000;
OBJ_SetI( hPropExpose_us, expose_us, 0 );
printf( "Current expose time(us): %d\n", expose_us );
}
{
OBJ_GetI( hPropWidth, ¤tWidth, 0 );
if( currentWidth == width )
{
currentWidth = width / 2;
}
else
{
currentWidth = width;
}
OBJ_SetI( hPropWidth, currentWidth, 0 );
}
printf( "Frames per second: %.5f.\n", fps );
}
{
#ifdef USE_MV_DISPLAY_LIB
#endif
}
else
{
}
}
else
{
printf(
"DMR_GetImageRequestResult: ERROR! Return value: %d(%s), request result: %d.\n", result,
DMR_ErrorCodeToString( result ), ReqRes.
result );
}
if( lastRequestNr >= 0 )
{
}
lastRequestNr = requestNr;
}
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;
#endif
}
manuallyStopAcquisitionIfNeeded( hDrv );
#ifdef USE_MV_DISPLAY_LIB
#endif
if( requestNr >= 0 )
{
}
{
}
{
}
{
}
return 0;
}
void captureLoop( CaptureParameter* pCaptureParams )
{
#ifdef _WIN32
HANDLE hThread = NULL;
unsigned int threadID = 0;
#endif
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__
if( getch() == EOF )
{
printf( "Calling 'getch' did return EOF...\n" );
}
# else
if( _getch() == EOF )
{
printf( "Calling '_getch' did return EOF...\n" );
}
# endif
s_boTerminated = 1;
WaitForSingleObject( hThread, INFINITE );
CloseHandle( hThread );
#else
liveLoop( pCaptureParams );
#endif
}
int main( int argc, char* argv[] )
{
CaptureParameter captureParameter;
unsigned int i = 0;
char* pStringBuffer = NULL;
( void )argc;
( void )argv;
{
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 );
{
END_APPLICATION;
}
{
{
selectInputChannel( hDrv );
}
}
modifyEnumPropertyI( hDrv, "Base", "TriggerMode" );
modifyEnumPropertyI( hDrv, "Base", "TriggerSource" );
#ifdef USE_MV_DISPLAY_LIB
#endif
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
#endif
{
}
{
}
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:750
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:809
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