Impact Acquire SDK C++
GenericInterfaceLayout.cpp

Parts of the GenericInterfaceLayout program are based on the SingleCapture.cpp example concerning the single snap of an image. The sample shows all GenICam™ interface properties which can be modified.

Program location
The source file GenericInterfaceLayout.cpp can be found under:
%INSTALLDIR%GenericInterfaceLayout
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.
GenericInterfaceLayout example:
  1. Opens a Balluff device.
  2. Afterwards, there are different possibilities, e.g. to snap an image, to list and change properties, etc.
Console Output
[0]: GX001559 (mvBlueCOUGAR-X122G, Family: mvBlueCOUGAR, interface layout: GenICam, acquisition start/snap behaviour: user)

Please enter the number in front of the listed device followed by [ENTER] to open it: 0
Using device number 0.
Initialising the device. This might take some time...
enter quit, snap, list, help or the name of the property you want to modify followed by [ENTER]:

...
How it works
After getting the device from user input the sample shows on Windows® system a image display (mvIMPACT::acquire::display) at the same time the sample offeres several possibilities.
  1. With list, device properties will be listed via a StringPropMap container. After the properties have been listed, you can set the properties.
  2. With snap, the sample will snap one image from the device and updates the image display.
StringPropMap propertyMap;
DeviceComponentLocator locator( pDev, dltSetting, "Base" );
populatePropertyMap( propertyMap, Component( locator.searchbase_id() ).firstChild() );
locator = DeviceComponentLocator( pDev, dltRequest );
populatePropertyMap( propertyMap, Component( locator.searchbase_id() ).firstChild() );
locator = DeviceComponentLocator( pDev, dltSystemSettings );
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" ) );

populatePropertyMap creates the path and shows the possible settings for each property.

