#ifdef _MSC_VER
# if _MSC_VER < 1300
# pragma warning( disable : 4786 )
# endif
#endif
#include <iostream>
#include <ios>
#include <sstream>
#include <apps/Common/exampleHelper.h>
#include <mvIMPACT_CPP/mvIMPACT_acquire.h>
#include <mvIMPACT_CPP/mvIMPACT_acquire_GenICam.h>
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
# include <windows.h>
# include <process.h>
# include <mvDisplay/Include/mvIMPACT_acquire_display.h>
#else
# include <stdio.h>
# include <unistd.h>
#endif
using namespace std;
static bool s_boTerminated = false;
struct ThreadParameter
{
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
explicit ThreadParameter(
Device* p,
const std::string& windowTitle ) : pDev( p ), displayWindow( windowTitle ) {}
#else
explicit ThreadParameter(
Device* p ) : pDev( p ) {}
#endif
};
static bool canRestoreFactoryDefault(
Device* pDev )
{
if( !usc.userSetSelector.isValid() || !usc.userSetLoad.isValid() )
{
return false;
}
vector<string> validUserSetSelectorStrings;
usc.userSetSelector.getTranslationDictStrings( validUserSetSelectorStrings );
return find( validUserSetSelectorStrings.begin(), validUserSetSelectorStrings.end(), "Default" ) != validUserSetSelectorStrings.end();
}
unsigned int DMR_CALL liveThread( void* pData )
{
ThreadParameter* pThreadParameter = reinterpret_cast< ThreadParameter* >( pData );
unsigned int cnt = 0;
cout << "Initialising the device. This might take some time..." << endl;
cout << endl;
try
{
pThreadParameter->pDev->interfaceLayout.write( dilGenICam );
pThreadParameter->pDev->open();
}
{
cout << "An error occurred while opening the device " << pThreadParameter->pDev->serial.read()
<< "Press [ENTER] to end the application..." << endl;
cin.get();
return 0;
}
cout << "The device will be configured now!\n" << endl;
if( canRestoreFactoryDefault( pThreadParameter->pDev ) )
{
if( usc.userSetSelector.isValid() && usc.userSetSelector.isWriteable() && usc.userSetLoad.isValid() && usc.userSetLoad.isMeth() )
{
cout << "Loading the device's default user set to avoid undefined settings!\n" << endl;
usc.userSetSelector.writeS( "Default" );
usc.userSetLoad.call();
}
}
else
{
cout << "The device seems not to support the default user set!" << endl;
}
const double dExposureTime = 10000.;
if( acq.exposureTime.isValid() && acq.exposureTime.isWriteable() )
{
cout << "Currently the exposure time is set to " << acq.exposureTime.read() << " us. Changing to " << dExposureTime << " us" << endl;
cout << endl;
acq.exposureTime.write( dExposureTime );
}
if( ifc.width.isValid() && ifc.height.isValid() )
{
cout << "The sensor has a max resolution of about " << ifc.width.getMaxValue() << "x" << ifc.height.getMaxValue() << " pixels" << endl;
cout << "The resolution will now be adjusted to the half of width and height. The resulting AOI will be: " << ifc.width.getMaxValue() / 2 << "x" << ifc.height.getMaxValue() / 2 << " pixels" << endl;
if( !ifc.width.isWriteable() || !ifc.height.isWriteable() )
{
cout << "Width or Height are not writable at the moment." << endl;
}
else
{
ifc.width.write( ifc.width.getMaxValue() / 2 );
ifc.height.write( ifc.height.getMaxValue() / 2 );
}
}
cout << endl;
cout << "To avoid some cabling work, we will use an internal timer for triggering in this sample!" << endl;
cout << "The trigger frequency will be configured to half of the max frequency the sensor would be capable of in your setup." << endl;
vector<string> availableTimers;
if( ctc.timerSelector.isValid() )
{
ctc.timerSelector.getTranslationDictStrings( availableTimers );
}
if( ctc.timerSelector.isValid() && ctc.timerSelector.isWriteable() && ( availableTimers.size() >= 2 ) && acq.triggerSelector.isValid() && acq.mvResultingFrameRate.isValid() )
{
ctc.timerSelector.writeS( "Timer1" );
vector<string> availableTriggerSources;
ctc.timerTriggerSource.getTranslationDictStrings( availableTriggerSources );
if( find( availableTriggerSources.begin(), availableTriggerSources.end(), "Timer2End" ) != availableTriggerSources.end() && acq.mvResultingFrameRate.isValid() )
{
const double dPeriod = 1000000. / ( acq.mvResultingFrameRate.read() / 2. );
if( dPeriod >= 300. )
{
ctc.timerDuration.write( 1000. );
ctc.timerTriggerSource.writeS( "Timer2End" );
ctc.timerTriggerSource.writeS( "Timer1End" );
ctc.timerSelector.writeS( "Timer2" );
ctc.timerDuration.write( dPeriod - 1000. );
acq.triggerSelector.writeS( "FrameStart" );
acq.triggerSource.writeS( "Timer1Start" );
acq.triggerMode.writeS( "On" );
}
}
else
{
cout << "This device does not support expected timer trigger sources! The device will work in free run mode instead!" << endl;
}
}
else
{
cout << "This device does not support timers! The device will work in free run mode instead!" << endl;
}
if( anc.gain.isValid() && anc.gain.isWriteable() )
{
anc.gain.write( anc.gain.getMaxValue() );
}
cout << "\nAvailable Digital IOs:" << endl;
vector<string> availableIOs;
dio.lineSelector.getTranslationDictStrings( availableIOs );
bool boConfiguredFirstOutput = false;
const vector<string>::size_type IOCnt = availableIOs.size();
for( vector<string>::size_type i = 0; i < IOCnt; i++ )
{
ostringstream oss;
oss << "Line" << i;
dio.lineSelector.writeS( oss.str() );
if( !boConfiguredFirstOutput && dio.lineMode.readS() == "Output" )
{
dio.lineSource.writeS( "mvExposureAndAcquisitionActive" );
boConfiguredFirstOutput = true;
}
cout << oss.str() << " - " << ( dio.lineMode.isValid() ? dio.lineMode.readS() : string( "UNSUPPORTED" ) )
<< " - LineStatus: " << ( dio.lineStatus.isValid() ? dio.lineStatus.readS() : string( "UNSUPPORTED" ) )
<< " - LineSource: " << ( dio.lineSource.isValid() ? dio.lineSource.readS() : string( "UNSUPPORTED" ) )
<< endl;
}
while( ( result =
static_cast< TDMR_ERROR >( fi.imageRequestSingle() ) ) == DMR_NO_ERROR ) {};
if( result != DEV_NO_FREE_REQUEST_AVAILABLE )
{
cout << "'FunctionInterface.imageRequestSingle' returned with an unexpected result: " << result
}
cout << "\nStarting image acquisition\n" << endl;
manuallyStartAcquisitionIfNeeded( pThreadParameter->pDev, fi );
const unsigned int timeout_ms = 5000;
while( !s_boTerminated )
{
int requestNr = fi.imageRequestWaitFor( timeout_ms );
pRequest = fi.isRequestNrValid( requestNr ) ? fi.getRequest( requestNr ) : 0;
if( pRequest )
{
{
++cnt;
if( cnt % 100 == 0 )
{
cout << "Info from " << pThreadParameter->pDev->serial.read()
<< ": " << statistics.framesPerSecond.name() << ": " << statistics.framesPerSecond.readS()
<< ", " << statistics.errorCount.name() << ": " << statistics.errorCount.readS()
<< ", " << statistics.captureTime_s.name() << ": " << statistics.captureTime_s.readS()
<< ", LineStatusAll: " << dio.lineStatusAll.readS() << endl;
anc.gain.write( ( anc.gain.read() == anc.gain.getMaxValue() ) ? anc.gain.getMinValue() : anc.gain.getMaxValue() );
}
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
pThreadParameter->displayWindow.GetImageDisplay().SetImage( pRequest );
pThreadParameter->displayWindow.GetImageDisplay().Update();
#else
#endif
}
else
{
}
if( pPreviousRequest )
{
}
pPreviousRequest = pRequest;
fi.imageRequestSingle();
}
else
{
cout << "imageRequestWaitFor failed (" << requestNr << ", " << ImpactAcquireException::getErrorCodeAsString( requestNr ) << ")"
<< ", timeout value too small?" << endl;
}
#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__APPLE__)
s_boTerminated = waitForInput( 0, STDOUT_FILENO ) == 0 ? false : true;
#endif
}
manuallyStopAcquisitionIfNeeded( pThreadParameter->pDev, fi );
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
pThreadParameter->displayWindow.GetImageDisplay().RemoveImage();
#endif
if( pRequest )
{
}
fi.imageRequestReset( 0, 0 );
return 0;
}
bool isDeviceSupportedBySample(
const Device*
const pDev )
{
{
return false;
}
vector<TDeviceInterfaceLayout> availableInterfaceLayouts;
return find( availableInterfaceLayouts.begin(), availableInterfaceLayouts.end(), dilGenICam ) != availableInterfaceLayouts.end();
}
int main( void )
{
cout << "--------------------------------------------!!! ATTENTION !!!--------------------------------------------" << endl;
cout << "Please be aware that the digital outputs of the device might be enabled during the test." << endl
<< "This might lead to unexpected behavior in case of devices which are connected to one of the digital outputs," << endl
<< "so only proceed if you are sure that this will not cause any issue with connected hardware!!" << endl;
cout << "---------------------------------------------------------------------------------------------------------" << endl;
cout << "" << endl;
Device* pDev = getDeviceFromUserInput( devMgr, isDeviceSupportedBySample );
if( !pDev )
{
cout << "Unable to continue! Press [ENTER] to end the application" << endl;
cin.get();
return 1;
}
cout << "Press [ENTER] to end the application" << endl;
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
unsigned int dwThreadID;
string windowTitle(
"mvIMPACT_acquire sample, Device " + pDev->
serial.
read() );
ThreadParameter threadParam( pDev, windowTitle );
HANDLE hThread = ( HANDLE )_beginthreadex( 0, 0, liveThread, ( LPVOID )( &threadParam ), 0, &dwThreadID );
cin.get();
s_boTerminated = true;
WaitForSingleObject( hThread, INFINITE );
CloseHandle( hThread );
#else
ThreadParameter threadParam( pDev );
liveThread( &threadParam );
#endif
return 0;
}
bool isValid(void) const
Checks if the internal component referenced by this object is still valid.
Definition mvIMPACT_acquire.h:1721
Grants access to devices that can be operated by this software interface.
Definition mvIMPACT_acquire.h:7171
This class and its functions represent an actual device detected by this interface in the current sys...
Definition mvIMPACT_acquire.h:6118
PropertyS serial
A string property (read-only) containing the serial number of this device.
Definition mvIMPACT_acquire.h:6551
PropertyIDeviceInterfaceLayout interfaceLayout
An enumerated integer property which can be used to define which interface layout shall be used when ...
Definition mvIMPACT_acquire.h:6644
PropertyIAcquisitionStartStopBehaviour acquisitionStartStopBehaviour
An enumerated integer property defining the start/stop behaviour during acquisition of this driver in...
Definition mvIMPACT_acquire.h:6800
ZYX read(int index=0) const
Reads a value from a property.
Definition mvIMPACT_acquire.h:4300
const EnumPropertyI & getTranslationDictValues(std::vector< ZYX > &sequence) const
This function queries a list of valid values for this property.
Definition mvIMPACT_acquire.h:4266
The function interface to devices supported by this interface.
Definition mvIMPACT_acquire.h:10758
Category for the acquisition and trigger control features.
Definition mvIMPACT_acquire_GenICam.h:2115
Category that contains the Analog control features.
Definition mvIMPACT_acquire_GenICam.h:3086
Category that contains the Counter and Timer control features.
Definition mvIMPACT_acquire_GenICam.h:4294
Category that contains the digital input and output control features.
Definition mvIMPACT_acquire_GenICam.h:3917
Category that contains the User Set control features.
Definition mvIMPACT_acquire_GenICam.h:9632
A base class for exceptions generated by Impact Acquire.
Definition mvIMPACT_acquire.h:256
std::string getErrorCodeAsString(void) const
Returns a string representation of the error associated with the exception.
Definition mvIMPACT_acquire.h:288
std::string read(int index=0) const
Reads a value from a property.
Definition mvIMPACT_acquire.h:5323
std::string readS(int index=0, const std::string &format="") const
Reads data from this property as a string.
Definition mvIMPACT_acquire.h:3340
Contains information about a captured buffer.
Definition mvIMPACT_acquire.h:8640
PropertyI imageHeight
An integer property (read-only) containing the height of the image in pixels.
Definition mvIMPACT_acquire.h:10331
bool isOK(void) const
Convenience function to check if a request has been processed successfully.
Definition mvIMPACT_acquire.h:9474
PropertyIRequestResult requestResult
An enumerated integer property (read-only) defining the result of this request.
Definition mvIMPACT_acquire.h:9780
PropertyI imageWidth
An integer property (read-only) containing the width of the image in pixels.
Definition mvIMPACT_acquire.h:10320
int unlock(void)
Unlocks the request for the driver again.
Definition mvIMPACT_acquire.h:9614
Contains basic statistical information.
Definition mvIMPACT_acquire.h:14509
A class that can be used to display images in a window.
Definition mvIMPACT_acquire_display.h:606
TDMR_ERROR
Errors reported by the device manager.
Definition mvDriverBaseEnums.h:2601
@ DMR_NO_ERROR
The function call was executed successfully.
Definition mvDriverBaseEnums.h:2603
This namespace contains classes and functions belonging to the GenICam specific part of the image acq...
Definition mvIMPACT_acquire.h:23827
This namespace contains classes and functions that can be used to display images.
This namespace contains classes and functions belonging to the image acquisition module of this SDK.
Definition mvCommonDataTypes.h:34