In streaming mode, you set the device running and then continuously collect data from the driver when it is available or wait until the device has finished collecting data and retrieve it from the driver.
To answer your questions:
First, I cannot understand why ps2000_run_streaming_ns() requires two sizes as parameters - max_samples and overview_buffer_size?
The driver stores data from each channel - this corresponds to max_samples
. Once you have finished collecting data, this can be retrieved from the driver using the ps2000_get_streaming_values_no_aggregation() for raw data values or call ps2000_get_streaming_values() to obtain aggregated data.
When collecting streaming data, the driver uses a temporary buffer to store data in before passing it to your application. The overview_buffer_size
parameter is used to define the size of this buffer. It is from these buffers that you copy data inside the streaming callback function.
The second question: Do I have to call ps2000_get_streaming_last_values() repeatedly or I can sleep between calls? (The sample code doesn't sleep, just calls it in the loop).
You can introduce a small sleep depending on the sampling rate at which you are collecting data. You need to ensure that you are collecting data at suitable intervals to ensure that data is not lost. Note that the PicoScope 2000 Series oscilloscopes are low memory devices so it would not take long to fill up the buffer memory which is used as a cache in streaming mode.
And third: According to the doc the ps2000_get_streaming_last_values() can return 0 if there is no samples available. It doesn't make sense, because it's callback registration function, how do I know that it's time to ask for call back then?
The function will return 0 if one of the input values is out of range. In the case of no samples being available, this would most likely be if the function is called when streaming data collection has stopped.
I hope that this helps.