Example #1
0
void Source::GetAcquisitionMode( bool aSelectSourceIfNeeded, QString &aAcquisitionMode )
{
	aAcquisitionMode = "";

	PvGenStateStack lState( mDevice->GetGenParameters() );
	if ( mMultiSource )
	{
		PvInt64 lCurrentSource = 0;
		mDevice->GetGenParameters()->GetEnumValue( "SourceSelector", lCurrentSource );

		if ( lCurrentSource != mSourceIndex )
		{
			if ( aSelectSourceIfNeeded )
			{
				// Push change on stack, will be reset when lState goes out of scope
				lState.SetEnumValue( "SourceSelector", mSourceIndex );
			}
			else
			{
				return;
			}
		}
	}

	PvGenEnum *lMode = mDevice->GetGenParameters()->GetEnum( "AcquisitionMode" );
	if ( lMode != NULL )
	{
		PvString lValue;
		lMode->GetValue( lValue );

		aAcquisitionMode = lValue.GetAscii();
	}
}
Example #2
0
void Source::GetAcquisitionModes( std::vector<QString> &aVector )
{
	aVector.clear();

	PvGenStateStack lState( mDevice->GetGenParameters() );
	if ( mMultiSource )
	{
		// Push change on stack, will be reset when lState goes out of scope
		lState.SetEnumValue( "SourceSelector", mSourceIndex );
	}

	PvGenEnum *lMode = mDevice->GetGenParameters()->GetEnum( "AcquisitionMode" );
	if ( lMode != NULL )
	{
		PvInt64 lCount;
		lMode->GetEntriesCount( lCount );

		for ( PvInt64 i = 0; i < lCount; i++ )
		{
			const PvGenEnumEntry *lEE = NULL;
			lMode->GetEntryByIndex( i, &lEE );
			if ( ( lEE != NULL ) && lEE->IsAvailable() )
			{
				PvString lName;
				lEE->GetName( lName );

				aVector.push_back( lName.GetAscii() );
			}
		}
	}
}
Example #3
0
PvResult Source::Close()
{
	// Stop image reception
	PvResult lResult = StopStreaming();
	if ( !lResult.IsOK() )
	{
		return lResult;
	}

	// Close stream
	if ( mStream->IsOpen() )
	{
		lResult = mStream->Close();
		if ( !lResult.IsOK() )
		{
			return lResult;
		}
	}

	if ( ( mDevice != NULL ) && mDevice->IsConnected() )
	{
		// Unregister acquisition mode update notifications
		PvGenEnum *lMode = mDevice->GetGenParameters()->GetEnum( "AcquisitionMode" );
		if ( lMode != NULL )
		{
			lMode->UnregisterEventSink( this );
		}
	}

	// We don't own the device, let's just forget about it
	mDevice = NULL;

	return PvResult::Code::OK;
}
Example #4
0
PvUInt32 Source::GetPayloadSize()
{
	PvGenStateStack lState( mDevice->GetGenParameters() );
	if ( mMultiSource )
	{
		// Push change on stack, will be reset when lState goes out of scope
		lState.SetEnumValue( "SourceSelector", mSourceIndex );
	}

	// Get parameters required
	PvGenInteger *lPayloadSize = mDevice->GetGenParameters()->GetInteger("PayloadSize" );
	PvGenInteger *lWidth = mDevice->GetGenParameters()->GetInteger( "Width" );
	PvGenInteger *lHeight = mDevice->GetGenParameters()->GetInteger( "Height" );
	PvGenEnum *lPixelFormat = mDevice->GetGenParameters()->GetEnum( "PixelFormat" );

	// Try getting the payload size from the PayloadSize mandatory parameter
	PvInt64 lPayloadSizeValue = 0;
	if ( lPayloadSize != NULL )
	{
		lPayloadSize->GetValue( lPayloadSizeValue );

        // Round up to make it mod 32 (works around an issue with some devices)
        if ((lPayloadSizeValue % 32) != 0)
        {
            lPayloadSizeValue = ((lPayloadSizeValue / 32) + 1) * 32;
        }
    }
	
	// Compute poor man's payload size - for devices not maintaining PayloadSize properly
	PvInt64 lPoorMansPayloadSize = 0;
	if ( (lWidth != NULL ) && ( lHeight != NULL ) && ( lPixelFormat != NULL ) )
	{
		PvInt64 lWidthValue, lHeightValue;
		lWidth->GetValue( lWidthValue );
		lHeight->GetValue( lHeightValue );

		PvInt64 lPixelFormatValue;
		lPixelFormat->GetValue( lPixelFormatValue );

		PvInt64 lPixelSizeInBits = PvImage::GetPixelSize( (PvPixelType)lPixelFormatValue );

		lPoorMansPayloadSize = ( lWidthValue * lHeightValue * lPixelSizeInBits) / 8;
	}

	// Take max, let pipeline know what the payload size is
	PvInt64 lBestPayloadSize = ( lPayloadSizeValue >= lPoorMansPayloadSize ) ? lPayloadSizeValue : lPoorMansPayloadSize;
	if ( ( lBestPayloadSize > 0 ) && ( lBestPayloadSize < ULONG_MAX ) )
	{
		return static_cast<PvUInt32>( lBestPayloadSize );
	}

	// Could not compute/retrieve payload size...
	return 0;
}
Example #5
0
void PvDualSourceSample::Connect( PvDeviceInfo *aDeviceInfo )
{
    // Just in case we came here still connected...
    Disconnect();

    // Connect to device using device info
    PvResult lResult = mDevice.Connect( aDeviceInfo );
    if ( !lResult.IsOK() )
    {
        PvMessageBox( this, lResult );
        return;
    }

    Source *lSources[ 2 ] = { mSource1, mSource2 };

    // Open channels
    PvGenEnum *lSourceSelector = mDevice.GetGenParameters()->GetEnum( "SourceSelector" );
    PvGenInteger *lSourceStreamChannel = mDevice.GetGenParameters()->GetInteger( "SourceStreamChannel" );
    if ( lSourceSelector != NULL )
    {
        for ( PvUInt16 i = 0; i < 2; i++ )
        {
            QString lValue;
            lValue.sprintf( "Source%d", i + 1 );

            lSourceSelector->SetValue( lValue.toAscii().data() );

            PvInt64 lChannel = 0;
            lSourceStreamChannel->GetValue( lChannel );

            lResult = lSources[i]->Open( &mDevice, aDeviceInfo->GetIPAddress(), static_cast<PvUInt16>( lChannel ) );
            if ( !lResult.IsOK() )
            {
                PvMessageBox( this, lResult );
                return;
            }
        }
    }
    else
    {
        // No source selector, if transmitter assume 1 on channel 0
        lResult = mSource1->Open( &mDevice, aDeviceInfo->GetIPAddress(), 0 );
        if ( !lResult.IsOK() )
        {
            PvMessageBox( this, lResult );
            return;
        }
    }

    // Sync the UI with our new status
    EnableInterface();
}
Example #6
0
PvResult Source::Open( PvDevice *aDevice, const PvString &aIPAddress, const PvString &aLocalIPAddress, PvUInt16 aChannel )
{
	// The device should already be connected
	mDevice = aDevice;

    // Is the device multisource?
	PvGenEnum *lSourceSelector = dynamic_cast<PvGenEnum *>( mDevice->GetGenParameters()->Get( "SourceSelector" ) );
	if ( lSourceSelector != NULL )
	{
		PvInt64 lCount;
		lSourceSelector->GetEntriesCount( lCount );

		mMultiSource = ( lCount > 1 );
	}

	// Register acquisition mode update notifications
	PvGenEnum *lMode = mDevice->GetGenParameters()->GetEnum( "AcquisitionMode" );
	if ( lMode != NULL )
	{
		lMode->RegisterEventSink( this );
	}

	// Open stream
	PvResult lResult = mStream->Open( aIPAddress, 0, aChannel, aLocalIPAddress );
	if ( !lResult.IsOK() )
	{
		return lResult;
	}

	// Negotiate packet size. On failure, assume the device is set to a valid packet size.
	mDevice->NegotiatePacketSize( aChannel, 1476 );

	// Set stream destination
	lResult = mDevice->SetStreamDestination( mStream->GetLocalIPAddress(), mStream->GetLocalPort(), aChannel );
	if ( !lResult.IsOK() )
	{
		return lResult;
	}

    QCoreApplication::sendEvent( mWidget, new QEvent( static_cast<QEvent::Type>( WM_UPDATEACQMODES ) ) );

    // Ready image reception
	lResult = StartStreaming();
	if ( !lResult.IsOK() )
	{
		return lResult;
	}

	return PvResult::Code::OK;
}
Example #7
0
PvResult Source::SetAcquisitionMode( const QString &aAcquisitionMode )
{
	PvGenStateStack lState( mDevice->GetGenParameters() );
	if ( mMultiSource )
	{
		// Push change on stack, will be reset when lState goes out of scope
		lState.SetEnumValue( "SourceSelector", mSourceIndex );
	}

	PvGenEnum *lMode = mDevice->GetGenParameters()->GetEnum( "AcquisitionMode" );
	if ( lMode != NULL )
	{
		PvResult lResult = lMode->SetValue( aAcquisitionMode.toAscii().data() );
	    if ( !lResult.IsOK() )
	    {
	    	return lResult;
	    }
	}

	return PvResult::Code::OK;
}
Example #8
0
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;
}