PicoScope 7 Software
Available on Windows, Mac and Linux
Code: Select all
short g_triggered = 0;
unsigned long g_trigAt = 0;
/****************************************************************************
* Callback
* used by PS6000 data streaimng collection calls, on receipt of data.
* used to set global flags etc checked by user routines
****************************************************************************/
void PREF4 CallBackStreaming( short handle,
unsigned long noOfSamples,
unsigned long startIndex,
short overflow,
unsigned long triggerAt,
short triggered,
short autoStop,
void *pParameter)
{
// used for streaming
g_sampleCount = noOfSamples;
g_startIndex = startIndex;
g_autoStopped = autoStop;
// flag to say done reading data
g_ready = TRUE;
g_triggered = triggered;
if(triggered)
g_trigAt = triggerAt;
}
Code: Select all
/****************************************************************************
* Stream Data Handler
* - Used by the two stream data examples - untriggered and triggered
* Inputs:
* - unit - the unit to sample on
* - preTrigger - the number of samples in the pre-trigger phase
* (0 if no trigger has been set)
***************************************************************************/
void StreamDataHandler(UNIT * unit, unsigned long preTrigger)
{
unsigned long sampleCount= BUFFER_SIZE * 1000;
short * buffer[1];
PICO_STATUS status;
unsigned long sampleInterval = 1;
int index = 0;
int totalSamples;
int totalAtTrigger = 0;
int postTriggerSamples;
short hasBeenTriggered = 0;
buffer[0] = (short*) malloc(sampleCount * sizeof(short));
status = ps6000SetDataBuffer( unit->handle,
PS6000_CHANNEL_A,
buffer[0],
sampleCount,
PS6000_RATIO_MODE_NONE);
printf("Waiting for trigger...Press a key to abort\n");
g_autoStopped = FALSE;
g_triggered = 0;
g_trigAt = 0;
status = ps6000RunStreaming(unit->handle,
&sampleInterval,
PS6000_US,
preTrigger,
1000000 - preTrigger,
//FALSE,
TRUE,
1,
PS6000_RATIO_MODE_NONE,
sampleCount);
printf("\nps6000RunStreaming status = 0x%x\n", status);
printf("Streaming data...Press a key to abort\n");
totalSamples = 0;
while (!_kbhit() && !g_autoStopped)
{
/* Poll until data is received. Until then, GetStreamingLatestValues wont call the callback */
Sleep(100);
g_ready = FALSE;
status = ps6000GetStreamingLatestValues(unit->handle, CallBackStreaming, NULL);
if (g_ready && g_sampleCount > 0) /* can be ready and have no data, if autoStop has fired */
{
if(g_triggered)
{
hasBeenTriggered = 1;
totalAtTrigger = totalSamples + g_trigAt;
}
totalSamples += g_sampleCount;
printf("Collected %li samples\r", totalSamples);
if(g_triggered)
{
printf("\n\nTriggered at %lu\n", totalAtTrigger);
}
}
}
if(hasBeenTriggered)
{
printf("Number of post trigger samples: %lu", (totalSamples - (totalAtTrigger - 1)));
}
ps6000Stop(unit->handle);
if (!g_autoStopped)
printf("data collection aborted\n");
printf("\nPress key to continue\n");
_getch();
free(buffer[0]);
}
Code: Select all
/****************************************************************************
* CollectStreamingTriggered
* this function demonstrates how to collect a stream of data
* from the unit (start collecting on trigger)
***************************************************************************/
void CollectStreamingTriggered(UNIT * unit)
{
short triggerVoltage = mv_to_adc(500, unit->channelSettings[PS6000_CHANNEL_A].range); // ChannelInfo stores ADC counts
struct tPwq pulseWidth;
struct tPS6000TriggerChannelProperties sourceDetails = { triggerVoltage,
10,
triggerVoltage,
10,
PS6000_CHANNEL_A,
PS6000_LEVEL};
struct tPS6000TriggerConditions conditions = { PS6000_CONDITION_TRUE,
PS6000_CONDITION_DONT_CARE,
PS6000_CONDITION_DONT_CARE,
PS6000_CONDITION_DONT_CARE,
PS6000_CONDITION_DONT_CARE,
PS6000_CONDITION_DONT_CARE,
PS6000_CONDITION_DONT_CARE };
struct tTriggerDirections directions = { PS6000_RISING,
PS6000_NONE,
PS6000_NONE,
PS6000_NONE,
PS6000_NONE,
PS6000_NONE };
memset(&pulseWidth, 0, sizeof(struct tPwq));
printf("Collect streaming triggered...\n");
printf("Data is written to disk file (data.txt)\n");
printf("Press a key to start\n");
_getch();
SetDefaults(unit);
/* Trigger enabled
* Rising edge
* Threshold = 500mV */
SetTrigger(unit->handle, &sourceDetails, 1, &conditions, 1, &directions, &pulseWidth, 0, 0, 0);
StreamDataHandler(unit, 1000);
}