Why am I getting more values than requested?

Post general discussions on using our drivers to write your own software here
Post Reply
Ben321
User
User
Posts: 5
Joined: Tue May 23, 2017 8:09 am

Why am I getting more values than requested?

Post by Ben321 » Wed Aug 07, 2019 7:04 am

When I use the function ps2000_run_streaming_ns() I'm using it with the following parameters:
ps2000_run_streaming_ns(hScope,1000,PS2000_NS,16000,0,1,16000)
As you can see, I am running it at 1000ns per sample (that is, a samplerate of 1million smp/sec), and disabled auto_stop (so that later I will call ps2000_stop to stop the streaming). And as you also can see, I set the max_samples and overview_buffer_size both to number of samples I want, and set number of samples per aggregate to 1, so as to force each sample to actually represent one actual sample (not a statistical minimum or maximum value for a range of samples).

This should make sure my callback function never gets more samples than 16000 samples. And I have my software buffer allocated to hold a maximum of 16000 samples (which matches the parameters I used when calling ps2000_run_streaming_ns). However, I have found that every once in a while my program crashed, and when I debugged it, I found I was on occasion getting over 30000 samples in a single running of my callback function (as indicated by the nValues parameter of the callback function). And of course, my callback function writes whatever data it has to the buffer (an array of 16000 16bit short integers) so it was overflowing the buffer and writing data to other data critical to the program's operation, crashing the program.

Why would it do that? That makes no sense. Why is the scope ignoring the parameters max_samples and overview_buffer_size in the function ps2000_run_streaming_ns, and giving me more samples than I told it to?

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

Re: Why am I getting more values than requested?

Post by Martyn » Wed Aug 07, 2019 9:47 am

As you have set AutoStop false, the scope will sample indefinitely, so there is no maximum samples. These parameters are used by the driver to hold a buffer full of raw data that can be accessed after you stop collection. If you only want a set number of samples in total then set AutoStop true.
Martyn
Technical Support Manager

Ben321
User
User
Posts: 5
Joined: Tue May 23, 2017 8:09 am

Re: Why am I getting more values than requested?

Post by Ben321 » Wed Aug 07, 2019 10:08 pm

Martyn wrote:
Wed Aug 07, 2019 9:47 am
As you have set AutoStop false, the scope will sample indefinitely, so there is no maximum samples. These parameters are used by the driver to hold a buffer full of raw data that can be accessed after you stop collection. If you only want a set number of samples in total then set AutoStop true.
So both the max_samples and overview_buffer_size parameters are ignored if auto_stop is disabled?
Well I tried setting both to zero, and the program crashed, so apparently they are both used to set something in the driver.

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

Re: Why am I getting more values than requested?

Post by Martyn » Tue Aug 13, 2019 1:47 pm

They are used to create the circular buffer within the driver from which the application callback reads the data. They don't need to be equal to the total number of samples you wish to collect but need to be large enough so that the circular buffer doesn't fill up when your application is busy doing other tasks.
Martyn
Technical Support Manager

Post Reply