Test and Measurement Forum

Help with understanding ps2000_run_streaming_ns

Post your .Net discussions here

Help with understanding ps2000_run_streaming_ns

Postby davidpruitt » Thu Jun 02, 2016 11:18 pm

Once again, using the Pico 2204A scope. When using hte ps2000_run_streaming_ns function, the parameters are as follows:

scope handle, sample interval, time units, max samples, auto stop, no. of samples per aggregate, and overview buffer size

If "auto stop" is false, does the parameter "max samples" mean or do anything? I assume it only means the total number of samples the user wants streamed before the scope stops streaming, but that is not clear in the documentation. Based on the documentation, "max samples" and "overview buffer size" sound almost identical, hence why I am confused.

The documentation reads as such:

max_samples: the maximum number of samples that the driver
should store from each channel. Your computer must have enough
physical memory for this many samples, multiplied by the number
of channels in use, multiplied by the number of bytes per sample.

overview_buffer_size: the size of the overview buffers,
temporary buffers used by the driver to store data before passing it
to your application. You can check for overview buffer overruns
using the ps2000_overview_buffer_status() function and adjust the
overview buffer size if necessary. We recommend using an initial
value of 15,000 samples.


To give you an idea of the context in which I am doing this in: In my application, I am doing constant streaming (so I set auto stop to be false). I have a software-defined logical trigger in my code that collects the samples I care about from the oscilloscope.

When my software-defined trigger is activated, I collect about 500ms worth of data at a sample rate of 1 sample = 10 us.

This is my call to the ps2000_run_streaming_ns function to set up streaming before all of that happens:

Code: Select all
uint _bufferSize = 15000; //is this really even necessary?!?!?!?
uint _overview_buffer_size = 15000;
uint microseconds_per_sample = 10;
short auto_stop = 0;
short result = PicoScopeLibrary.Imports.ps2000_run_streaming_ns(ScopeHandle, microseconds_per_sample,
   PicoScopeLibrary.Imports.ReportedTimeUnits.MicroSeconds,
   _bufferSize, auto_stop, 1, _overview_buffer_size);


Thanks for any help!
davidpruitt
Advanced User
Advanced User
 
Posts: 21
Joined: Tue May 17, 2016 6:45 pm

Re: Help with understanding ps2000_run_streaming_ns

Postby Hitesh » Fri Jun 03, 2016 9:29 am

Hi David,

The driver is able to store samples collected during streaming mode collection.

If you use the auto_stop feature then the data collection is stopped when max_samples have been collected per channel.

If you do not use the auto_stop flag, then when you stop the data collection, max_samples will be the number of samples per channel stored in the driver which you can then retrieve using the ps2000_get_streaming_values() and ps2000_get_streaming_values_no_aggregation() functions (your application may already have collected all the samples you require which could be more than max_samples).

If your application does not need to make use of the max_samples parameter, then you can set it to a small value.

The overview_buffer_size is used for temporary buffers used to collect the data, and can be smaller than the buffers that the driver will use to store the samples during data collection. The data from the overview buffers should be copied into application buffers in the callback function.

The Programmer's Guide is in the process of being updated so I will request that clarification is provided.

Hope this provides suitable clarification.

Regards,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2058
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: Help with understanding ps2000_run_streaming_ns

Postby davidpruitt » Fri Jun 03, 2016 3:23 pm

The way I would like to interact with the oscilloscope is basically as if it were a serial connection just streaming me constant data, and then I choose to either throw away that data or use it.

So something like this (pseudocode):

Code: Select all
StartStreaming(scope_handle);

while(true)
{
   new_data = ReadNewScopeData(scope_handle);
   ProcessNewData(new_data);
}


I have basically built a software trigger to see when the scope data exceeds a certain voltage value (in my case, 0.5 V), and any time it does that, I retain the next 500ms of scope data. Otherwise, I throw it all away.

So basically like this:

Code: Select all
StartStreaming(scope_handle);

program_state = idle;

while(true)
{
   new_data = ReadNewScopeData(scope_handle);
      
   switch (program_state)
   {
      case idle:
         //see if there is a trigger
         is_triggered = new_data.Max() > 0.5 volts
         if (is_triggered)
            set program state to triggered
            
      case triggered:
         
         triggered_data.Add(new_data);
         if (triggered_data.length > 500 ms of data)
            save triggered_data to file
            set program state to idle
   }
}
davidpruitt
Advanced User
Advanced User
 
Posts: 21
Joined: Tue May 17, 2016 6:45 pm

Re: Help with understanding ps2000_run_streaming_ns

Postby Hitesh » Mon Jun 06, 2016 8:12 am

Hi David,

Based on your requirements, I would suggest copying the data into an application buffer for each channel in the streaming callback and then process the data from the application buffer(s) in your main iteration loop.

Have you seen the code flow in the C# streaming example callback function?

Regards,
Hitesh

Technical Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 2058
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire


Return to .Net Languages (C#, VB.Net, .)

Who is online

Users browsing this forum: No registered users and 0 guests