Fast Streaming Mode in C for 2204 and 2205

Post your C and C++ discussions here
Post Reply
drd
Newbie
Posts: 0
Joined: Fri Mar 09, 2012 3:49 pm

Fast Streaming Mode in C for 2204 and 2205

Post by drd »

I'm trying to understand the dynamics of Fast Streaming mode.

I get the scope set up using ps2000_run_streaming_ns.
Then I do

Code: Select all

 while (!kbhit() {
          ps2000_get_streaming_last_values(handle, myhandler);
          Sleep(0);
          /// do stuff with data
}

void myhandler(  blah blah) {
// copy from the overviewbuffers to my own arrays
}
get_streaming last values does not block... so will handler only run once or twice or not at all every time get streaming last values is called? I'm worried about mutual exclusion. Also, what are the pointers in overbuffers pointing to? The newly collected data? Or do I need offsets into those from somewhere else?

Hitesh

Re: Fast Streaming Mode in C for 2204 and 2205

Post by Hitesh »

Hi drd,

The handler will run once every time the ps2000_get_streaming_last_values() function is called.

With regards to the pointers in overbuffers, section 3.5.34 (my_get_overview_buffers) provides an explanation of this - it is 'a pointer to a location where ps2000_get_streaming_last_values() will store a pointer to its overview buffers that contain the sampled data. The driver creates the overview buffers when you call ps2000_run_streaming_ns() to
start fast streaming.'

The overview buffer is 'A buffer in the PC's memory in which the PicoScope 2000 Series driver temporarily stores data on its way from the oscilloscope to the application's buffer.'

The driver uses zero indexing so you don't have to be concerned about offsets.

Once you have stopped collecting data you then retrieve the values into specified buffers in your code.

I hope this provides suitable clarification for you - please reply to this post if you require further clarification.

Regards,

jokkebk
Newbie
Posts: 0
Joined: Tue May 15, 2012 4:27 pm

Re: Fast Streaming Mode in C for 2204 and 2205

Post by jokkebk »

Hello,

I am still very much confused how the ps2000_get_streaming_last_values(), the user-provided callback, overview buffers and fast streaming interact. This would definitely need a more thorough treatment in the programmers manual.

For example, let's say I want to stream 1 gigabyte of data at 2MS/s. I can stop the data collection myself so I allocate a 1 GB buffer and use the following to start streaming:

ps2000_run_streaming_ns(handle, 500, PS2000_NS, 1000000, 0, 1, 50000);

(in your PicoScopeUSBStreaming.pdf it is stated that maximum record the driver itself can store is 2 MS, which I assume limits max_samples to 2000000 at most, also, I have assumed aggregation value of 1 means "no aggregation", although this is not explicitly stated at all in the documentation, only that the value should be 1 or more)

Then I loop and repeatedly call ps2000_get_streaming_last_values(), saving recently captured data in the callback function to my 1 GB buffer until it is full, at which point I end the capture process. Everything works nicely. However:

1) You state that "once you have stopped collecting data, you then retrieve the values into specified buffers in your code" - how is that possible if I have ran the capture process for 1 GS, and the driver has supposedly only allocated 1 MS for its own buffer?

2) Shouldn't I be storing the data in the callback instead? I'm currently doing this and it works great.

3) I noticed that the example program ps2000con.c does not do anything to the overview buffers in the callback - is this because the total capture length is actually max_samples, not more (so the driver buffer is enough for all captured data)?

4) What kind of value do you recommend for the overview buffer for maximum throughput? I have noticed that faster than 280 ns capture rates are not possible, but this 3.6 MS/s is somewhat less than 6.6 MS/s maximum rate suggested by PicoScopeUSBStreaming.pdf for the 2-channel 2000 series - do the overview buffer sizes have a role in this, or is it just PC/hardware specific?

Overall, the documentation should have a general explanation how the fast streaming mode works in the driver, this would eliminate a lot of guessing on the user part. For example, it is unclear if the driver is doing the capture in a separate thread, and if overview buffers are just pointers to the big capture buffer of max_samples (or if max_samples is just a counter totally separate from buffer sizes), or if the driver somehow calculates the aggregates into separate overview buffers.

-Joonas

PS. Amazing product! The C API docs just leave some question marks...

Hitesh

Re: Fast Streaming Mode in C for 2204 and 2205

Post by Hitesh »

Hi Joonas,

The number specified for aggregation is effectively a ratio, so a value of 1 means effectively no aggregration.

With regards to the four main questions:

1 & 2)
once you have stopped collecting data, you then retrieve the values into specified buffers in your code
I was referring to the example code having missed what is in the Programmer's Guide so apologies for any confusion. The example calls the ps2000_get_streaming_values_no_aggregation() function to get the data without aggregation from the driver after the data has been collected. In section 3.5.34 (my_overview_buffers) of the guide it does mention
'Your callback function should do nothing more than copy the data to another buffer within your application.'


so ideally you should copy out the data into your buffer as you have done.

3) The example code provides some guidance on how to call the functions and provide some sort of sequence. The Programmer's guide provides more information on the function and how code should be structured. In the example, there is a call made to the ps2000_get_streaming_values_no_aggregation() after the driver has stopped collecting data in order to extract the data from the overview buffers into the channels.

4) This will be dependent on your PC resources but we've noticed that you've enabled Channel B so this will have some impact. Set the Channel B 'enabled' variable to false and hopefull you should see an improvement.

I've passed on your comments about the documentation to our Technical Authors.

I hope this helps.

Post Reply