MLTCam::MLTCam() { data = new ushort[IMAGE_WIDTH*IMAGE_HEIGHT]; PvDeviceFinderWnd lFinderWnd; if (! lFinderWnd.ShowModal().IsOK() ) { return; } lDeviceInfo = (PvDeviceInfo*)lFinderWnd.GetSelected(); PvResult lResult; if( lDeviceInfo != NULL ) { qDebug() << "MLTCam::Connecting to" << lDeviceInfo->GetManufacturerInfo().GetAscii(); lDevice = PvDevice::CreateAndConnect(lDeviceInfo, &lResult ); if ( lResult.IsOK() ) { qDebug() << "MLTCam::Connected"; } } else { qDebug() << "MLTCam::No device found"; } lResult = lDevice->GetParameters()->GetIntegerValue("Height",height); if ( height != 2944) InitializationCam(); lStream = OpenStream( lDeviceInfo); qDebug() << "MLTCam::OpenStream"; ConfigureStream( lDevice, lStream ); qDebug() << "MLTCam::ConfigureStream"; CreateStreamBuffers( lDevice, lStream, &lBufferList ); qDebug() << "MLTCam::CreateStreamBuffers"; }
bool SelectDevice( PvString &aIP ) { // Create a GEV Device finder dialog PvDeviceFinderWnd lDeviceFinderWnd; // Prompt the user to select a GEV Device lDeviceFinderWnd.ShowModal(); // Get the connectivity information for the selected GEV Device PvDeviceInfo* lDeviceInfo = lDeviceFinderWnd.GetSelected(); // If no device is selected, abort if( lDeviceInfo == NULL ) { printf( "No device selected.\n" ); return false; } aIP = lDeviceInfo->GetIPAddress(); return true; }
void PvDualSourceSample::OnConnectionConnectAction() { // create a device finder wnd and open the select device dialog PvDeviceFinderWnd lWnd; lWnd.SetTitle( "GEV Device Selection" ); // Show device finder if ( ( !lWnd.ShowModal().IsOK() ) || ( lWnd.GetSelected() == NULL ) ) { return; } // Show hourglass QCursor lOldCursor = cursor(); setCursor( Qt::WaitCursor ); QCoreApplication::processEvents(); // Connect to device Connect( lWnd.GetSelected() ); // Restore cursor setCursor( lOldCursor ); }
int main( int aCount, const char ** aArgs ) { char lDeviceAddress[1024]; char lMulticastAddress[1024]; char lLocalAddress[1024]; memset( lLocalAddress, 0, 1024 ); sprintf( lMulticastAddress, "239.192.1.1" ); memset( lDeviceAddress, 0, 1024 ); bool lPassive = true; PvUInt32 lChannel = 0; PvUInt16 lHostPort = 1042; PvResult lResult; for ( int i=1; i<aCount; i++ ) { std::string lString = aArgs[i]; if ( lString.find( "--hostport" ) != std::string::npos ) { sscanf( aArgs[i], "--hostport=%d", &lHostPort ); } else if ( lString.find( "--localaddress" ) != std::string::npos ) { sscanf( aArgs[i], "--localaddress=%s", lLocalAddress ); } else if ( lString.find( "--multicastaddress" ) != std::string::npos ) { sscanf( aArgs[i], "--multicastaddress=%s", lMulticastAddress ); } else if ( lString.find( "--deviceaddress" ) != std::string::npos ) { sscanf( aArgs[i], "--deviceaddress=%s", lDeviceAddress ); } else if ( lString.find( "--unicast" ) != std::string::npos ) { memset( lMulticastAddress, 0, 1024 ); } else if ( lString.find( "--connectdevice" ) != std::string::npos ) { lPassive = false; } else if ( lString.find( "--channel" ) != std::string::npos ) { sscanf( aArgs[i], "--channel=%d", &lChannel ); } else if ( lString.find( "--help" ) != std::string::npos ) { PrintHelp(); return 0; } else { printf( "Did not recognize argument %s\n", aArgs[i] ); PrintHelp(); return 1; } } if ( strlen( lDeviceAddress ) == 0 ) { // No device address specified. Prompt with the device finder. PvDeviceFinderWnd lWnd; if ( !lWnd.ShowModal().IsOK() ) { printf( "No GEV device selected.\n" ); return 1; } PvDeviceInfo* lInfo = lWnd.GetSelected(); sprintf( lDeviceAddress, "%s", lInfo->GetIPAddress().GetAscii() ); } PvStream lStream; if ( strlen( lMulticastAddress ) == 0 ) { lResult = lStream.Open( lDeviceAddress, lHostPort, lChannel, lLocalAddress ); printf( "Receiving from device %s on interface %s:%d\n", lDeviceAddress, lStream.GetLocalIPAddress().GetAscii(), lStream.GetLocalPort() ); } else { lResult = lStream.Open( lDeviceAddress, lMulticastAddress, lHostPort, lChannel, lLocalAddress ); printf( "Receiving from multicast address %s:%d (device %s) on interface %s:%d\n", lMulticastAddress, lHostPort, lDeviceAddress, lStream.GetLocalIPAddress().GetAscii(), lStream.GetLocalPort() ); } if ( !lResult.IsOK() ) { printf( "Failed opening the incoming stream: %s\n", lResult.GetDescription().GetAscii() ); return 1; } PvPipeline lPipeline( &lStream ); PvDevice lDevice; PvGenParameterArray *lDeviceParams = NULL; if ( !lPassive ) { lResult = lDevice.Connect( lDeviceAddress ); if ( !lResult.IsOK() ) { printf( "Failed connecting to the device to set its destination and initiate an AcquisitionStart: %s\n", lResult.GetDescription().GetAscii() ); printf( "If the eBUS Transmitter to receive from doesn't have full device capabilities, add the --passive command line option and initiate streaming manually.\n" ); return 1; } lDevice.SetStreamDestination( lStream.GetLocalIPAddress(), lStream.GetLocalPort(), lChannel ); // Get device parameters need to control streaming lDeviceParams = lDevice.GetGenParameters(); // Reading payload size from device. Otherwise, the pipeline may miss the first several images. PvInt64 lReceivePayloadSize = 0; lDeviceParams->GetIntegerValue( "PayloadSize", lReceivePayloadSize ); // Set the Buffer size and the Buffer count lPipeline.SetBufferSize( static_cast<PvUInt32>( lReceivePayloadSize ) ); } lPipeline.SetBufferCount( 16 ); // Increase for high frame rate without missing block IDs lPipeline.Start(); if ( !lPassive ) { // TLParamsLocked is optional but when present, it MUST be set to 1 // before sending the AcquisitionStart command lDeviceParams->SetIntegerValue( "TLParamsLocked", 1 ); lDeviceParams->ExecuteCommand( "GevTimestampControlReset" ); // The pipeline is already "armed", we just have to tell the device // to start sending us images lDeviceParams->ExecuteCommand( "AcquisitionStart" ); } // Get stream parameters/stats PvGenParameterArray *lStreamParams = lStream.GetParameters(); printf( "Press any key to stop receiving. \n" ); char lDoodle[] = "|\\-|-/"; int lDoodleIndex = 0; PvInt64 lImageCountVal = 0; double lFrameRateVal = 0.0; double lBandwidthVal = 0.0; while ( !PvKbHit() ) { PvBuffer *lBuffer = NULL; PvResult lOperationResult; PvResult lResult = lPipeline.RetrieveNextBuffer( &lBuffer, 1000, &lOperationResult ); if ( lResult.IsOK() ) { if ( lOperationResult.IsOK() ) { // // We now have a valid buffer. This is where you would typically process the buffer. // ----------------------------------------------------------------------------------------- // ... lStreamParams->GetIntegerValue( "ImagesCount", lImageCountVal ); lStreamParams->GetFloatValue( "AcquisitionRateAverage", lFrameRateVal ); lStreamParams->GetFloatValue( "BandwidthAverage", lBandwidthVal ); printf( "%c BlockID: %016llX %.01f FPS %.01f Mb/s\r", lDoodle[ lDoodleIndex ], lBuffer->GetBlockID(), lFrameRateVal, lBandwidthVal / 1000000.0 ); } // We have an image - do some processing (...) and VERY IMPORTANT, // release the buffer back to the pipeline lPipeline.ReleaseBuffer( lBuffer ); } else { printf( "%c Timeout\r", lDoodle[ lDoodleIndex ] ); } ++lDoodleIndex %= 6; } }
bool AcquireImages() { // Create a GEV Device finder dialog PvDeviceFinderWnd lDeviceFinderWnd; // Prompt the user to select a GEV Device lDeviceFinderWnd.ShowModal(); // Get the connectivity information for the selected GEV Device PvDeviceInfo* lDeviceInfo = lDeviceFinderWnd.GetSelected(); // If no device is selected, abort if( lDeviceInfo == NULL ) { cout << "No device selected." << endl; return false; } PvString lMACAddress = lDeviceInfo->GetMACAddress(); PvString lIPAddress = lDeviceInfo->GetIPAddress(); // Connect to the GEV Device PvDevice lDevice; cout << "Connecting to " << lMACAddress.GetAscii() << endl; // if ( !lDevice.Connect( lDeviceInfo ).IsOK() ) if ( !lDevice.Connect( lDeviceInfo ).IsOK() ) { cout << "Unable to connect to " << lMACAddress.GetAscii() << endl; return false; } cout << "Successfully connected to " << lMACAddress.GetAscii() << endl; cout << endl; SourceList lSources; // Get source selector PvGenEnum *lSourceSelector = lDevice.GetGenParameters()->GetEnum( "SourceSelector" ); if ( lSourceSelector != NULL ) { // Go through all sources, create source objects PvInt64 lCount = 0; lSourceSelector->GetEntriesCount( lCount ); for ( PvInt64 i = 0; i < lCount; i++ ) { // Get source enum entry const PvGenEnumEntry *lEE = NULL; lSourceSelector->GetEntryByIndex( i, &lEE ); // If available, create source if ( ( lEE != NULL ) && lEE->IsAvailable() ) { // Get source name PvString lSourceName; lEE->GetName( lSourceName ); // Create source Source *lSource = new Source( &lDevice, lIPAddress, lSourceName ); lSource->Open(); // Add to sources list lSources.push_back( lSource ); cout << endl; } } } else { // If no source selector, just create a single source Source *lSource = new Source( &lDevice, lIPAddress, "" ); lSource->Open(); // Add to sources list lSources.push_back( lSource ); cout << endl; } // Start the acquisiton on all sources SourceList::iterator lIt = lSources.begin(); while ( lIt != lSources.end() ) { ( *( lIt++ ) )->StartAcquisition(); cout << endl; } // Aggressive initial value, will be adjusted vs frame rate PvUInt32 lTimeout = 1; // Acquire images until the user instructs us to stop cout << "<press a key to stop streaming>" << endl; while ( !PvKbHit() ) { double lNewTimeout = 1000.0; lIt = lSources.begin(); while ( lIt != lSources.end() ) { ( *lIt )->RetrieveImages( lTimeout ); ( *lIt )->PrintStatistics(); // Always use the smallest recommended timeout double lRecommendedTimeout = ( *lIt )->GetRecommendedTimeout(); if ( lRecommendedTimeout < lNewTimeout ) { lNewTimeout = lRecommendedTimeout; } lIt++; } // Update timeout for next round - smallest recommended divided by number of sources lTimeout = static_cast<PvUInt32>( lNewTimeout / static_cast<double>( lSources.size() ) + 0.5 ); cout << "\r"; } PvGetChar(); // Flush key buffer for next stop cout << endl << endl; // Stop the acquisiton on all sources lIt = lSources.begin(); while ( lIt != lSources.end() ) { ( *( lIt++ ) )->StopAcquisition(); cout << endl; } // Close and delete sources lIt = lSources.begin(); while ( lIt != lSources.end() ) { ( *lIt )->Close(); cout << endl; delete *lIt; lIt++; } // Finally disconnect the device. Optional, still nice to have cout << "Disconnecting device" << endl; lDevice.Disconnect(); return true; }