PicoScope 7 Software
Available on Windows, Mac and Linux
Code: Select all
unsigned long bufferSize = 30000000; // size of the software buffer is 30MB
FILE * fpA, * fpB;
FILE * fp1, * fp2;
short * buffers[2];
PICO_STATUS status;
unsigned long sampleInterval = 1670;
for (i = 0; i < unit->ChannelCount; i++) // create data buffers
{
buffers[i] = (short*) malloc(bufferSize * sizeof(short));
ps5000SetDataBuffer(unit->handle, (PS5000_CHANNEL) i, buffers[i], bufferSize);
}
printf("Waiting for trigger...Press a key to abort\n");
g_autoStop = FALSE;
status = ps5000RunStreaming(unit->handle, &sampleInterval, PS5000_NS,
preTrigger, 30000000 - preTrigger, FALSE, 1,
bufferSize);
if (status != PICO_OK)
{
printf("Streaming Mode: fail to call run_streaming successfully \n");
return;
}
printf("Streaming data...Press a key to abort\n");
fpA = fopen("channelA.bin", "w");
fpB = fopen("channelB.bin", "w");
while (!_kbhit() && !g_autoStop)
{
/* Poll until data is received. Until then, GetStreamingLatestValues wont call the callback */
Sleep(100);
g_ready = FALSE;
status = ps5000GetStreamingLatestValues(unit->handle,
CallBackStreaming, NULL);
if (g_ready && g_sampleCount > 0) /* can be ready and have no data, if autoStop has fired */
{
printf("Collected %i samples, index = %i\n", g_sampleCount, g_startIndex);
fwrite(&buffers[0][g_startIndex], sizeof(short), g_sampleCount, fpA);
fwrite(&buffers[1][g_startIndex], sizeof(short), g_sampleCount, fpB);
}
}
ps5000Stop(unit->handle);
fclose(fpA);
fclose(fpB);
if (!g_autoStop) {
printf("data collection aborted\n");
_getch();
}
for (i = 0; i < unit->ChannelCount; i++) {
free(buffers[i]);
}
// Read out from the binary file and save as text
printf("Opening binary file and saving as text...\n");
for (i = 0; i < unit->ChannelCount; i++) // create data buffers
{
buffers[i] = (short*) malloc(bufferSize * sizeof(short));
}
fpA = fopen("channelA.bin", "r");
fpB = fopen("channelB.bin", "r");
fp1 = fopen("channelA.txt","w");
fp2 = fopen("channelB.txt","w");
fread(buffers[0], sizeof(short), 10000, fpA);
fread(buffers[1], sizeof(short), 10000, fpB);
for (i = 0; i < 10000; i++) {
fprintf(fp1,"%i, %d\n", i, buffers[0][i]);
fprintf(fp2,"%i, %d\n", i, buffers[1][i]);
}
fclose(fpA);
fclose(fpB);
fclose(fp1);
fclose(fp2);
for (i = 0; i < unit->ChannelCount; i++) {
free(buffers[i]);
}