The property handling functions use at a basic level the read and write functions:
In addition to the device handling related functionalities there is a specific function to check the payload type of a received mvIMPACT::acquire::Request object:
#ifndef exampleHelperH
#define exampleHelperH exampleHelperH
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <common/designData.h>
#include <mvIMPACT_CPP/mvIMPACT_acquire.h>
template<class _Ty>
class DisplayDictEntry
{
public:
void operator()( const std::pair<std::string, _Ty>& data ) const
{
std::cout << " [" << data.second << "]: " << data.first << std::endl;
}
};
class DisplayComponent
{
public:
void operator()( const Component& data ) const
{
if( data.isValid() )
{
std::cout << " " << data.name() << "(" << data.typeAsString() << ")" << std::endl;
}
}
};
class DisplayProperty
{
public:
void operator()( const std::pair<std::string, mvIMPACT::acquire::Property>& data ) const
{
if( data.second.isValid() )
{
std::cout << data.first << ": " << data.second.readSArray() << "(" << data.second.flagsAsString() << ")" << std::endl;
}
}
};
template<class _Ty>
{
_Ty prop( p );
#if defined(_MSC_VER) && (_MSC_VER < 1300)
std::vector<std::pair<std::string, _Ty::value_type> > dict;
prop.getTranslationDict( dict );
std::for_each( dict.begin(), dict.end(), DisplayDictEntry<_Ty::value_type>() );
#else
std::vector<std::pair<std::string, typename _Ty::value_type> > dict;
prop.getTranslationDict( dict );
std::for_each( dict.begin(), dict.end(), DisplayDictEntry<typename _Ty::value_type>() );
#endif
}
template<class _Tx>
bool supportsEnumStringValue( const _Tx& prop, const std::string& value )
{
if( prop.hasDict() )
{
typename std::vector<std::string> sequence;
prop.getTranslationDictStrings( sequence );
return std::find( sequence.begin(), sequence.end(), value ) != sequence.end();
}
return false;
}
template<class _Tx, typename _Ty>
bool supportsValue( const _Tx& prop, const _Ty& value )
{
if( prop.hasDict() )
{
typename std::vector<_Ty> sequence;
prop.getTranslationDictValues( sequence );
return std::find( sequence.begin(), sequence.end(), value ) != sequence.end();
}
if( prop.hasMinValue() && ( prop.getMinValue() > value ) )
{
return false;
}
if( prop.hasMaxValue() && ( prop.getMaxValue() < value ) )
{
return false;
}
return true;
}
template<typename _Ty, typename _Tx>
void conditionalSetProperty( const _Ty& prop, const _Tx& value, bool boSilent = false )
{
if( prop.isValid() && prop.isWriteable() && supportsValue( prop, value ) )
{
prop.write( value );
if( !boSilent )
{
std::cout << "Property '" << prop.name() << "' set to '" << prop.readS() << "'." << std::endl;
}
}
}
template<typename _Ty>
void conditionalSetEnumPropertyByString( const _Ty& prop, const std::string& value, bool boSilent = false )
{
if( prop.isValid() && prop.isWriteable() && supportsEnumStringValue( prop, value ) )
{
prop.writeS( value );
if( !boSilent )
{
std::cout << "Property '" << prop.name() << "' set to '" << prop.readS() << "'." << std::endl;
}
}
}
{
const std::string name( prop.
name() );
std::cout << std::endl
<<
"Property '" << name <<
"'(display name: '" << prop.
displayName() <<
"', type: " << prop.
typeAsString() <<
") currently specifies the following flags: " << prop.
flagsAsString() << std::endl
<< std::endl;
if( !doc.empty() )
{
std::cout << "The following documentation has been reported by the driver for this feature: " << std::endl
<< doc << std::endl
<< std::endl;
}
{
std::vector<Component> selectedFeatureList;
std::cout << "The following features are selected by this feature(Whenever the current feature is modified, all selected features might change):" << std::endl;
std::for_each( selectedFeatureList.begin(), selectedFeatureList.end(), DisplayComponent() );
std::cout << std::endl;
}
{
std::vector<Component> selectingFeatureList;
std::cout << "The following features select this feature(Whenever a selecting features is modified, a selected one might change):" << std::endl;
std::for_each( selectingFeatureList.begin(), selectingFeatureList.end(), DisplayComponent() );
std::cout << std::endl;
}
{
}
{
}
{
}
{
std::cout << "'" << name << "' defines a dictionary. Valid values are: " << std::endl;
{
DisplayPropertyDictionary<mvIMPACT::acquire::PropertyI>( prop );
}
{
DisplayPropertyDictionary<mvIMPACT::acquire::PropertyI64>( prop );
}
{
DisplayPropertyDictionary<mvIMPACT::acquire::PropertyF>( prop );
}
else
{
std::cout <<
"Error! Unhandled enum prop type: " << prop.
typeAsString() << std::endl;
}
}
std::cout <<
"The current value of '" << name <<
"' is: '" << prop.
readS() <<
"'" << std::endl;
}
{
{
std::cout << "Property '" << name << "' is not supported/available." << std::endl;
return false;
}
displayPropertyData( prop );
return true;
}
{
{
{
std::cout << "'FunctionInterface.acquisitionStart' returned with an unexpected result: " << result
}
}
}
{
{
{
std::cout << "'FunctionInterface.acquisitionStop' returned with an unexpected result: " << result
}
}
}
inline void modifyPropertyValue(
const mvIMPACT::acquire::Property& prop,
const std::string& param =
"",
const std::string& index =
"" )
{
try
{
const std::string name( prop.
name() );
{
int valIndex = 0;
if( param.empty() )
{
std::cout << "Enter the new value for '" << name << "': ";
std::string val;
std::cin >> val;
std::cin.get();
{
std::cout <<
"'" << name <<
"' defines " << prop.
valCount() <<
" values. Enter the index (zero-based) of the value to modify: ";
std::cin >> valIndex;
std::cin.get();
}
}
else
{
if( !index.empty() )
{
valIndex = atoi( index.c_str() );
}
prop.
writeS( param, valIndex );
}
}
else
{
std::cout << "'" << name << "' is read-only, thus can't be modified." << std::endl;
}
}
{
}
}
{
if( displayPropertyDataWithValidation( prop, name ) )
{
modifyPropertyValue( prop );
}
std::cout << std::endl;
}
{
ImageBuffer* pImageBuffer = 0;
switch( payloadType )
{
{
std::cout << "Buffer of type '" << bufferTypeAsString << "' captured, containing " << bufferPartCount << " part" << ( ( bufferPartCount > 1 ) ? "s (just the first one will be displayed)" : "" ) << std::endl;
for( unsigned int i = 0; i < bufferPartCount; i++ )
{
#ifndef __clang_analyzer__
#endif
std::cout <<
" Part " << i <<
" contains data of type: '" << pRequest->
getBufferPart( i ).
dataType.
readS() <<
"' - " << pPart->iWidth <<
"x" << pPart->iHeight <<
" pixels @ " << pPart->iBytesPerPixel <<
" bytes per pixel";
if( ( ( partType == bpdtGDC_2DImage ) || ( partType == bpdt2DImage ) ) && !pImageBuffer )
{
}
std::cout << std::endl;
}
}
break;
break;
default:
std::cout <<
"Buffer of type '" << bufferTypeAsString <<
"' with " << pRequest->
bufferSizeFilled.
read() <<
" bytes captured but its data type can not be displayed within this example." << std::endl;
break;
}
return pImageBuffer;
}
{
return out;
}
template<class _Elem, class _Traits, class _Ax>
int match( const std::basic_string<_Elem, _Traits, _Ax>& searchString, const std::basic_string<_Elem, _Traits, _Ax>& candidate, _Elem wildcard )
{
typename std::basic_string<_Elem, _Traits, _Ax>::size_type searchLength = searchString.length();
if( candidate.length() < searchString.length() )
{
if( candidate.empty() )
{
return -1;
}
if( candidate[candidate.length() - 1] != wildcard )
{
return -1;
}
searchLength = candidate.length() - 1;
}
for( typename std::basic_string<_Elem, _Traits, _Ax>::size_type i = 0; i < searchLength; i++ )
{
if( ( candidate[i] != searchString[i] ) && ( candidate[i] != wildcard ) )
{
return -1;
}
}
return 0;
}
{
if( devCnt == 0 )
{
std::cout << "No compliant device found!" << std::endl;
return 0;
}
std::set<unsigned int> validDeviceNumbers;
for( unsigned int i = 0; i < devCnt; i++ )
{
Device* pDev = devMgr[i];
if( pDev )
{
if( !pSupportedDeviceCheckFn || pSupportedDeviceCheckFn( pDev ) )
{
std::cout << "[" << i << "]: " << pDev->serial.read() << " (" << pDev->product.read() << ", " << pDev->family.read();
if( pDev->interfaceLayout.isValid() )
{
if( boAutomaticallyUseGenICamInterface )
{
conditionalSetProperty( pDev->interfaceLayout, dilGenICam, true );
}
std::cout << ", interface layout: " << pDev->interfaceLayout.readS();
}
if( pDev->acquisitionStartStopBehaviour.isValid() )
{
conditionalSetProperty( pDev->acquisitionStartStopBehaviour, assbUser, true );
std::cout << ", acquisition start/stop behaviour: " << pDev->acquisitionStartStopBehaviour.readS();
}
if( pDev->interfaceLayout.isValid() && !pDev->interfaceLayout.isWriteable() && pDev->isInUse() )
{
std::cout << ", !!!ALREADY IN USE!!!";
}
std::cout << ")" << std::endl;
validDeviceNumbers.insert( i );
}
}
}
if( validDeviceNumbers.empty() )
{
std::cout << devMgr.
deviceCount() <<
" devices have been detected:" << std::endl;
for( unsigned int i = 0; i < devCnt; i++ )
{
Device* pDev = devMgr[i];
if( pDev )
{
std::cout << " [" << i << "]: " << pDev->serial.read() << " (" << pDev->product.read() << ", " << pDev->family.read() << ")" << std::endl;
}
}
std::cout << "However none of these devices seems to be supported by this sample." << std::endl << std::endl;
return 0;
}
std::cout << std::endl << "Please enter the number in front of the listed device followed by [ENTER] to open it: ";
unsigned int devNr = 0;
std::cin >> devNr;
std::cin.get();
if( validDeviceNumbers.find( devNr ) == validDeviceNumbers.end() )
{
std::cout << "Invalid selection!" << std::endl;
return 0;
}
if( !boSilent )
{
std::cout << "Using device number " << devNr << "." << std::endl;
}
return devMgr[devNr];
}
inline std::vector<mvIMPACT::acquire::Device*>::size_type getValidDevices(
const mvIMPACT::acquire::DeviceManager& devMgr, std::vector<mvIMPACT::acquire::Device*>& v, SUPPORTED_DEVICE_CHECK pSupportedDeviceCheckFn = 0 )
{
for( unsigned int i = 0; i < devCnt; i++ )
{
Device* pDev = devMgr[i];
if( pDev )
{
if( !pSupportedDeviceCheckFn || pSupportedDeviceCheckFn( pDev ) )
{
v.push_back( pDev );
}
}
}
return v.size();
}
#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__APPLE__)
# include <fcntl.h>
# include <stdio.h>
# include <sys/types.h>
# include <termios.h>
# include <unistd.h>
inline unsigned waitForInput( int maxWait_sec, int fd )
{
fd_set rfds;
struct timeval tv;
FD_ZERO( &rfds );
#ifndef __clang_analyzer__
FD_SET( fd, &rfds );
#endif
tv.tv_sec = maxWait_sec;
tv.tv_usec = 0;
return select( fd + 1, &rfds, NULL, NULL, &tv );
}
inline int checkKeyboardInput( void )
{
struct termios oldt, newt;
tcgetattr( STDIN_FILENO, &oldt );
newt = oldt;
newt.c_lflag &= ~( ICANON | ECHO );
tcsetattr( STDIN_FILENO, TCSANOW, &newt );
const int oldf = fcntl( STDIN_FILENO, F_GETFL, 0 );
fcntl( STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK );
const int ch = getchar();
tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
fcntl( STDIN_FILENO, F_SETFL, oldf );
if( ch != EOF )
{
return 1;
}
return 0;
}
#endif
#endif
const ImageBufferDesc & getImageBufferDesc(void) const
Returns a const reference to the image buffer descriptor of this buffer part.
Definition mvIMPACT_acquire.h:8465
PropertyI64BufferPartDataType dataType
An enumerated 64-bit integer property (read-only) containing the data type of this buffer part.
Definition mvIMPACT_acquire.h:8513
std::string displayName(void) const
Returns the display name of the component referenced by this object.
Definition mvIMPACT_acquire.h:1217
std::string name(void) const
Returns the name of the component referenced by this object.
Definition mvIMPACT_acquire.h:1206
unsigned int selectedFeatureCount(void) const
Returns the number of features selected by the current one.
Definition mvIMPACT_acquire.h:1928
std::string docString(void) const
Returns a string containing general information about the component referenced by this object.
Definition mvIMPACT_acquire.h:1623
unsigned int selectedFeatures(std::vector< Component > &v) const
Retrieves the list of components that are selected by the current one.
Definition mvIMPACT_acquire.h:1965
TComponentType type(void) const
Returns the type of the referenced component.
Definition mvIMPACT_acquire.h:1785
bool isWriteable(void) const
Checks if the caller has write/modify access to the component.
Definition mvIMPACT_acquire.h:1755
bool isValid(void) const
Checks if the internal component referenced by this object is still valid.
Definition mvIMPACT_acquire.h:1721
std::string flagsAsString(const std::string &separator=" | ") const
Returns the flags associated with this component as a string.
Definition mvIMPACT_acquire.h:1645
std::string typeAsString(void) const
Returns the type of the referenced component as a string.
Definition mvIMPACT_acquire.h:1809
unsigned int selectingFeatures(std::vector< Component > &v) const
Retrieves the list of components that are selecting the current one.
Definition mvIMPACT_acquire.h:1990
unsigned int selectingFeatureCount(void) const
Returns the number of features selecting the current one.
Definition mvIMPACT_acquire.h:1942
Grants access to devices that can be operated by this software interface.
Definition mvIMPACT_acquire.h:7171
unsigned int deviceCount(void) const
Returns the number of devices currently present in the system.
Definition mvIMPACT_acquire.h:7400
This class and its functions represent an actual device detected by this interface in the current sys...
Definition mvIMPACT_acquire.h:6118
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:4907
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
int acquisitionStop(void) const
Manually stops the acquisition engine of this device driver instance.
Definition mvIMPACT_acquire.h:11018
int acquisitionStart(void) const
Manually starts the acquisition engine of this device driver instance.
Definition mvIMPACT_acquire.h:10992
ImageBuffer * getBuffer(void) const
Grants access to the underlying mvIMPACT::acquire::ImageBuffer structure managed by this object.
Definition mvIMPACT_acquire.h:8313
A base class for exceptions generated by Impact Acquire.
Definition mvIMPACT_acquire.h:256
std::string getErrorString(void) const
Returns an error string containing information about the reason for the error.
Definition mvIMPACT_acquire.h:270
std::string getErrorCodeAsString(void) const
Returns a string representation of the error associated with the exception.
Definition mvIMPACT_acquire.h:288
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
bool hasMaxValue(void) const
Checks if a maximum value is defined for this property.
Definition mvIMPACT_acquire.h:3305
bool hasMinValue(void) const
Checks if a minimum value is defined for this property.
Definition mvIMPACT_acquire.h:3317
unsigned int valCount(void) const
Returns the current number of values managed by this property.
Definition mvIMPACT_acquire.h:3506
bool hasStepWidth(void) const
Checks if a step width is defined for this property.
Definition mvIMPACT_acquire.h:3329
const Property & writeS(const std::string &value, int index=0) const
Assigns a new value to this property.
Definition mvIMPACT_acquire.h:3550
bool hasDict(void) const
Returns whether this property defines a translation dictionary or not.
Definition mvIMPACT_acquire.h:3274
Contains information about a captured buffer.
Definition mvIMPACT_acquire.h:8640
unsigned int getBufferPartCount(void) const
Returns the number of buffer parts currently associated with this request.
Definition mvIMPACT_acquire.h:8997
PropertyI64 bufferSizeFilled
A 64bit integer property (read-only) containing the total amount of data (in bytes) that has been cap...
Definition mvIMPACT_acquire.h:9808
PropertyIPayloadType payloadType
An enumerated integer property (read-only) defining the payload type of this request.
Definition mvIMPACT_acquire.h:9817
BufferPart & getBufferPart(unsigned int index) const
Returns a reference to a buffer part descriptor of this request.
Definition mvIMPACT_acquire.h:9023
TDMR_ERROR
Errors reported by the device manager.
Definition mvDriverBaseEnums.h:2601
TComponentType
Allowed components handled by this module.
Definition mvPropHandlingDatatypes.h:327
TBufferPartDataType
Defines buffer part data types.
Definition TBufferPartDataType.h:41
@ DMR_NO_ERROR
The function call was executed successfully.
Definition mvDriverBaseEnums.h:2603
@ ptChunkOnly
Chunk data only.
Definition mvDriverBaseEnums.h:4360
@ ptJPEG
JPEG image data.
Definition mvDriverBaseEnums.h:4336
@ ptJPEG2000
JPEG 2000 image data.
Definition mvDriverBaseEnums.h:4343
@ pt2DImage
Color or monochrome (2D) image.
Definition mvDriverBaseEnums.h:4329
@ ptGenDC
GenDC data.
Definition mvDriverBaseEnums.h:4383
@ ptH264
H.264 image data.
Definition mvDriverBaseEnums.h:4350
@ ptMultiPart
Multi-Part data.
Definition mvDriverBaseEnums.h:4371
@ ptUnknown
The framework is not aware of the data type of this request.
Definition mvDriverBaseEnums.h:4321
@ assbUser
The user can control the start and stop of the data transfer from the device.
Definition mvDriverBaseEnums.h:170
@ ctPropInt64
Defines a property for 64 bit integer values.
Definition mvPropHandlingDatatypes.h:356
@ ctPropFloat
Defines a property for floating point values.
Definition mvPropHandlingDatatypes.h:350
@ ctPropInt
Defines a property for 32 bit integer values.
Definition mvPropHandlingDatatypes.h:348
@ plStepWidth
Set/Get the step width value for this mvIMPACT::acquire::Property.
Definition mvIMPACT_acquire.h:3033
@ plMinValue
Set/Get the minimum value for this mvIMPACT::acquire::Property.
Definition mvIMPACT_acquire.h:3026
@ plMaxValue
Set/Get the maximum value for this mvIMPACT::acquire::Property.
Definition mvIMPACT_acquire.h:3019