After selecting a device the user can choose what he wants to do. The program waits for the input:
bool boRun = true;
while( boRun )
{
cout << "enter quit, snap, list, help or the name of the property you want to modify followed by [ENTER]: ";
cin >> cmd;
if( cmd == "snap" )
{
singleCapture( boMustStartAcquisition, 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
{
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 );
}
}
}
'timeout' will define a new timeout used as a max. wait timeout for a snapped image to become ready
#include <algorithm>
#include <iostream>
#include <map>
#include <memory>
#include <apps/Common/exampleHelper.h>
#include <mvIMPACT_CPP/mvIMPACT_acquire.h>
#ifdef _WIN32
# include <mvDisplay/Include/mvIMPACT_acquire_display.h>
# define USE_DISPLAY
#endif
using namespace std;
using StringPropMap = map<string, Property>;
struct CaptureParameter
{
#ifdef USE_DISPLAY
shared_ptr<ImageDisplayWindow> pDisplayWindow;
#endif
explicit CaptureParameter(
Device* p ) : pDev( p ), fi( p )
{
#ifdef USE_DISPLAY
pDisplayWindow = make_shared<ImageDisplayWindow>(
"mvIMPACT_acquire sample, Device " + pDev->
serial.
read() );
#endif
}
CaptureParameter( const CaptureParameter& src ) = delete;
CaptureParameter& operator=( const CaptureParameter& rhs ) = delete;
};
void populatePropertyMap( StringPropMap& m,
Component it,
const string& currentPath =
"" )
{
{
string fullName( currentPath );
if( fullName != "" )
{
fullName += "/";
}
{
populatePropertyMap( m, it.
firstChild(), fullName );
}
{
m.insert( make_pair( fullName,
Property( it ) ) );
}
++it;
}
}
void singleCapture( CaptureParameter& params, int maxWaitTime_ms )
{
params.fi.imageRequestSingle();
manuallyStartAcquisitionIfNeeded( params.pDev, params.fi );
int requestNr = params.fi.imageRequestWaitFor( maxWaitTime_ms );
if( params.fi.isRequestNrValid( requestNr ) )
{
const Request* pRequest = params.fi.getRequest( requestNr );
{
#ifdef USE_DISPLAY
params.pDisplayWindow->GetImageDisplay().SetImage( pRequest );
params.pDisplayWindow->GetImageDisplay().Update();
#else
#endif
}
else
{
cout <<
"A request has been returned, but the acquisition was not successful. Reason: " << pRequest->
requestResult.
readS() << endl;
}
params.fi.imageRequestUnlock( requestNr );
}
else
{
cout << "The acquisition failed: " << ImpactAcquireException::getErrorCodeAsString( requestNr ) << endl;
}
manuallyStopAcquisitionIfNeeded( params.pDev, params.fi );
params.fi.imageRequestReset( 0, 0 );
}
int main( int argc, char* argv[] )
{
string settingName;
for( int i = 1; i < argc; i++ )
{
string arg( argv[i] );
if( arg.find( "-s" ) == 0 )
{
}
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 == nullptr )
{
pDev = getDeviceFromUserInput( devMgr );
}
if( pDev == nullptr )
{
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
{
}
{
cout <<
"An error occurred while opening the device(error code: " << e.
getErrorCode() <<
")." << endl
<< "Press [ENTER] to end the application" << endl;
cin.get();
return 1;
}
if( !settingName.empty() )
{
cout << "Trying to load setting " << settingName << "..." << endl;
int result = fi.loadSetting( settingName );
if( result != DMR_NO_ERROR )
{
cout << "loadSetting( \"" << settingName << "\" ); call failed: " << ImpactAcquireException::getErrorCodeAsString( result ) << endl;
}
}
CaptureParameter captureParameter( pDev );
StringPropMap propertyMap;
try
{
}
populatePropertyMap( propertyMap,
Component( locator.searchbase_id() ).
firstChild(),
string(
"SystemSettings" ) );
populatePropertyMap( propertyMap,
Component( locator.searchbase_id() ).
firstChild(),
string(
"Info" ) );
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( captureParameter, 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;
fi.saveSetting( pDev->
serial.
read(), sfNative, sGlobal );
}
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 );
}
}
}
return 0;
}
std::string name(void) const
Returns the name of the component referenced by this object.
Definition mvIMPACT_acquire.h:1206
A base class to implement access to internal driver components.
Definition mvIMPACT_acquire.h:1439
bool isValid(void) const
Checks if the internal component referenced by this object is still valid.
Definition mvIMPACT_acquire.h:1721
bool isProp(void) const
Checks if this component is of type mvIMPACT::acquire::Property or a derived type.
Definition mvIMPACT_acquire.h:1706
bool isList(void) const
Checks if this component is of type mvIMPACT::acquire::ComponentList.
Definition mvIMPACT_acquire.h:1686
Component firstChild(void) const
Moves to the first child of this component(moves down one level).
Definition mvIMPACT_acquire.h:1595
A class to locate components within the driver.
Definition mvIMPACT_acquire.h:8043
Grants access to devices that can be operated by this software interface.
Definition mvIMPACT_acquire.h:7171
Device * getDeviceBySerial(const std::string &serial="", unsigned int devNr=0, char wildcard=' *') const
Tries to locate a device via the serial number.
Definition mvIMPACT_acquire.h:7524
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
void open(void)
Opens a device.
Definition mvIMPACT_acquire.h:6420
HDEV hDev(void) const
A unique identifier for this device.
Definition mvIMPACT_acquire.h:6318
ZYX read(int index=0) const
Reads a value from a property.
Definition mvIMPACT_acquire.h:4300
The function interface to devices supported by this interface.
Definition mvIMPACT_acquire.h:10758
A base class for exceptions generated by Impact Acquire.
Definition mvIMPACT_acquire.h:256
int getErrorCode(void) const
Returns a unique numerical representation for this error.
Definition mvIMPACT_acquire.h:275
std::string read(int index=0) const
Reads a value from a property.
Definition mvIMPACT_acquire.h:5323
A base class for properties.
Definition mvIMPACT_acquire.h:3134
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
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