In the first step it is verified if the device is allows access to its I2C bus. Once the device allows access to the I2C bus, it will be configured.
const int i2cDeviceAddress = pDev->manufacturerSpecificInformation.read().find( ";SF3" ) != std::string::npos || pDev->manufacturerSpecificInformation.read().find( "-3M" ) != std::string::npos ? 0x32 : 0x30;
unique_ptr<GenICam::mvI2cInterfaceControl> pI2C;
try
{
pI2C = unique_ptr<GenICam::mvI2cInterfaceControl>( new GenICam::mvI2cInterfaceControl( pDev ) );
pI2C->mvI2cInterfaceEnable.write( bTrue );
pI2C->mvI2cInterfaceSpeed.writeS( "kHz_400" );
pI2C->mvI2cInterfaceDeviceAddress.write( i2cDeviceAddress );
pI2C->mvI2cInterfaceDeviceSubAddress.write( 0x08 );
pI2C->mvI2cInterfaceWrite.call();
pI2C->mvI2cInterfaceDeviceSubAddress.write( 0x08 );
const char writeBuf[1] = { 1 };
pI2C->mvI2cInterfaceBinaryBuffer.writeBinary( string( writeBuf, sizeof( writeBuf ) / sizeof( writeBuf[0] ) ) );
pI2C->mvI2cInterfaceBytesToWrite.write( 1 );
pI2C->mvI2cInterfaceWrite.call();
pI2C->mvI2cInterfaceDeviceSubAddress.write( 0x10801 );
pI2C->mvI2cInterfaceBytesToWrite.write( 0 );
pI2C->mvI2cInterfaceWrite.call();
}
catch( const ImpactAcquireException& e )
{
cout << "ERROR! I2C properties which are essential to run this sample are not available for the selected device (error code: " << e.getErrorCode() << "(" << e.getErrorCodeAsString() << ")), press [ENTER] to end the application..." << endl;
return 1;
}
Finally the measurement value of the temperature sensor is read out in a loop and printed to stdout.
double lastTemperatureDisplayed = {0.};
while( !s_boTerminated )
{
pI2C->mvI2cInterfaceDeviceSubAddress.write( 0x05 );
pI2C->mvI2cInterfaceBytesToRead.write( 0x02 );
pI2C->mvI2cInterfaceRead.call();
const string i2cReadBinaryData = pI2C->mvI2cInterfaceBinaryBuffer.readBinary();
const int temp = ( i2cReadBinaryData[0] * 256 ) + i2cReadBinaryData[1];
const double currentTemperature = static_cast<double>( ( ( temp << 3 ) & 0xffff ) ) / 128.;
if( currentTemperature != lastTemperatureDisplayed )
{
cout << "Mainboard Temperature: " << currentTemperature << "\370C" << endl;
lastTemperatureDisplayed = currentTemperature;
}
this_thread::sleep_for( chrono::milliseconds( 1000 ) );
}
#include <algorithm>
#include <apps/Common/exampleHelper.h>
#include <functional>
#include <memory>
#include <mvIMPACT_CPP/mvIMPACT_acquire_GenICam.h>
#include <thread>
using namespace std;
static bool s_boTerminated = false;
{
unique_ptr<GenICam::mvI2cInterfaceControl> pI2C;
try
{
pI2C->mvI2cInterfaceEnable.write( bTrue );
pI2C->mvI2cInterfaceSpeed.writeS( "kHz_400" );
pI2C->mvI2cInterfaceDeviceAddress.write( i2cDeviceAddress );
pI2C->mvI2cInterfaceDeviceSubAddress.write( 0x08 );
pI2C->mvI2cInterfaceWrite.call();
pI2C->mvI2cInterfaceDeviceSubAddress.write( 0x08 );
const char writeBuf[1] = { 1 };
pI2C->mvI2cInterfaceBinaryBuffer.writeBinary( string( writeBuf, sizeof( writeBuf ) / sizeof( writeBuf[0] ) ) );
pI2C->mvI2cInterfaceBytesToWrite.write( 1 );
pI2C->mvI2cInterfaceWrite.call();
pI2C->mvI2cInterfaceDeviceSubAddress.write( 0x10801 );
pI2C->mvI2cInterfaceBytesToWrite.write( 0 );
pI2C->mvI2cInterfaceWrite.call();
}
{
cout <<
"ERROR! I2C properties which are essential to run this sample are not available for the selected device (error code: " << e.
getErrorCode() <<
"(" << e.
getErrorCodeAsString() <<
")), press [ENTER] to end the application..." << endl;
return 1;
}
double lastTemperatureDisplayed = {0.};
while( !s_boTerminated )
{
pI2C->mvI2cInterfaceDeviceSubAddress.write( 0x05 );
pI2C->mvI2cInterfaceBytesToRead.write( 0x02 );
pI2C->mvI2cInterfaceRead.call();
const string i2cReadBinaryData = pI2C->mvI2cInterfaceBinaryBuffer.readBinary();
const int temp = ( i2cReadBinaryData[0] * 256 ) + i2cReadBinaryData[1];
const double currentTemperature = static_cast<double>( ( ( temp << 3 ) & 0xffff ) ) / 128.;
if( currentTemperature != lastTemperatureDisplayed )
{
cout << "Mainboard Temperature: " << currentTemperature << "\370C" << endl;
lastTemperatureDisplayed = currentTemperature;
}
this_thread::sleep_for( chrono::milliseconds( 1000 ) );
}
return 0;
}
bool isDeviceSupportedBySample(
const Device*
const pDev )
{
{
return false;
}
vector<TDeviceInterfaceLayout> availableInterfaceLayouts;
return find( availableInterfaceLayouts.begin(), availableInterfaceLayouts.end(), dilGenICam ) != availableInterfaceLayouts.end();
}
int main( void )
{
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
{
}
{
cout <<
"An error occurred while opening the device(error code: " << e.
getErrorCode() <<
")." << endl
<< "Press [ENTER] to end the application" << endl;
cin.get();
return 1;
}
cout << "Press [ENTER] to end the application" << endl;
s_boTerminated = false;
thread myThread( threadFn, pDev );
cin.get();
s_boTerminated = true;
myThread.join();
return 0;
}
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 manufacturerSpecificInformation
A string property (read-only) containing manufacturer specific information of this device.
Definition mvIMPACT_acquire.h:6822
void open(void)
Opens a device.
Definition mvIMPACT_acquire.h:6420
PropertyIDeviceInterfaceLayout interfaceLayout
An enumerated integer property which can be used to define which interface layout shall be used when ...
Definition mvIMPACT_acquire.h:6644
PropertyIAcquisitionStartStopBehaviour acquisitionStartStopBehaviour
An enumerated integer property defining the start/stop behaviour during acquisition of this driver in...
Definition mvIMPACT_acquire.h:6800
const EnumPropertyI & getTranslationDictValues(std::vector< ZYX > &sequence) const
This function queries a list of valid values for this property.
Definition mvIMPACT_acquire.h:4266
Contains features to control the I2C interface.
Definition mvIMPACT_acquire_GenICam.h:15136
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
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
This namespace contains classes and functions belonging to the image acquisition module of this SDK.
Definition mvCommonDataTypes.h:34