PicoScope 7 Software
Available on Windows, Mac and Linux
I haven't tried the code yet, but after reviewing it, it seems you've gone back to using an array of buffers that's twice as big. In your sample code, I believe you used a downsampling mode of PS6000_RATIO_MODE_AGGREGATE, which returns two values (min and max). To reduce the memory usage, I specified PS6000_RATIO_MODE_NONE, which I thought would return only one value per sample and cut the memory usage in half, requiring only one buffer per channel instead of two. Am I misunderstanding that?Martyn wrote:Managed to get some holiday
Can you try with the attached code
Code: Select all
void BlockDataHandler(UNIT * unit, char * text, int offset)
{
int i, j;
float timeInterval;
unsigned long sampleCount= 125000005;//BUFFER_SIZE;
FILE * fp=NULL;
unsigned long maxSamples;
// short * buffers[PS6000_MAX_CHANNEL_BUFFERS];
short * buffers[4];
long timeIndisposed;
PICO_STATUS status;
long numPreSamples = BUFFER_SIZE * 5 / 500;
long numPostSamples = BUFFER_SIZE * 495 / 500;
for (i = 0; i < unit->channelCount; i++)
{
buffers[i] = (short*)malloc(sampleCount * sizeof(short));
if (buffers[i] == 0) {
printf("ERROR, malloc 1 (%d) failed.\n", i);
}
// buffers[i * 2 + 1] = (short*)malloc(sampleCount * sizeof(short));
// if (buffers[i*2+1] == 0) {
// printf("ERROR, malloc 2 (%d) failed.\n", i);
// }
// status = ps6000SetDataBuffers(unit->handle, (short)i, buffers[i * 2], buffers[i * 2 + 1], sampleCount, PS6000_RATIO_MODE_NONE);
status = ps6000SetDataBuffer(unit->handle, (short)i, buffers[i], sampleCount, PS6000_RATIO_MODE_NONE);
printf("BlockDataHandler:ps6000SetDataBuffers(channel %d) ------ %d \n", i, status);
}
/* find the maximum number of samples, the time interval (in timeUnits),
* the most suitable time units, and the maximum oversample at the current timebase*/
while (ps6000GetTimebase2(unit->handle, timebase, sampleCount, &timeInterval, oversample, &maxSamples, 0))
{
timebase++;
}
printf("\nTimebase: %lu SampleInterval: %fnS oversample: %hd maxSamples: %ul\n", timebase, timeInterval, oversample, maxSamples);
/* Start it collecting, then wait for completion*/
g_ready = FALSE;
if((status = ps6000RunBlock(unit->handle, 0, sampleCount, timebase, oversample, &timeIndisposed, 0, CallBackBlock, NULL)) != PICO_OK)
// if((status = ps6000RunBlock(unit->handle, numPreSamples, numPostSamples, timebase, oversample, &timeIndisposed, 0, CallBackBlock, NULL)) != PICO_OK)
printf("BlockDataHandler:ps6000RunBlock ------ 0x%08lx \n", status);
printf("Waiting for trigger...Press a key to abort\n");
while (!g_ready && !_kbhit()) {
Sleep(0);
}
status = ps6000Stop(unit->handle);
printf("BlockDataHandler:ps6000Stop ------ %i \n", status);
if(g_ready)
{
//printf("indisposed time = %ul\n", timeIndisposed);
if((status = ps6000GetValues(unit->handle, 0, (unsigned long*) &sampleCount, 1, PS6000_RATIO_MODE_NONE, 0, NULL)) != PICO_OK)
printf("BlockDataHandler:ps6000GetValues ------ %i \n", status);
printf("samples: %ul\n", sampleCount);
/* Print out the first 10 readings, converting the readings to mV if required */
printf(text);
printf("Value (%s)\n", ( scaleVoltages ) ? ("mV") : ("ADC Counts"));
for (j = 0; j < unit->channelCount; j++)
{
if (unit->channelSettings[j].enabled)
printf("Channel%c:\t", 'A' + j);
}
printf("\n");
for (i = offset; i < offset+10; i++)
{
for (j = 0; j < unit->channelCount; j++)
{
if (unit->channelSettings[j].enabled)
{
printf(" %6d ", scaleVoltages ?
adc_to_mv(buffers[j][i], unit->channelSettings[PS6000_CHANNEL_A + j].range) // If scaleVoltages, print mV value
:buffers[j][i]); // else print ADC Count
}
}
printf("\n");
}
sampleCount = __min(sampleCount, BUFFER_SIZE);
fopen_s(&fp, BlockFile, "w");
if (fp != NULL)
{
fprintf(fp, "Block Data log\n\n");
fprintf(fp,"Results shown for each of the enabled Channels are......\n");
fprintf(fp,"Maximum Aggregated value ADC Count & mV, Minimum Aggregated value ADC Count & mV\n\n");
fprintf(fp, "Time ");
for (i = 0; i < unit->channelCount; i++)
{
if (unit->channelSettings[i].enabled)
{
fprintf(fp," Ch Max ADC Max mV Min ADC Min mV ");
}
}
fprintf(fp, "\n");
for (i = 0; i < sampleCount; i++)
{
fprintf(fp, "%5lld,", g_times[0] + (long long)(i * timeInterval));
for (j = 0; j < unit->channelCount; j++)
{
//fprintf(fp, "%lld ", g_times[j] + (long long)(i * timeInterval));
if (unit->channelSettings[j].enabled)
{
fprintf(fp,
"%C,%5d,%+5d,",
'A' + j,
buffers[j][i],
adc_to_mv(buffers[j][i], unit->channelSettings[PS6000_CHANNEL_A + j].range));
}
}
fprintf(fp, "\n");
}
}
else
printf( "Cannot open the file %s for writing.\n"
"Please ensure that you have permission to access.\n", BlockFile);
}
else
{
printf("data collection aborted\n");
_getch();
}
if (fp != NULL)
fclose(fp);
for (i = 0; i < unit->channelCount; i++)
{
free(buffers[i]);
}
}