Test and Measurement Forum

use call backfunction in continuous streaming

Post your C and C++ discussions here

use call backfunction in continuous streaming

Postby Xchen » Thu Dec 11, 2014 3:13 am

Hi,

We have a PS5244A and are trying to use the C sample code from PicoTech to stream data continuously. The original code was modified so that raw data, not aggregated data, are copied into application buffer by the CallBackStreaming() function.

I also set the scope to sample at 48ns interval, 16-bit before start streaming. The wait time in the while() loop of the sample code function StreamDataHandler() is changed to sleep(1000), in the hope to receive 20.833333M samples every cycle. Please see the code at the end.

The program printed out number of samples collected each time CallBackStreaming() was executed (and flagged g_read and set g_sampleCount to non-zero), until a keyboard hit stops the program. However it seems to be getting large and small number of samples alternately every other cycle. The screen output is quoted below. The parameter "index" is the count of how many times the while() loos is being executed.

Why didn't it collect same amount of data every time as expected (20833333 every second, = 1/48ns)? Does CallBackStreaming() get called every time in the while() loop at the line :

status = ps5000aGetStreamingLatestValues(unit->handle, CallBackStreaming, &bufferInfo);

or it gets called whenever the buffer is full?

Thanks in advance for any help!

Xi

Searching for devices...


5V power supply not connected.
Do you want to run using USB only Y/N?

Powering the unit via USB
Handle: 1. Device opened successfully.
MCTunit.resolution =4
MCTunit.maxADCValue =32767


Collect streaming...
Data is written to disk file (stream.txt)
Press a key to start

Streaming Data continually at Time Interval = 48 (ns)

Streaming data...Press a key to stop

index = 1
Collected 2080768 samples, start index in buffer= 0, Total: 2080768 samples
index = 2
Collected 2565 samples, start index in buffer= 2080768, Total: 2083333 samples
index = 3
Collected 2080767 samples, start index in buffer= 0, Total: 4164100 samples
index = 4
Collected 2566 samples, start index in buffer= 2080767, Total: 4166666 samples
index = 5
Collected 2080766 samples, start index in buffer= 0, Total: 6247432 samples
index = 6
Collected 2567 samples, start index in buffer= 2080766, Total: 6249999 samples
index = 7
Collected 2080765 samples, start index in buffer= 0, Total: 8330764 samples
index = 8
Collected 2568 samples, start index in buffer= 2080765, Total: 8333332 samples
index = 9
Collected 2080764 samples, start index in buffer= 0, Total: 10414096 samples
index = 10
Collected 2569 samples, start index in buffer= 2080764, Total: 10416665 samples
index = 11
Collected 2080763 samples, start index in buffer= 0, Total: 12497428 samples
index = 12
Collected 2570 samples, start index in buffer= 2080763, Total: 12499998 samples
index = 13
Collected 2080762 samples, start index in buffer= 0, Total: 14580760 samples
index = 14
Collected 2571 samples, start index in buffer= 2080762, Total: 14583331 samples
index = 15
Collected 2080761 samples, start index in buffer= 0, Total: 16664092 samples
index = 16
Collected 2572 samples, start index in buffer= 2080761, Total: 16666664 samples

Time elapsed = 16807 (ms)
Total samples collected = 16666664
Streaming Rate = 9.916501e+05 (Samples/sec)

Data collection aborted
Exit.



Code: Select all
    int64_t time_start_ms, time_stop_ms;
    int64_t time_test1_ms, time_test2_ms;
    time_start_ms = exx_get_time_ms();
   
   while (!_kbhit() && !g_autoStopped)
   {
   /* Poll until data is received. Until then, GetStreamingLatestValues wont call the callback */
      Sleep(1000);
      g_ready = FALSE;
     
      status = ps5000aGetStreamingLatestValues(unit->handle, CallBackStreaming, &bufferInfo);
     
      index ++;
      printf("\nindex = %d\n", index);
      
     if (g_ready && g_sampleCount > 0) /* can be ready and have no data, if autoStop has fired */
      {
         totalSamples += g_sampleCount;           
         printf("Collected %3li samples, start index in buffer= %5lu, Total: %6d samples ", g_sampleCount, g_startIndex, totalSamples);
      }
   }

    time_stop_ms = exx_get_time_ms();
    printf("\nTime elapsed = %d (ms)\n", time_stop_ms - time_start_ms);
    printf("Total samples collected = %d\n", totalSamples);
    printf("Streaming Rate = %e (Samples/sec)\n", 1000.0*totalSamples/(time_stop_ms-time_start_ms));
Xchen
Newbie
 
Posts: 0
Joined: Tue Dec 09, 2014 6:12 am

Re: use call backfunction in continuous streaming

Postby Hitesh » Tue Dec 16, 2014 11:48 am

Hello Xi,

The behaviour that you are seeing is expected.

Although the device can collect data in streaming mode, the data will be 'chunked' in order to send it over the USB connection to the PC.

Please note that for 8-bit resolution data collection, the maximum transfer rate over the USB 2.0 connection (depending on PC resources) would be around 30MS/s, so for 16-bit resolution, this would be around 15MS/s.

The buffer memory on the PicoScope is used as a cache but you will need to ensure that your application retrieves the data from the driver in good time to avoid lost data.

The streaming callback function (CallBackStreaming()) is called when the driver has data from the device.

I would suggest increasing your overview buffer size. Is there a particular reason why you need a specific number of samples to be returned on each iteration of the loop?

Regards,
Hitesh

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


Return to C and C++

Who is online

Users browsing this forum: No registered users and 1 guest