Test and Measurement Forum

Streaming and callbacks (Linux)

Post your Linux discussions here

Streaming and callbacks (Linux)

Postby mrrg » Mon Nov 14, 2016 5:25 pm

Hello

I am trying to stream data from a digital port, with triggering.

I have gotten so far that I am calling ps2000aGetStreamingLatestValues() with a callback function.

The callback function is called, but then data is still in the scope right?
And I need to call ps2000aGetValuesAsync() to transfer data from the scope?

I do this supplying a second callback to ps2000aGetValuesAsync(), strangely defined as void * lpDataReady ??

This function is then never called by ps2000aGetValuesAsync()? Why is this so?

All functions return PICO_OK

Note that noOfSamples and startIndex indicate data exists, though sometimes noOfSamples is negative in the callback function ps2000aStreamingReady() ??

We use the picoscope: 2208B MSO
And the latest linux drivers: libps2000a-1.1/
mrrg
Newbie
 
Posts: 0
Joined: Mon Nov 14, 2016 4:44 pm

Re: Streaming and callbacks (Linux)

Postby Hitesh » Tue Nov 15, 2016 9:55 am

Hi mrrg,

If you require data during the collection process, you should copy data from the driver buffers to application buffers in the streaming callback as per the definition below:

Code: Select all
/****************************************************************************
* Callback
* used by PS2000A data streaming collection calls, on receipt of data.
* used to set global flags etc checked by user routines
****************************************************************************/
void PREF4 CallBackStreaming(   int16_t handle,
   int32_t noOfSamples,
   uint32_t   startIndex,
   int16_t overflow,
   uint32_t triggerAt,
   int16_t triggered,
   int16_t autoStop,
   void   *pParameter)
{
   int32_t channel;
   int32_t digiPort;
   BUFFER_INFO * bufferInfo = NULL;

   if (pParameter != NULL)
   {
      bufferInfo = (BUFFER_INFO *) pParameter;
   }

   // used for streaming
   g_sampleCount   = noOfSamples;
   g_startIndex   = startIndex;
   g_autoStopped   = autoStop;
   g_overflow      = overflow;

   // flag to say done reading data
   g_ready = TRUE;

   // flags to show if & where a trigger has occurred
   g_trig = triggered;
   g_trigAt = triggerAt;

   if (bufferInfo != NULL && noOfSamples)
   {
      if (bufferInfo->mode == ANALOGUE)
      {
         for (channel = 0; channel < bufferInfo->unit->channelCount; channel++)
         {
            if (bufferInfo->unit->channelSettings[channel].enabled)
            {
               if (bufferInfo->appBuffers && bufferInfo->driverBuffers)
               {
                  if (bufferInfo->appBuffers[channel * 2]  && bufferInfo->driverBuffers[channel * 2])
                  {
                     memcpy_s (&bufferInfo->appBuffers[channel * 2][startIndex], noOfSamples * sizeof(int16_t),
                        &bufferInfo->driverBuffers[channel * 2][startIndex], noOfSamples * sizeof(int16_t));
                  }
                  if (bufferInfo->appBuffers[channel * 2 + 1] && bufferInfo->driverBuffers[channel * 2 + 1])
                  {
                     memcpy_s (&bufferInfo->appBuffers[channel * 2 + 1][startIndex], noOfSamples * sizeof(int16_t),
                        &bufferInfo->driverBuffers[channel * 2 + 1][startIndex], noOfSamples * sizeof(int16_t));
                  }
               }
            }
         }
      }
      else if (bufferInfo->mode == AGGREGATED)
      {
         for (channel = 0; channel < bufferInfo->unit->digitalPorts; channel++)
         {
            if (bufferInfo->appDigBuffers && bufferInfo->driverDigBuffers)
            {
               if (bufferInfo->appDigBuffers[channel * 2] && bufferInfo->driverDigBuffers[channel * 2])
               {
                  memcpy_s (&bufferInfo->appDigBuffers[channel * 2][startIndex], noOfSamples * sizeof(int16_t),
                     &bufferInfo->driverDigBuffers[channel * 2][startIndex], noOfSamples * sizeof(int16_t));
               }
               if (bufferInfo->appDigBuffers[channel * 2 + 1] && bufferInfo->driverDigBuffers[channel * 2 + 1])
               {
                  memcpy_s (&bufferInfo->appDigBuffers[channel * 2 + 1][startIndex], noOfSamples * sizeof(int16_t),
                     &bufferInfo->driverDigBuffers[channel * 2 + 1][startIndex], noOfSamples * sizeof(int16_t));
               }
            }
         }
      }
      else if (bufferInfo->mode == DIGITAL)
      {
         for (digiPort = 0; digiPort < bufferInfo->unit->digitalPorts; digiPort++)
         {
            if (bufferInfo->appDigBuffers && bufferInfo->driverDigBuffers)
            {
               if (bufferInfo->appDigBuffers[digiPort] && bufferInfo->driverDigBuffers[digiPort])
               {
                  memcpy_s (&bufferInfo->appDigBuffers[digiPort][startIndex], noOfSamples * sizeof(int16_t),
                     &bufferInfo->driverDigBuffers[digiPort][startIndex], noOfSamples * sizeof(int16_t));
               }
            }
         }
      }
   }
}

The ps2000aGetValuesAsync() function can be used once data collection has been stopped to retrieve data values from the driver (with different modes of downsampling if required). The ps2000aStop() function should be called beforehand.

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: Streaming and callbacks (Linux)

Postby mrrg » Wed Nov 16, 2016 1:27 pm

Ok thanks, it works now. I was confused by the manual.
mrrg
Newbie
 
Posts: 0
Joined: Mon Nov 14, 2016 4:44 pm


Return to Linux

Who is online

Users browsing this forum: No registered users and 0 guests