#if !defined(linux) && !defined(__linux) && !defined(__linux__) && !defined(__APPLE__)
# error Sorry! Code for Unix flavoured operating systems only!
#endif
#include <stdio.h>
#include <cstdlib>
#include <unistd.h>
#include <iostream>
#include <errno.h>
#include <apps/Common/exampleHelper.h>
#include <mvIMPACT_CPP/mvIMPACT_acquire.h>
using namespace std;
#define PRESS_A_KEY \
getchar();
class ThreadParameter
{
volatile bool m_boTerminateThread;
public:
ThreadParameter(
Device* pDev ) : m_pDev( pDev ), m_boTerminateThread(
false ) {}
{
return m_pDev;
}
bool terminated( void ) const
{
return m_boTerminateThread;
}
void terminateThread( void )
{
m_boTerminateThread = true;
}
};
static unsigned int thread_func( void* pData )
{
ThreadParameter* pThreadParameter = reinterpret_cast<ThreadParameter*>( pData );
unsigned int cnt = 0;
try
{
pThreadParameter->device()->open();
}
{
cout << "An error occurred while opening the device " << pThreadParameter->device()->serial.read()
<< "Press [ENTER] to end the application..."
<< endl;
PRESS_A_KEY
return 0;
}
Statistics statistics( pThreadParameter->device() );
const int REQUEST_COUNT = ss.requestCount.read();
for( int i = 0; i < REQUEST_COUNT; i++ )
{
result = fi.imageRequestSingle();
if( result != DMR_NO_ERROR )
{
cout << "Error while filling the request queue: " << ImpactAcquireException::getErrorCodeAsString( result ) << endl;
}
}
const unsigned int timeout_ms = 8000;
while( !pThreadParameter->terminated() )
{
requestNr = fi.imageRequestWaitFor( timeout_ms );
if( fi.isRequestNrValid( requestNr ) )
{
pRequest = fi.getRequest( requestNr );
{
++cnt;
if( cnt % 100 == 0 )
{
cout << "Info from " << pThreadParameter->device()->serial.read()
<< ": " << statistics.framesPerSecond.name() << ": " << statistics.framesPerSecond.readS()
<< ", " << statistics.errorCount.name() << ": " << statistics.errorCount.readS()
<< ", " << statistics.captureTime_s.name() << ": " << statistics.captureTime_s.readS() << endl;
}
}
else
{
}
if( fi.isRequestNrValid( lastRequestNr ) )
{
fi.imageRequestUnlock( lastRequestNr );
}
lastRequestNr = requestNr;
fi.imageRequestSingle();
}
else
{
cout << "imageRequestWaitFor failed (" << requestNr << ", " << ImpactAcquireException::getErrorCodeAsString( requestNr ) << ", device " << pThreadParameter->device()->serial.read() << ")"
<< ", timeout value too small?" << endl;
}
}
if( fi.isRequestNrValid( requestNr ) )
{
fi.imageRequestUnlock( requestNr );
}
fi.imageRequestReset( 0, 0 );
return 0;
}
static void* liveThread( void* pData )
{
thread_func( pData );
return NULL;
}
int main( void )
{
if( devCnt == 0 )
{
cout << "No " << PRODUCT_NAME << " compliant device found! Unable to continue!" << endl;
return 1;
}
pthread_t* pHandles = new pthread_t[devCnt];
pthread_attr_t* pAttrs = new pthread_attr_t[devCnt];
vector<ThreadParameter*> threadParams;
for( unsigned int i = 0; i < devCnt; i++ )
{
threadParams.push_back( new ThreadParameter( devMgr[i] ) );
cout << devMgr[i]->family.read() << "(" << devMgr[i]->serial.read() << ")" << endl;
}
for( unsigned int j = 0; j < devCnt; j++ )
{
pthread_attr_init( &pAttrs[j] );
pthread_create( &pHandles[j], &pAttrs[j], liveThread, ( void* )threadParams[j] );
}
cout << "Press return to end the acquisition( the initialisation of the devices might take some time )" << endl;
PRESS_A_KEY
cout << "Terminating live threads..." << endl;
size_t vSize = threadParams.size();
for( unsigned int k = 0; k < vSize; k++ )
{
cout << "Terminating thread " << k << "." << endl;
threadParams[k]->terminateThread();
}
for( unsigned int j = 0; j < devCnt; j++ )
{
cout << "Waiting for thread " << j << " to terminate." << endl;
pthread_join( pHandles[j], NULL );
}
cout << "All capture threads terminated." << endl;
for( unsigned int l = 0; l < vSize; l++ )
{
delete threadParams[l];
cout << "thread parameter " << l << " removed." << endl;
}
delete [] pHandles;
cout << "All thread handles removed." << endl;
delete [] pAttrs;
cout << "All thread atributes removed." << endl;
return 0;
}
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
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
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 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
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
Contains basic statistical information.
Definition mvIMPACT_acquire.h:14509
A base class for accessing settings that control the overall behaviour of a device driver.
Definition mvIMPACT_acquire.h:14728
const int INVALID_ID
A constant to check for an invalid ID returned from the property handling module.
Definition mvPropHandlingDatatypes.h:62
@ DMR_NO_ERROR
The function call was executed successfully.
Definition mvDriverBaseEnums.h:2603
This namespace contains classes and functions belonging to the image acquisition module of this SDK.
Definition mvCommonDataTypes.h:34