Source code
//
// @description: Example applications for Impact Acquire
// @copyright: Copyright (C) 2005 - 2024 Balluff GmbH
// @authors: APIs and drivers development team at Balluff GmbH
// @initial date: 2005-05-04
//
// 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,i
// 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 <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 // #ifdef _WIN32
using namespace std;
using namespace mvIMPACT::acquire;
using StringPropMap = map<string, Property>;
//-----------------------------------------------------------------------------
struct CaptureParameter
//-----------------------------------------------------------------------------
{
Device* pDev;
#ifdef USE_DISPLAY
shared_ptr<ImageDisplayWindow> pDisplayWindow;
#endif // #ifdef USE_DISPLAY
explicit CaptureParameter( Device* p ) : pDev( p ), fi( p )
{
#ifdef USE_DISPLAY
// IMPORTANT: It's NOT safe to create multiple display windows in multiple threads!!!
pDisplayWindow = make_shared<ImageDisplayWindow>( "mvIMPACT_acquire sample, Device " + pDev->serial.read() );
#endif // #ifdef USE_DISPLAY
}
CaptureParameter( const CaptureParameter& src ) = delete;
CaptureParameter& operator=( const CaptureParameter& rhs ) = delete;
};
//-----------------------------------------------------------------------------
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;
// method object will be ignored...
}
}
//-----------------------------------------------------------------------------
void singleCapture( CaptureParameter& params, int maxWaitTime_ms )
//-----------------------------------------------------------------------------
{
// send a request to the default request queue of the device and
// wait for the result.
params.fi.imageRequestSingle();
manuallyStartAcquisitionIfNeeded( params.pDev, params.fi );
// wait for the image send to the default capture queue
int requestNr = params.fi.imageRequestWaitFor( maxWaitTime_ms );
// check if the image has been captured without any problems
if( params.fi.isRequestNrValid( requestNr ) )
{
const Request* pRequest = params.fi.getRequest( requestNr );
if( pRequest->isOK() )
{
// everything went well. Display the result...
#ifdef USE_DISPLAY
params.pDisplayWindow->GetImageDisplay().SetImage( pRequest );
params.pDisplayWindow->GetImageDisplay().Update();
#else
cout << "Image captured(" << pRequest->imageWidth.read() << "x" << pRequest->imageHeight.read() << ")" << endl;
#endif // #ifdef USE_DISPLAY
}
else
{
cout << "A request has been returned, but the acquisition was not successful. Reason: " << pRequest->requestResult.readS() << endl;
}
// ... unlock the request again, so that the driver can use it again
params.fi.imageRequestUnlock( requestNr );
}
else
{
// Please note that slow systems or interface technologies in combination with high resolution sensors
// might need more time to transmit an image than the timeout value which has been passed to imageRequestWaitFor().
// If this is the case simply wait multiple times OR increase the timeout(not recommended as usually not necessary
// and potentially makes the capture thread less responsive) and rebuild this application.
// Once the device is configured for triggered image acquisition and the timeout elapsed before
// the device has been triggered this might happen as well.
// The return code would be -2119(DEV_WAIT_FOR_REQUEST_FAILED) in that case, the documentation will provide
// additional information under TDMR_ERROR in the interface reference.
// If waiting with an infinite timeout(-1) it will be necessary to call 'imageRequestReset' from another thread
// to force 'imageRequestWaitFor' to return when no data is coming from the device/can be captured.
cout << "The acquisition failed: " << ImpactAcquireException::getErrorCodeAsString( requestNr ) << endl;
}
manuallyStopAcquisitionIfNeeded( params.pDev, params.fi );
// in any case clear the queue to have consistent behaviour the next time this function gets called
// as otherwise an image not ready yet might be returned directly when this function gets called the next time
params.fi.imageRequestReset( 0, 0 );
}
//-----------------------------------------------------------------------------
bool isDeviceSupportedBySample( const Device* const pDev )
//-----------------------------------------------------------------------------
{
if( !pDev->interfaceLayout.isValid() )
{
return false;
}
vector<TDeviceInterfaceLayout> availableInterfaceLayouts;
pDev->interfaceLayout.getTranslationDictValues( availableInterfaceLayouts );
return find( availableInterfaceLayouts.begin(), availableInterfaceLayouts.end(), dilGenICam ) != availableInterfaceLayouts.end();
}
//-----------------------------------------------------------------------------
int main( void )
//-----------------------------------------------------------------------------
{
cout << "This sample is meant for devices that support the GenICam interface layout only. Other devices might be installed" << endl
<< "but won't be recognized by the application." << endl
<< endl;
DeviceManager devMgr;
Device* pDev = getDeviceFromUserInput( devMgr, isDeviceSupportedBySample );
if( pDev == nullptr )
{
cout << "Unable to continue! Press [ENTER] to end the application" << endl;
cin.get();
return 1;
}
cout << "Initialising the device. This might take some time..." << endl;
try
{
pDev->open();
}
catch( const ImpactAcquireException& e )
{
// this e.g. might happen if the same device is already opened in another process...
cout << "An error occurred while opening the device(error code: " << e.getErrorCode() << ")." << endl
<< "Press [ENTER] to end the application" << endl;
cin.get();
return 1;
}
CaptureParameter captureParameter( pDev );
// obtain all the settings related properties available for this device
// Only work with the 'Base' setting. For more information please refer to the manual (working with settings)
StringPropMap propertyMap;
DeviceComponentLocator locator( pDev, dltSetting, "Base" );
populatePropertyMap( propertyMap, Component( locator.searchbase_id() ).firstChild() );
locator = DeviceComponentLocator( pDev, dltRequest );
populatePropertyMap( propertyMap, Component( locator.searchbase_id() ).firstChild() );
locator = DeviceComponentLocator( pDev, dltSystemSettings );
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 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
{
const 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
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
PropertyIDeviceInterfaceLayout interfaceLayout
An enumerated integer property which can be used to define which interface layout shall be used when ...
Definition mvIMPACT_acquire.h:6644
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
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