Streaming strange behavior

Post your C and C++ discussions here
Post Reply
Cview
Newbie
Posts: 0
Joined: Wed Jul 21, 2010 12:20 pm

Streaming strange behavior

Post by Cview »

Hi !

First of all I'd like to warmly thanks PicoTech for providing such an awesome device.
The 4424 has became my daily companion for more than two years.

I've developed my own streaming application that work pretty well when streaming lasts at least 20 seconds.
When I ask for streaming for 10 sec I get either an unusually very long delay or a an infinite loop.

Help would be much appreciated,

Regards,

Olivier


Here is the code :

Code: Select all

    // Setup Data channel A range and coupling.
    CurrentStatus = ps4000SetChannel( Handle, PS4000_CHANNEL_A, true , true, (PS4000_RANGE)VoltageRange  );                       // Channel A activated, DC coupling.
    if( CurrentStatus != PICO_OK )
     {  CurrentStatus = ps4000CloseUnit( Handle );
        wxEndBusyCursor();
        wxMessageBox( "Can't set channel A.\n\nExiting.", "PicoScope error", wxOK |wxICON_ERROR );
        return( -1 );
     }
    // Channel A data buffer.
    CurrentStatus = ps4000SetDataBuffer( Handle, PS4000_CHANNEL_A, GLOBAL_CurveData[ CurrentCurveIndex ], SampleNumber );
    if( CurrentStatus != PICO_OK )
     {  CurrentStatus = ps4000CloseUnit( Handle );
        wxEndBusyCursor();
        wxMessageBox( wxString("Error allocating Channel A buffer :") << PicoGetErrorText( CurrentStatus ) << "\n\nExiting.", "PicoScope error", wxOK | wxICON_ERROR );
        return( -1 );
     }


    if( FileRibbon_PicoVoltageRange2_Choice->GetSelection() >= 2  )
      {
            // >> Channel B << .
            CurrentStatus = ps4000SetChannel( Handle, PS4000_CHANNEL_B, true, true, (PS4000_RANGE)GLOBAL_CurvePicoVoltageRange[ CurrentCurveIndex +1]  );
            if( CurrentStatus != PICO_OK )
             {  CurrentStatus = ps4000CloseUnit( Handle );
                wxEndBusyCursor();
                wxMessageBox( "Can't set channel B.\n\nExiting.", "PicoScope error", wxOK | wxICON_ERROR );
                return( -1 );
            }
            // Channel B data buffer.
            CurrentStatus = ps4000SetDataBuffer( Handle, PS4000_CHANNEL_B, GLOBAL_CurveData[ CurrentCurveIndex +1], SampleNumber );
            if( CurrentStatus != PICO_OK )
             {  CurrentStatus = ps4000CloseUnit( Handle );
                wxEndBusyCursor();
                wxMessageBox( wxString("Error allocating Channel B buffer :") << PicoGetErrorText( CurrentStatus ) << "\n\nExiting.", "PicoScope error", wxOK | wxICON_ERROR );
                return( -1 );
             }
      }
     else
      {
            // >> Channel B  << is OFF.
            CurrentStatus = ps4000SetChannel( Handle, PS4000_CHANNEL_B, false, true, PS4000_1V );
            if( CurrentStatus != PICO_OK )
               {  CurrentStatus = ps4000CloseUnit( Handle );
                    wxEndBusyCursor();
                    wxMessageBox( "Can't set channel B.\n\nExiting.", "PicoScope error", wxOK | wxICON_ERROR );
                    return( -1 );
                }
        }



    // >> Channel C << is OFF.
    CurrentStatus = ps4000SetChannel( Handle, PS4000_CHANNEL_C, false, true, PS4000_1V );
    if( CurrentStatus != PICO_OK )
     {  CurrentStatus = ps4000CloseUnit( Handle );
        wxEndBusyCursor();
        wxMessageBox( "Can't set channel C.\n\nExiting.", "PicoScope error", wxOK | wxICON_ERROR );
        return( -1 );
    }
    // >> Channel D << is OFF.
    CurrentStatus = ps4000SetChannel( Handle, PS4000_CHANNEL_D, false, true, PS4000_1V );
    if( CurrentStatus != PICO_OK )
     {  CurrentStatus = ps4000CloseUnit( Handle );
        wxEndBusyCursor();
        wxMessageBox( "Can't set channel D.\n\nExiting.", "PicoScope error", wxOK | wxICON_ERROR );
         return( -1 );
     }



    // Trigger  set to 'OFF'.
    if( ps4000SetSimpleTrigger( Handle, 0, PS4000_CHANNEL_A, 0, ABOVE, 0, 1) != PICO_OK )
     {  CurrentStatus = ps4000CloseUnit( Handle );
        wxEndBusyCursor();
        wxMessageBox( "Can't set Trigger.\n\nExiting.", "PicoScope error", wxOK | wxICON_ERROR );
        return( -1 );
     }


    // Run streaming.
    CurrentStatus = ps4000RunStreaming( Handle, &SamplingPeriod, (PS4000_TIME_UNITS) (GLOBAL_CurvePicoSamplingPeriodUnit[ CurrentCurveIndex ]), 0, SampleNumber, true, 1, SampleNumber );

    if( CurrentStatus != PICO_OK )
     {  CurrentStatus = ps4000CloseUnit( Handle );
        wxEndBusyCursor();
        wxMessageBox( wxString("Error running streaming: ") << PicoGetErrorText( CurrentStatus ) << "\n\nExiting.", "PicoScope error", wxOK | wxICON_ERROR );
        return( -1 );
    }


    // Streaming loop.
    Pico_AutoStop_Flag = false;
    Sleep(100);
    while( Pico_AutoStop_Flag == false )
     {  Sleep(100);
        // Poll until data is received. Until then, GetStreamingLatestValues wont call the callback.
        Pico_StreamingDataReady_Flag = false;
        CurrentStatus = ps4000GetStreamingLatestValues( Handle, (ps4000StreamingReady)BcoagFrame::PicoStreamingCallBack, NULL );
     }


    // Close PicoScope.
    ps4000Stop( Handle );
    ps4000CloseUnit( Handle );

Martyn
Site Admin
Site Admin
Posts: 4491
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Streaming strange behavior

Post by Martyn »

We would need to see your Callback function, PicoStreamingCallBack, and the values you are passing to ps4000RunStreaming when it works and when it doesn't.
Martyn
Technical Support Manager

Post Reply