#ifdef _MSC_VER
# if _MSC_VER < 1300
# pragma warning( disable : 4786 )
# endif
#endif
#include <iostream>
#include <algorithm>
#include <map>
#include <apps/Common/exampleHelper.h>
#if !defined(linux) && !defined(__linux) && !defined(__linux__)
#else
typedef void* ImageDisplayWindow;
#endif
using namespace std;
typedef map<string, Property> StringPropMap;
void populatePropertyMap( StringPropMap& m, Component it, const string& currentPath = "" )
{
while( it.isValid() )
{
string fullName( currentPath );
if( fullName != "" )
{
fullName += "/";
}
fullName += it.name();
if( it.isList() )
{
populatePropertyMap( m, it.firstChild(), fullName );
}
else if( it.isProp() )
{
m.insert( make_pair( fullName, Property( it ) ) );
}
++it;
}
}
void singleCapture( Device* pDev, const FunctionInterface& fi, ImageDisplayWindow* pDisp, int maxWaitTime_ms )
{
fi.imageRequestSingle();
manuallyStartAcquisitionIfNeeded( pDev, fi );
int requestNr = fi.imageRequestWaitFor( maxWaitTime_ms );
if( fi.isRequestNrValid( requestNr ) )
{
const Request* pRequest = fi.getRequest( requestNr );
if( pRequest->isOK() )
{
#if !defined(linux) && !defined(__linux) && !defined(__linux__)
pDisp->GetImageDisplay().SetImage( pRequest );
pDisp->GetImageDisplay().Update();
#else
cout << "Image captured(" << pRequest->imageWidth.read() << "x" << pRequest->imageHeight.read() << ")" << endl;
( void )pDisp;
#endif
}
else
{
cout << "A request has been returned, but the acquisition was not successful. Reason: " << pRequest->requestResult.readS() << endl;
}
fi.imageRequestUnlock( requestNr );
}
else
{
}
manuallyStopAcquisitionIfNeeded( pDev, fi );
fi.imageRequestReset( 0, 0 );
}
int main( int argc, char* argv[] )
{
DeviceManager devMgr;
Device* pDev = 0;
string settingName;
for( int i = 1; i < argc; i++ )
{
string arg( argv[i] );
if( arg.find( "-s" ) == 0 )
{
pDev = devMgr.getDeviceBySerial( arg.substr( 2 ) );
}
else
{
settingName = string( arg );
}
}
if( argc <= 1 )
{
cout << "Available command line parameters:" << endl
<< endl
<< "-s<serialNumber> to pre-select a certain device. If this device can be found no further user interaction is needed" << endl
<< "any other string will be interpreted as a name of a setting to load" << endl << endl;
}
if( !pDev )
{
pDev = getDeviceFromUserInput( devMgr );
}
if( !pDev )
{
cout << "Could not obtain a valid pointer to a device. Unable to continue!"
<< "Press [ENTER] to end the application" << endl;
cin.get();
return 1;
}
else
{
cout << "Initialising device: " << pDev->serial.read() << ". This might take some time..." << endl;
}
try
{
pDev->open();
}
catch( const ImpactAcquireException& e )
{
cout << "An error occurred while opening the device(error code: " << e.getErrorCode() << ")." << endl
<< "Press [ENTER] to end the application" << endl;
cin.get();
return 1;
}
FunctionInterface fi( pDev );
if( !settingName.empty() )
{
cout << "Trying to load setting " << settingName << "..." << endl;
int result = fi.loadSetting( settingName );
{
}
}
#if !defined(linux) && !defined(__linux) && !defined(__linux__)
ImageDisplayWindow* pDisp = new ImageDisplayWindow( "mvIMPACT_acquire sample" );
#else
ImageDisplayWindow* pDisp = 0;
#endif
StringPropMap propertyMap;
DeviceComponentLocator locator( pDev,
dltSetting,
"Base" );
populatePropertyMap( propertyMap, Component( locator.searchbase_id() ).firstChild() );
try
{
populatePropertyMap( propertyMap, Component( locator.searchbase_id() ).firstChild() );
}
catch( const ImpactAcquireException& ) {}
locator = DeviceComponentLocator( pDev,
dltRequest );
populatePropertyMap( propertyMap, Component( locator.searchbase_id() ).firstChild() );
populatePropertyMap( propertyMap, Component( locator.searchbase_id() ).firstChild(), string( "SystemSettings" ) );
locator = DeviceComponentLocator( pDev,
dltInfo );
populatePropertyMap( propertyMap, Component( locator.searchbase_id() ).firstChild(), string( "Info" ) );
populatePropertyMap( propertyMap, Component( pDev->hDev() ).firstChild(), string( "Device" ) );
string cmd;
int timeout_ms = 500;
bool boRun = true;
while( boRun )
{
cout << "enter quit, snap, list, help, save or the name of the property you want to modify followed by [ENTER]: ";
cin >> cmd;
if( cmd == "snap" )
{
singleCapture( pDev, fi, pDisp, timeout_ms );
}
else if( cmd == "list" )
{
for_each( propertyMap.begin(), propertyMap.end(), DisplayProperty() );
}
else if( cmd == "help" )
{
cout << "quit: terminates the sample" << endl
<< "snap: takes and displays one image with the current settings" << endl
<< "list: displays all properties available for this device" << endl
<< "help: displays this help text" << endl
<< "timeout: set a new timeout(in ms) used as a max. timeout to wait for an image" << endl
<< "the full name of a property must be specified" << endl;
}
else if( cmd == "quit" )
{
boRun = false;
continue;
}
else if( cmd == "timeout" )
{
cout << "Enter the new timeout to be passed to the imageRequestWaitFor function: ";
cin >> timeout_ms;
}
else if( cmd == "save" )
{
cout << "Saving global settings for the device " << pDev->serial.read() << endl;
}
else
{
StringPropMap::const_iterator it = propertyMap.find( cmd );
if( it == propertyMap.end() )
{
cout << "Unknown command or property" << endl;
}
else
{
displayPropertyData( it->second );
if( it->second.hasDict() )
{
cout << "This function expects the string representation as input!" << endl;
}
modifyPropertyValue( it->second );
}
}
}
#if !defined(linux) && !defined(__linux) && !defined(__linux__)
delete pDisp;
#endif
return 0;
}
std::string getErrorCodeAsString(void) const
Returns a string representation of the error associated with the exception.
Definition: mvIMPACT_acquire.h:280
@ DMR_NO_ERROR
The function call was executed successfully.
Definition: mvDriverBaseEnums.h:2270
@ dltSetting
Specifies a certain setting.
Definition: mvIMPACT_acquire.h:7613
@ dltIOSubSystem
Specifies the driver interface list containing properties to work with any kind of I/O pin belonging ...
Definition: mvIMPACT_acquire.h:7644
@ dltSystemSettings
Specifies the driver interface list containing properties, which influence the overall operation of t...
Definition: mvIMPACT_acquire.h:7638
@ dltInfo
Specifies the driver interfaces list containing general information.
Definition: mvIMPACT_acquire.h:7626
@ dltRequest
Specifies the list of driver owned image request objects.
Definition: mvIMPACT_acquire.h:7615
@ sfNative
Stores/loads the setting in/from a platform dependent location.
Definition: mvPropHandlingDatatypes.h:747
@ sGlobal
Save the setting as global as possible.
Definition: mvPropHandlingDatatypes.h:972
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: mvImageBuffer.h:42