#ifdef _MSC_VER
# if _MSC_VER < 1300
# pragma warning( disable : 4786 )
# endif
#endif
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <vector>
#ifdef _WIN32
# include <windows.h>
#elif defined(linux) || defined(__linux) || defined(__linux__) || defined(__APPLE__)
# include <unistd.h>
#else
# error unsupported target platform
#endif
#include <apps/Common/exampleHelper.h>
#include <common/minmax.h>
#include <mvIMPACT_CPP/mvIMPACT_acquire.h>
#include <mvIMPACT_CPP/mvIMPACT_acquire_GenICam.h>
using namespace std;
string getStringFromCIN( void )
{
cout << endl << ">>> ";
string cmd;
cin >> cmd;
cin.get();
return cmd;
}
int getIntFromCIN( void )
{
return atoi( getStringFromCIN().c_str() );
}
int getHEXFromCIN( void )
{
int result = 0;
#if (defined(_MSC_VER) && (_MSC_VER >= 1400)) || defined (__STDC_LIB_EXT1__)
sscanf_s( getStringFromCIN().c_str(), "%i", &result );
#else
sscanf( getStringFromCIN().c_str(), "%i", &result );
#endif
return result;
}
template<typename _Ty>
void hexToCOUT( const _Ty& param )
{
cout.setf( ios::hex, ios::basefield );
cout << "0x" << param;
cout.unsetf( ios::hex );
}
{
}
{
cout << "This device has" << endl;
cout << " " << inputCount << " digital input(s)" << endl;
for( unsigned int i = 0; i < inputCount; i++ )
{
}
cout << endl;
if( inputCount > 0 )
{
cout << "All input registers can be queried with a single function call: Calling 'readInputRegister' returned ";
cout << endl;
cout << "From the LSB to the MSB a '1' in this result indicates, that this input is currently connected to a signal" << endl
<< "that is interpreted as a logical '1'. E.g. 0x13 indicates that inputs 0, 1 and 4 are currently in 'high' state." << endl;
}
cout << " " << outputCount << " digital output(s)" << endl;
if( outputCount > 0 )
{
unsigned int readOnlyAccessMask = 0;
bool boRun = true;
while( boRun )
{
for( unsigned int j = 0; j < outputCount; j++ )
{
cout <<
" [" << j <<
"]: " << pOutput->
getDescription() <<
"(current state: " << pOutput->
get() <<
", " << ( pOutput->
isWriteable() ?
"" :
"NOT " ) <<
"manually switchable)" << endl;
{
readOnlyAccessMask |= 1 << j;
}
}
cout << endl;
cout << "Enter the number of a digital output followed by [ENTER] to modify its state or 'c' followed by [ENTER] to continue." << endl;
const string cmd( getStringFromCIN() );
if( cmd == "c" )
{
boRun = false;
continue;
}
const unsigned int index = static_cast<unsigned int>( atoi( cmd.c_str() ) );
if( ( index >= outputCount ) || !isdigit( cmd[0] ) )
{
cout << "Invalid selection" << endl;
continue;
}
{
cout << pOutput->
getDescription() <<
" is not manually switchable." << endl;
continue;
}
cout << "Please enter the number in front of the function that shall be called followed by [ENTER]:" << endl;
cout << " [0]: set" << endl
<< " [1]: reset" << endl
<< " [2]: flip" << endl;
const int newMode = getIntFromCIN();
switch( newMode )
{
case 0:
break;
case 1:
break;
case 2:
break;
default:
cout << "Invalid selection." << endl;
break;
}
}
cout << "All output registers can be queried with a single function call." << endl
<< endl
<< "From the LSB to the MSB a '1' in this result indicates, that this output is currently switched to 'high' or 'active' state" << endl
<< endl
<< "E.g. 0x22 indicates that outputs 1 and 5 (zero-based) are currently in 'high' state." << endl;
const unsigned int fullOutputMask = bitMask( outputCount );
boRun = true;
while( boRun )
{
cout << "Calling 'readOutputRegister' returned ";
cout << endl;
cout << "Please enter 'y' followed by [ENTER] to modify all digital outputs with a single function" << endl
<< "call or anything else followed by [ENTER] to continue." << endl;
if( getStringFromCIN() != "y" )
{
boRun = false;
continue;
}
cout << "Please enter the bitmask in hex that contains the new values for the digital outputs followed by [ENTER]: ";
unsigned int value = static_cast<unsigned int>( getHEXFromCIN() );
if( value & ~fullOutputMask )
{
value &= fullOutputMask;
cout << "WARNING: More bits than outputs specified. Bitmask truncated to ";
hexToCOUT( value );
cout << endl;
}
cout << "Please enter the bitmask in hex that contains '1's for outputs that shall be affected by this operation followed by [ENTER]: ";
const unsigned int mask = static_cast<unsigned int>( getHEXFromCIN() );
if( readOnlyAccessMask & mask )
{
cout << "WARNING: At least one selected output is not manually switchable: Mask: ";
hexToCOUT( mask );
cout << ", read-only access mask: ";
hexToCOUT( readOnlyAccessMask );
cout << endl;
cout << "No digital outputs have been modified." << endl
<< endl;
continue;
}
}
}
cout << "This device also has" << endl;
cout <<
" " << ioss.
RTCtrProgramCount() <<
" hardware real-time controller(s)." << endl
<< endl;
{
cout << "How to program the HRTC (Hardware RealTime Controller) is not part of this sample, but the manual will contain a separate chapter on this topic.";
}
<< endl;
}
void mvGenICamIOAccess(
Device* pDev )
{
try
{
const unsigned int IOCount = dioc.lineSelector.dictSize();
bool boRun = true;
while( boRun )
{
cout << endl;
cout << " This device has " << IOCount << " DigitalIOs" << endl;
cout << " ------------------------------------------" << endl;
vector<int64_type> validLineSelectorValues;
dioc.lineSelector.getTranslationDictValues( validLineSelectorValues );
const vector<int64_type>::size_type cnt = validLineSelectorValues.size();
for( vector<int64_type>::size_type i = 0; i < cnt; i++ )
{
dioc.lineSelector.write( validLineSelectorValues[i] );
cout << " IO " << validLineSelectorValues[i] << ": \t Type: " << dioc.lineMode.readS() << " \t Current state: " << ( dioc.lineStatus.read() ? "ON" : "OFF" ) << endl;
}
cout << " ------------------------------------------" << endl;
cout << endl;
cout << "Please enter a valid line number followed by [ENTER]:" << endl;
cout << "- if it is an output its value will be inverted" << endl;
cout << "- if it is an input its value will be polled continuously for 10 seconds" << endl;
cout << "- or enter 'c' followed by [ENTER] to continue:" << endl;
const string cmd( getStringFromCIN() );
if( cmd == "c" )
{
boRun = false;
continue;
}
const unsigned int index = static_cast<unsigned int>( atoi( cmd.c_str() ) );
if( ( index >= IOCount ) || !isdigit( cmd[0] ) )
{
cout << "Invalid selection" << endl;
continue;
}
dioc.lineSelector.write( index );
if( dioc.lineMode.readS() == "Output" )
{
dioc.lineInverter.write( dioc.lineInverter.read() ?
bFalse :
bTrue );
}
else if( dioc.lineMode.readS() == "Input" )
{
cout << endl
<< endl;
cout << " ------------------------------------------" << endl;
cout << " Polling Input '" << dioc.lineSelector.readS() << "'" << endl;
cout << " ------------------------------------------" << endl;
cout << endl;
for( int i = 0; i < 100; i++ )
{
cout << "\r Value:" << ( dioc.lineStatus.read() ? "ON" : "OFF" );
#ifdef _WIN32
Sleep( 100 );
#else
usleep( 1000 * 100 );
#endif
cout << "\t Remaining Time:"
<< fixed << setprecision( 1 )
<< ( 10. - ( static_cast<double>( i + 1 ) / 10. ) );
cout.flush();
}
cout << endl
<< endl;
}
else
{
cout << "IO " << index << " is a '" << dioc.lineMode.readS() << "'!" << endl;
}
}
}
{
cout << endl;
cout << endl;
}
}
void mvBlueFOXIOAccess(
Device* pDev )
{
displayCommonIOFeatures( ioss );
if( ioss.digitalInputThreshold.isValid() )
{
cout << "This device also supports the '" << ioss.digitalInputThreshold.name() << "' property." << endl;
displayPropertyData( ioss.digitalInputThreshold );
}
cout << "To use a digital output in 'expose active' mode, the property '" << cs.flashMode.name() << "' can be used." << endl
<< "If a delay between switching the output and starting the frame exposure is needed, this can be achieved by " << endl
<< "writing to the property '" << cs.flashToExposeDelay_us.name() << "'." << endl;
}
int main( void )
{
Device* pDev = getDeviceFromUserInput( devMgr );
if( !pDev )
{
cout << "Unable to continue! Press [ENTER] to end the application" << endl;
cin.get();
return 1;
}
{
mvGenICamIOAccess( pDev );
}
{
mvBlueFOXIOAccess( pDev );
}
else
{
cout <<
"Device " << pDev->
serial.
read() <<
"(" << pDev->
product <<
") is not supported by this sample" << endl;
cout << "Press [ENTER] to end the application" << endl;
cin.get();
return 1;
}
cout << "Press [ENTER] to end the application" << endl;
cin.get();
return 0;
}
mvBlueFOX related camera settings(Device specific interface layout only).
Definition mvIMPACT_acquire.h:20035
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 product
A string property (read-only) containing the product name of this device.
Definition mvIMPACT_acquire.h:6537
PropertyS serial
A string property (read-only) containing the serial number of this device.
Definition mvIMPACT_acquire.h:6551
PropertyS family
A string property (read-only) containing the family name of this device.
Definition mvIMPACT_acquire.h:6526
PropertyIDeviceInterfaceLayout interfaceLayout
An enumerated integer property which can be used to define which interface layout shall be used when ...
Definition mvIMPACT_acquire.h:6644
A class to represent a digital output pin(Device specific interface layout only).
Definition mvIMPACT_acquire.h:15546
bool get(void) const
Returns the current state of this output pin.
Definition mvIMPACT_acquire.h:15571
void set(void)
Sets the output pin to 'logic 1'.
Definition mvIMPACT_acquire.h:15594
void reset(void)
Sets the output pin to 'logic 0'.
Definition mvIMPACT_acquire.h:15599
bool isWriteable(void) const
Checks if the caller has write/modify access to this digital output.
Definition mvIMPACT_acquire.h:15589
std::string getDescription(void) const
Returns a description for this digital output.
Definition mvIMPACT_acquire.h:15609
bool flip(void)
Inverts the current state of the digital output and returns the previous state.
Definition mvIMPACT_acquire.h:15559
ZYX read(int index=0) const
Reads a value from a property.
Definition mvIMPACT_acquire.h:4300
Category that contains the digital input and output control features.
Definition mvIMPACT_acquire_GenICam.h:3917
A class to handle the digital inputs and outputs for mvBlueFOX USB cameras(Device specific interface ...
Definition mvIMPACT_acquire.h:16787
A base class to handle digital inputs and outputs(Device specific interface layout only).
Definition mvIMPACT_acquire.h:16385
unsigned int getInputCount(void) const
Returns the number of mvIMPACT::acquire::DigitalInput s available for the mvIMPACT::acquire::Device a...
Definition mvIMPACT_acquire.h:16569
unsigned int getPulseStartConfigurationCount(void) const
Returns the number of mvIMPACT::acquire::PulseStartConfiguration objects available for the mvIMPACT::...
Definition mvIMPACT_acquire.h:16546
virtual void writeOutputRegister(unsigned int value, unsigned int mask=UINT_MAX)=0
Alters the state of the digital output register.
DigitalOutput * output(unsigned int nr) const
Returns a pointer to a mvIMPACT::acquire::DigitalOutput object.
Definition mvIMPACT_acquire.h:16615
unsigned int RTCtrProgramCount(void) const
Returns the number of mvIMPACT::acquire::RTCtrProgram s available for the mvIMPACT::acquire::Device a...
Definition mvIMPACT_acquire.h:16564
const DigitalInput * input(unsigned int nr) const
Returns a const pointer to a mvIMPACT::acquire::DigitalInput object.
Definition mvIMPACT_acquire.h:16597
unsigned int getOutputCount(void) const
Returns the number of digital outputs available for the mvIMPACT::acquire::Device associated with thi...
Definition mvIMPACT_acquire.h:16622
virtual unsigned int readOutputRegister(void) const =0
Returns the current state of the digital output register.
virtual unsigned int readInputRegister(void) const =0
Returns the current state of the digital input register.
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
A class to represent a sync. output pin(Device specific interface layout only).
Definition mvIMPACT_acquire.h:15629
PropertyF lowPart_pc
A float property defining the width in percent the sync. signal stays low during one period....
Definition mvIMPACT_acquire.h:15644
PropertyF frequency_Hz
A float property defining the frequency(in Hertz) for the sync. signal generated by this pin.
Definition mvIMPACT_acquire.h:15642
@ bFalse
Off, false or logical low.
Definition mvDriverBaseEnums.h:589
@ bTrue
On, true or logical high.
Definition mvDriverBaseEnums.h:591
This namespace contains classes and functions belonging to the GenICam specific part of the image acq...
Definition mvIMPACT_acquire.h:23830
This namespace contains classes and functions belonging to the image acquisition module of this SDK.
Definition mvCommonDataTypes.h:34