PicoScope 7 Software
Available on Windows, Mac and Linux
Code: Select all
PICO_STATUS CurrentStatus;
int16_t Handle;
// Open PicoScope 4000.
CurrentStatus = ps4000OpenUnit( &Handle );
// Check retuned Pico Handle.
if( Handle == 0 )
{
wxEndBusyCursor();
wxMessageBox( wxString("Sorry,\nNo Picoscope found : ") << PicoGetErrorText( CurrentStatus ) << "\n\nExiting.", "PicoScope error", wxOK | wxICON_ERROR );
return( -1 );
}
if( Handle == -1 )
{
wxEndBusyCursor();
wxMessageBox( wxString("Sorry,\nFailed to open Picoscope : ") << PicoGetErrorText( CurrentStatus ) << "\n\nExiting.", "PicoScope error", wxOK | wxICON_ERROR );
return( -1 );
}
// Check returned Pico Status.
if( ( CurrentStatus != PICO_OK ) && ( CurrentStatus != PICO_EEPROM_CORRUPT ) )
{
wxEndBusyCursor();
wxMessageBox( wxString("Sorry,\n Bad Pico Status returned: ") << PicoGetErrorText( CurrentStatus ) << "\n\nExiting.", "PicoScope error", wxOK | wxICON_ERROR );
return( -1 );
}
// Free Pico Data buffers.
for( int i=0; i < PICO_CHANNELS_MAX_NB; i++)
if( GLOBAL_PicoSignal_Data[i] != NULL )
{
delete [] GLOBAL_PicoSignal_Data[i];
GLOBAL_PicoSignal_Data[i] = NULL;
}
// Compute sample number.
GLOBAL_PicoSignal_SampleNumber = uint32_t( float( RibbonPico_SamplingDuration_SpinCtrl->GetValue() ) / float( GLOBAL_PicoSignal_SamplingPeriod )* float( 1.0e9 ) );
// Select channels, range and coupling.
// >> Channel A <<
if( GLOBAL_PicoSignal_VoltageRange[0] != -1 )
{
// Memory alloc.
GLOBAL_PicoSignal_Data[0] = new int16_t[ GLOBAL_PicoSignal_SampleNumber ];
// Setup Data channel A.
CurrentStatus = ps4000SetChannel( Handle, PS4000_CHANNEL_A, int16_t( true ), int16_t( GLOBAL_PicoSignal_CouplingMode[0] ), (PS4000_RANGE)GLOBAL_PicoSignal_VoltageRange[0] ); // Channel A activated, DC coupling, +/-5V range.
if( CurrentStatus != PICO_OK )
{
CurrentStatus = ps4000CloseUnit( Handle );
wxEndBusyCursor();
wxMessageBox( "Can't set channel A.\n\nExiting.", "PicoScope error", wxOK |wxICON_ERROR );
return( -1 );
}
CurrentStatus = ps4000SetDataBuffer( Handle, PS4000_CHANNEL_A, GLOBAL_PicoSignal_Data[0], GLOBAL_PicoSignal_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 );
}
}
else
CurrentStatus = ps4000SetChannel( Handle, PS4000_CHANNEL_A, int16_t( false ), GLOBAL_PicoSignal_CouplingMode[0], (PS4000_RANGE)GLOBAL_PicoSignal_VoltageRange[0] ); // Channel A activated, DC coupling, +/-5V range.
// >> Channel B <<
if( GLOBAL_PicoSignal_VoltageRange[1] != -1 )
{
// Memory alloc.
GLOBAL_PicoSignal_Data[1] = new int16_t[ GLOBAL_PicoSignal_SampleNumber ];
// Setup Data channel B.
CurrentStatus = ps4000SetChannel( Handle, PS4000_CHANNEL_B, int16_t( true ), int16_t( GLOBAL_PicoSignal_CouplingMode[1] ), (PS4000_RANGE)GLOBAL_PicoSignal_VoltageRange[1] ); // Channel B activated, DC coupling, +/-5V range.
if( CurrentStatus != PICO_OK )
{
CurrentStatus = ps4000CloseUnit( Handle );
wxEndBusyCursor();
wxMessageBox( "Can't set channel B.\n\nExiting.", "PicoScope error", wxOK | wxICON_ERROR );
return( -1 );
}
CurrentStatus = ps4000SetDataBuffer( Handle, PS4000_CHANNEL_B, GLOBAL_PicoSignal_Data[1], GLOBAL_PicoSignal_SampleNumber );
if( CurrentStatus != PICO_OK )
{
CurrentStatus = ps4000CloseUnit( Handle );
wxEndBusyCursor();
wxMessageBox( "Error allocating Channel B buffer.\n\nExiting.", "PicoScope error", wxOK | wxICON_ERROR );
return( -1 );
}
}
else
CurrentStatus = ps4000SetChannel( Handle, PS4000_CHANNEL_B, int16_t( false ), GLOBAL_PicoSignal_CouplingMode[1], (PS4000_RANGE)GLOBAL_PicoSignal_VoltageRange[1] ); // Channel A activated, DC coupling, +/-5V range.
// >> Channel C <<
if( GLOBAL_PicoSignal_VoltageRange[2] != -1 )
{
// Memory alloc.
GLOBAL_PicoSignal_Data[2] = new int16_t[ GLOBAL_PicoSignal_SampleNumber ];
// Setup Data channel C.
CurrentStatus = ps4000SetChannel( Handle, PS4000_CHANNEL_C, int16_t( true ), int16_t( GLOBAL_PicoSignal_CouplingMode[2] ), (PS4000_RANGE)GLOBAL_PicoSignal_VoltageRange[2] ); // Channel B activated, DC coupling, +/-5V range.
if( CurrentStatus != PICO_OK )
{
CurrentStatus = ps4000CloseUnit( Handle );
wxEndBusyCursor();
wxMessageBox( "Can't set channel C.\n\nExiting.", "PicoScope error", wxOK | wxICON_ERROR );
return( -1 );
}
CurrentStatus = ps4000SetDataBuffer( Handle, PS4000_CHANNEL_C, GLOBAL_PicoSignal_Data[2], GLOBAL_PicoSignal_SampleNumber );
if( CurrentStatus != PICO_OK )
{
CurrentStatus = ps4000CloseUnit( Handle );
wxEndBusyCursor();
wxMessageBox( "Error allocating Channel C buffer.\n\nExiting.", "PicoScope error", wxOK | wxICON_ERROR );
return( -1 );
}
}
else
CurrentStatus = ps4000SetChannel( Handle, PS4000_CHANNEL_C, int16_t( false ), GLOBAL_PicoSignal_CouplingMode[2], (PS4000_RANGE)GLOBAL_PicoSignal_VoltageRange[2] ); // Channel A activated, DC coupling, +/-5V range.
// >> Channel D <<
if( GLOBAL_PicoSignal_VoltageRange[3] != -1 )
{
// Memory alloc.
GLOBAL_PicoSignal_Data[3] = new int16_t[ GLOBAL_PicoSignal_SampleNumber ];
// Setup data channel D.
CurrentStatus = ps4000SetChannel( Handle, PS4000_CHANNEL_D, int16_t( true ), int16_t( GLOBAL_PicoSignal_CouplingMode[3] ), (PS4000_RANGE)GLOBAL_PicoSignal_VoltageRange[3] ); // Channel B activated, DC coupling, +/-5V range.
if( CurrentStatus != PICO_OK )
{
CurrentStatus = ps4000CloseUnit( Handle );
wxEndBusyCursor();
wxMessageBox( "Can't set channel D.\n\nExiting.", "PicoScope error", wxOK | wxICON_ERROR );
return( -1 );
}
CurrentStatus = ps4000SetDataBuffer( Handle, PS4000_CHANNEL_D, GLOBAL_PicoSignal_Data[3], GLOBAL_PicoSignal_SampleNumber );
if( CurrentStatus != PICO_OK )
{
CurrentStatus = ps4000CloseUnit( Handle );
wxEndBusyCursor();
wxMessageBox( "Error allocating Channel D buffer.\n\nExiting.", "PicoScope error", wxOK | wxICON_ERROR );
return( -1 );
}
}
else
CurrentStatus = ps4000SetChannel( Handle, PS4000_CHANNEL_D, int16_t( false ), GLOBAL_PicoSignal_CouplingMode[3], (PS4000_RANGE)GLOBAL_PicoSignal_VoltageRange[3] ); // Channel A activated, DC coupling, +/-5V range.
// >> Trigger << : *NO* trigger condition.
TRIGGER_CONDITIONS conditions;
conditions.channelA = CONDITION_DONT_CARE;
conditions.channelB = CONDITION_DONT_CARE;
conditions.channelC = CONDITION_DONT_CARE;
conditions.channelD = CONDITION_DONT_CARE;
conditions.aux = CONDITION_DONT_CARE;
conditions.pulseWidthQualifier = CONDITION_DONT_CARE;
TRIGGER_CHANNEL_PROPERTIES properties;
properties.thresholdLower = 0;
properties.thresholdUpper = 0;
properties.thresholdLowerHysteresis = 0;
properties.thresholdUpperHysteresis = 300;
properties.channel = PS4000_CHANNEL_A;
properties.thresholdMode = LEVEL;
if( ps4000SetTriggerChannelConditions( Handle, &conditions, 1) != PICO_OK )
{
CurrentStatus = ps4000CloseUnit( Handle );
wxEndBusyCursor();
wxMessageBox( "Can't set Trigger Conditions.\n\nExiting.", "PicoScope error", wxOK | wxICON_ERROR );
return( -1 );
}
if( ps4000SetTriggerChannelDirections(Handle, NONE, RISING, NONE, NONE, NONE, NONE) != PICO_OK)
{
CurrentStatus = ps4000CloseUnit( Handle );
wxEndBusyCursor();
wxMessageBox( "Can't set Trigger Direction.\n\nExiting.", "PicoScope error", wxOK | wxICON_ERROR );
return( -1 );
}
if( ps4000SetTriggerChannelProperties(Handle, &properties, 1, 0, 0) != PICO_OK)
{
CurrentStatus = ps4000CloseUnit( Handle );
wxEndBusyCursor();
wxMessageBox( "Can't set Trigger Properties.\n\nExiting.", "PicoScope error", wxOK | wxICON_ERROR );
return( -1 );
}
uint32_t UsedSamplingPeriod = GLOBAL_PicoSignal_SamplingPeriod;
int16_t Pico_AutoStop_Flag = false;
// Run streaming.
CurrentStatus = ps4000RunStreaming( Handle, &UsedSamplingPeriod, PS4000_NS, uint32_t(10), uint32_t( GLOBAL_PicoSignal_SampleNumber -10 ), int16_t( true ), uint32_t( 1 ), GLOBAL_PicoSignal_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 wait loop.
while( Pico_AutoStop_Flag == false )
{
// Poll until data is received. Until then, GetStreamingLatestValues wont call the callback.
Pico_StreamingDataReady_Flag = false;
CurrentStatus = ps4000GetStreamingLatestValues( Handle, (ps4000StreamingReady)MyApp::PicoStreamingCallBack, NULL );
}
// Close.
ps4000Stop( Handle );
ps4000CloseUnit( Handle );
/******************************************************************************/
void _stdcall MyApp::PicoStreamingCallBack( int16_t handle,
int32_t noOfSamples,
uint32_t startIndex,
int16_t overflow,
uint32_t triggerAt,
int16_t triggered,
int16_t autoStop,
void *pParameter )
{
Pico_AutoStop_Flag = autoStop;
// Set data ready flag.
Pico_StreamingDataReady_Flag = true;
}