Test and Measurement Forum

Digital Triggering

Post general discussions on using our drivers to write your own software here

Digital Triggering

Postby Will252 » Wed May 04, 2016 9:01 am

Hi, I am writing a python program to interface with a PicoScope 2205MSO. I can set the timebase and voltage range, run in block, rapid block and streaming modes, set a data buffer and read back the data. But I am having trouble setting a digital trigger.

My script calls ps2000aSetTriggerDigitalPortProperties without any errors but the data returned doesn't seem to have been triggered, it appears to have just starts recording immediately. Do I need to call any other functions to set a digital trigger?
Will252
Newbie
 
Posts: 0
Joined: Wed Aug 05, 2015 1:39 pm

Re: Digital Triggering

Postby Hitesh » Thu May 05, 2016 10:00 am

Hi Will252,

Try calling the ps2000aSetTriggerChannelConditions() function to indicate that a digital trigger will be used.

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: Digital Triggering

Postby Will252 » Fri May 06, 2016 2:55 pm

So I've tried calling ps2000aSetTrggerChannelConditions. When I set channel A as the trigger channel it runs without errors but if I try to use digital I get the error: PICO_CONDITIONS (One or more of the conditions are incorrect.).

The reason I didn't try it before is the manual says
channelC, channelD, aux, digita: not used.
. I assume that is why it is ok with channel A but not digital.
Will252
Newbie
 
Posts: 0
Joined: Wed Aug 05, 2015 1:39 pm

Re: Digital Triggering

Postby Hitesh » Mon May 09, 2016 9:18 am

Hi Will252,

Which version of the ps2000a.dll are you using?

A new function (ps2000aSetDigitalAnalogTriggerOperand()) has been introduced - please refer to section 3.41 of the Programmer's Guide.

If you are using the dll provided as part of the PicoScope 6.11 installation, try calling this function with operand set to PS2000A_OPERAND_OR.

If this does not work, please post your code showing how the trigger is being set up.

I will check here in case there is an error in the Programmer's Guide with respect to the ps2000aSetTriggerChannelConditions() 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

Re: Digital Triggering

Postby mrrg » Mon Nov 21, 2016 1:13 pm

Hello

I am having similar problems in Linux.

What is the status of ps2000aSetTriggerChannelConditions() ?

Should I call this to set the digital triggering?
mrrg
Newbie
 
Posts: 0
Joined: Mon Nov 14, 2016 4:44 pm

Re: Digital Triggering

Postby Hitesh » Tue Nov 22, 2016 9:46 am

Hi mmrg,

You will need to call ps2000aSetTriggerChannelConditions() and set the trigger state for the digital ports to PS2000A_CONDITION_TRUE. Next, you will need to call ps2000aSetTriggerDigitalPortProperties() to set the actual digital trigger properties.

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: Digital Triggering

Postby mrrg » Tue Nov 22, 2016 1:40 pm

Ok, now I am setting one condition with
Code: Select all
cond[0].digital=PS2000A_CONDITION_TRUE;


all others are set to
Code: Select all
PS2000A_CONDITION_FALSE


This returns
Code: Select all
PICO_OK


I also made sure that ps2000aSetTriggerChannelConditions() receives the correct pointer and number of conditions, (made an array of conditions but use only the first).

Now the program started to crash on ps2000aRunStreaming () this worked before adding the condition.

bt
#0 0x00007ffff6249fe6 in ?? () from /opt/picoscope/lib/libps2000a.so.2
#1 0x00007ffff62441b6 in ?? () from /opt/picoscope/lib/libps2000a.so.2
#2 0x00007ffff6238a07 in ?? () from /opt/picoscope/lib/libps2000a.so.2
#3 0x00007ffff61cfeca in ps2000aRunStreaming () from /opt/picoscope/lib/libps2000a.so.2

Do the order of the calls matter?
I am calling in this order:

ps2000aOpenUnit()
ps2000aSetChannel()
ps2000aSetDigitalPort()
ps2000aSetTriggerDigitalPortProperties()
ps2000aSetTriggerChannelConditions()
ps2000aSetDataBuffer()
ps2000aRunStreaming()

Best regards
Reine
mrrg
Newbie
 
Posts: 0
Joined: Mon Nov 14, 2016 4:44 pm

Re: Digital Triggering

Postby Hitesh » Tue Nov 22, 2016 2:29 pm

Hi Reine,

I would suggest calling ps2000aSetTriggerChannelConditions() BEFORE ps2000aSetTriggerDigitalPortProperties().

Which version of the ps2000a driver are you using?

Is it possible to post your source code here or e-mail it to support@picotech.com?

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: Digital Triggering

Postby mrrg » Tue Nov 22, 2016 4:17 pm

Hello

I moved the ps2000aSetTriggerChannelConditions() but it still do not trigger.
Also I have very big problems to make the picoscope application to trigger.

I can not post all of the code since it is a lot of unrelated software GUI stuff etc... but I can post the interface code to your device. The following function calls are done on the device class from the GUI and they in turn call your functions, the toplevel functions are at the left column..lower levels to the right.
Code: Select all
// dev->openDevice()         calls ps2000aOpenUnit()
// dev->maplist2Channel()    calls setChannel()
//                           calls ps2000aSetChannel() and ps2000aSetTriggerChannelConditions()
//
// dev->setDigitalPort()     calls ps2000aSetDigitalPort()
// dev->maplist2Directions() calls setDirections() calls ps2000aSetTriggerDigitalPortProperties()
// dev->setDataDevBuffer()   calls ps2000aSetDataBuffer()
// dev->startStreaming()     calls ps2000aRunStreaming()
// dev->getStream()          calls ps2000aGetStreamingLatestValues() with callback void lpPs2000AReady()


Here is the header file
Code: Select all
//
// $HeadURL: svn://squid.irfu.se/swada/libGUI/Device.H $
// $Revision: 333 $
// $Date: 2013-09-27 18:44:22 +0200 (fre, 27 sep 2013) $
// $Author: rg $
//
// Copyright: (C) Reine Gill 2010-2016
//
#ifndef _DEVICE_H_
#define _DEVICE_H_
#include <math.h>
//#include <libusb.h>
#include <PicoStatus.h>
#include <ps2000aApi.h>
#include <map>

#include "Map.H"
#include "SDLThreads.H"

// Device we have is PicoScope 2208B MSO, DX123/0056
//
// According to user manual we shall use the API:
//
///opt/picoscope/include/libps2000a-1.1/
// PicoStatus.h  ps2000aApi.h
// libps2000a
//
//
using namespace std;

// global function not part of the device object
void lpPs2000AReady(
          int16_t handle,
          int32_t noOfSamples,
          uint32_t startIndex,
          int16_t overflow,
          uint32_t triggerAt,
          int16_t triggered,
          int16_t autoStop,void *nParameter
          );

typedef struct channel_type_def
{
  int16_t enabled;
  PS2000A_COUPLING type;
  PS2000A_RANGE range;
  float analogOffset;

} channel_type;

typedef struct port_type_def
{
  int16_t enabled;
  int16_t logiclevel;
} port_type;

class Device
{
public:
  Device();
  ~Device();
 
  bool openDevice();
  bool closeDevice();

  // Set device functions
  bool setChannel(PS2000A_CHANNEL ch);
  bool setDigitalPort(PS2000A_DIGITAL_PORT port);

  bool setDirections();
  bool setDataDevBuffer(int32_t ch);
  bool startStreaming();
  bool stopStreaming();

  // Get device functions
  bool getMaxDownsampling();
  bool getStream();
  unsigned int getNoSamples();
  string getSamplingRateStr();
  void getDataPointer(int16_t **ap,uint32_t *len);

  void ValueHz(double val,char *str);

  // Convert lists of GUI parameters to update device data and also call device set functions
  void maplist2Channel(PS2000A_CHANNEL ch,const char *key,Value *v);
  void maplist2Directions(const char *key,Value *v,int offset);


  void func_lpPs2000AReady(int16_t handle,int32_t noOfSamples,uint32_t startIndex,
            int16_t overflow,uint32_t triggerAt,int16_t triggered,
            int16_t autoStop,void *nParameter);

  // Public Device parameters
  uint32_t requsted_sample_interval;                  // Requested sample interval
  uint32_t used_sample_interval;                      // Actual sample interval

  PS2000A_TIME_UNITS sample_interval_time_unit;        // Units
  uint32_t maxPreTriggerSamples;                       // Maximum pre trigger samples
  uint32_t maxPostTriggerSamples;                      // Maximum post trigger samples
  int16_t autoStop;                                    // Stop then max samples reached

  uint16_t segments;                                   // Number of memory segments

  uint32_t downSampleRatio;                            // Down sample ratio
  uint32_t maxDownSampleRatio;                         // Maximum downsample ratio
  PS2000A_RATIO_MODE downSampleRatioMode;              // Down sample ratio mode

  PS2000A_DIGITAL_CHANNEL_DIRECTIONS directions[32];  // Port directions
  int16_t ndirections;                                // Number of directions

  int present_port_ind;                               // Present port index 0 or 1

  int16_t nconditions;
  PS2000A_TRIGGER_CONDITIONS cond[8];               



  std::map<int,channel_type> channel;
  std::map<int,port_type>    port;

  std::map<int,string> range2str;
  std::map<string,int> str2range;

  std::map<string,int> str2direction;

  std::map<int,string> unit2str;

  std::map<int,double> unit2factor;


private:   
  // Private device parameters
  int16_t handle;
  int16_t *devBuff[2];       // Data devBuffer
  int32_t  dev_buff_len[2];  // Data devBuffer length
  int16_t *appBuff[2];       // Application buffers

  bool devbuffer_set;
};
#endif



Here is the source:
Code: Select all
//
// $HeadURL: svn://squid.irfu.se/swada/libGUI/Base.cpp $
// $Revision: 323 $
// $Date: 2013-09-23 16:44:37 +0200 (mån, 23 sep 2013) $
// $Author: rg $
//
// Copyright: (C) Reine Gill 2010-2016
//
#include <cstdio>
#include <cstring>
#include "Device.H"

extern Device     *dev; // Pointer to the picoscope device class, only one
extern Signal scopeProcess0_sig;


// dev->openDevice()         calls ps2000aOpenUnit()
// dev->maplist2Channel()    calls setChannel()
//                           calls ps2000aSetChannel() and ps2000aSetTriggerChannelConditions()
//
// dev->setDigitalPort()     calls ps2000aSetDigitalPort()
// dev->maplist2Directions() calls setDirections() calls ps2000aSetTriggerDigitalPortProperties()
// dev->setDataDevBuffer()   calls ps2000aSetDataBuffer()
// dev->startStreaming()     calls ps2000aRunStreaming()
// dev->getStream()          calls ps2000aGetStreamingLatestValues() with callback void lpPs2000AReady()
Device::Device()
{
  int i;

  requsted_sample_interval  = 20;
  used_sample_interval      = 20;
  sample_interval_time_unit = PS2000A_US;

  // Setup a map to convert time units to strings
  unit2str[PS2000A_FS]="fs";
  unit2str[PS2000A_PS]="ps";
  unit2str[PS2000A_NS]="ns";
  unit2str[PS2000A_US]="us";
  unit2str[PS2000A_MS]="ms";
  unit2str[PS2000A_S]="s";

  // Setup a map to convert time units to factors
  unit2factor[PS2000A_FS]=1e-15;
  unit2factor[PS2000A_PS]=1e-12;
  unit2factor[PS2000A_NS]=1e-9;
  unit2factor[PS2000A_US]=1e-6;
  unit2factor[PS2000A_MS]=1e-3;
  unit2factor[PS2000A_S] =1.0;

  // Default no Autostop
  autoStop=0;

  // Set default number of samples
  dev_buff_len[0]=200000;
  dev_buff_len[1]=200000;

  present_port_ind=0; // Set the present digital port to 0

  // Half before trigg half after
  //maxPreTriggerSamples=(dev_buff_len[0]>>1);
  //maxPostTriggerSamples=(dev_buff_len[0]>>1);

  // No samples before trigg
  maxPreTriggerSamples=0;
  maxPostTriggerSamples=dev_buff_len[0];
   
  // Allocate buffers for ports and application
  devBuff[0]=new int16_t[dev_buff_len[0]];
  devBuff[1]=new int16_t[dev_buff_len[1]];

  appBuff[0]=new int16_t[dev_buff_len[0]];
  appBuff[1]=new int16_t[dev_buff_len[1]];

  // To begin with use only one memory segment
  segments=1;

  // Set the default downsampling ratio
  downSampleRatio=1;

  // Do not do any downsampling
  downSampleRatioMode=PS2000A_RATIO_MODE_NONE;

  // Setup channels, stored in a map not array
  channel[PS2000A_CHANNEL_A].enabled=0;
  channel[PS2000A_CHANNEL_B].enabled=0;
  channel[PS2000A_CHANNEL_C].enabled=0;
  channel[PS2000A_CHANNEL_D].enabled=0;

  channel[PS2000A_CHANNEL_A].type=PS2000A_AC;
  channel[PS2000A_CHANNEL_B].type=PS2000A_AC;
  channel[PS2000A_CHANNEL_C].type=PS2000A_AC;
  channel[PS2000A_CHANNEL_D].type=PS2000A_AC;

  channel[PS2000A_CHANNEL_A].range=PS2000A_5V;
  channel[PS2000A_CHANNEL_B].range=PS2000A_5V;
  channel[PS2000A_CHANNEL_C].range=PS2000A_5V;
  channel[PS2000A_CHANNEL_D].range=PS2000A_5V;

  channel[PS2000A_CHANNEL_A].analogOffset=0.0f;
  channel[PS2000A_CHANNEL_B].analogOffset=0.0f;
  channel[PS2000A_CHANNEL_C].analogOffset=0.0f;
  channel[PS2000A_CHANNEL_D].analogOffset=0.0f;


  // Setup digital port stored in a map not an array
  port[PS2000A_DIGITAL_PORT0].enabled=0;
  port[PS2000A_DIGITAL_PORT0].logiclevel=0;
 
  port[PS2000A_DIGITAL_PORT1].enabled=0;
  port[PS2000A_DIGITAL_PORT1].logiclevel=0;

  ndirections=16; // PS2000A_MAX_DIGITAL_CHANNELS is 32 this is wrong for our device

  // Setup default directions
  for(i=0;i<ndirections;i++)
    {
      directions[i].channel=(PS2000A_DIGITAL_CHANNEL)i; // PS2000A_DIGITAL_CHANNEL_0 starts at 0 so this works
      directions[i].direction=PS2000A_DIGITAL_DONT_CARE;
    }

  nconditions=8; // Setup some conditions to false

  for(i=0;i<nconditions;i++)
    {
      cond[i].channelA=PS2000A_CONDITION_FALSE;
      cond[i].channelB=PS2000A_CONDITION_FALSE;
      cond[i].channelC=PS2000A_CONDITION_FALSE;
      cond[i].channelD=PS2000A_CONDITION_FALSE;
      cond[i].external=PS2000A_CONDITION_FALSE;
      cond[i].aux=PS2000A_CONDITION_FALSE;
      cond[i].pulseWidthQualifier=PS2000A_CONDITION_FALSE;
      cond[i].digital=PS2000A_CONDITION_FALSE;
    }

  // Setup 1 channel digital trigger condition
  cond[0].digital=PS2000A_CONDITION_TRUE;

  // / Setup a map to Convert range setting to a string, used by GUI callback
  range2str[PS2000A_10MV]="10mV";
  range2str[PS2000A_20MV]="20mV";
  range2str[PS2000A_50MV]="50mV";
  range2str[PS2000A_100MV]="100mV";
  range2str[PS2000A_200MV]="200mV";
  range2str[PS2000A_500MV]="500mv";
  range2str[PS2000A_1V]="1V";
  range2str[PS2000A_2V]="2V";
  range2str[PS2000A_5V]="5V";
  range2str[PS2000A_10V]="10V";
  range2str[PS2000A_20V]="20V";
  range2str[PS2000A_50V]="50V";

  //  Setup a map to convert a string to a range setting, used by functions that support the GUI
  str2range["10mV"]=PS2000A_10MV;
  str2range["20mV"]=PS2000A_20MV;
  str2range["50mV"]=PS2000A_50MV;
  str2range["100mV"]=PS2000A_100MV;
  str2range["200mV"]=PS2000A_200MV;
  str2range["500mV"]=PS2000A_500MV;
  str2range["1V"]=PS2000A_1V;
  str2range["2V"]=PS2000A_2V;
  str2range["5V"]=PS2000A_5V;
  str2range["10V"]=PS2000A_10V;
  str2range["20V"]=PS2000A_20V;
  str2range["50V"]=PS2000A_50V;

  // Setup a map to convert direction strings to enums, used by functions that support the GUI
  str2direction["DNT_CARE"]=PS2000A_DIGITAL_DONT_CARE;
  str2direction["LOW"]=PS2000A_DIGITAL_DIRECTION_LOW;
  str2direction["HIGH"]=PS2000A_DIGITAL_DIRECTION_HIGH;
  str2direction["RISING"]=PS2000A_DIGITAL_DIRECTION_RISING;
  str2direction["FALLING"]=PS2000A_DIGITAL_DIRECTION_FALLING;
  str2direction["R or F"]=PS2000A_DIGITAL_DIRECTION_RISING_OR_FALLING;

  handle=0; // Set default handle
}

Device::~Device()
{
  // Device buffer port 0
  if(devBuff[0]!=NULL)
    delete devBuff[0];
  // Device buffer port 1
  if(devBuff[1]!=NULL)
    delete devBuff[1];

// Application buffer port 0 and 1
  if(appBuff[0]!=NULL)
    delete appBuff[0];

  if(appBuff[1]!=NULL)
    delete appBuff[1];
}

bool Device::openDevice()
{
  PICO_STATUS stat;
 
  stat=ps2000aOpenUnit(&handle,NULL);


  if(stat==PICO_OK)
    {
      LogMessage("Connected to device! ps2000aOpenUnit()\n");
      return true;
    }

  LogMessage("Handle %d\n",handle);
  LogMessage("PICO Status %d\n",stat);

  return false;
}

bool Device::closeDevice()
{
  PICO_STATUS stat;
 
  stat=ps2000aCloseUnit(handle);

  if(stat==PICO_OK)
    {     
      LogMessage("Disconnected from device! ps2000aCloseUnit()\n");
      return true;
    }

  LogMessage("Handle %d\n",handle);
  LogMessage("PICO Status %d\n",stat);

  return false;
}



bool Device::setChannel(PS2000A_CHANNEL ch)
{
  PICO_STATUS stat;
 
  stat=ps2000aSetChannel(
          handle,
          ch,
          channel[ch].enabled,
          channel[ch].type,
          channel[ch].range,
          channel[ch].analogOffset
          );

     
  if(stat==PICO_OK)
      LogMessage("Configured Channel %d, ps2000aSetChannel()\n",ch);
  else
    {
      LogMessage("PICO Status %d\n",stat);
      return false;
    }


  // We need channel conditions for triggering
  stat=ps2000aSetTriggerChannelConditions(handle,cond,nconditions);

  if(stat==PICO_OK)
      LogMessage("ps2000aSetTriggerChannelConditions()\n");
  else
    {
      LogMessage("PICO Status %d\n",stat);
      return false;
    }


  return true;

}

bool Device::setDirections()
{
  PICO_STATUS stat;
 

  stat=ps2000aSetTriggerDigitalPortProperties(
                     handle,
                     directions,
                     ndirections
                     );

     
  if(stat==PICO_OK)
      LogMessage("Setup digital trigger directions\nps2000aSetTriggerDigitalPortProperties()\n");
  else
    {
      LogMessage("PICO Status %d\n",stat);
      return false;
    }

  /* // This is a bugfix to get digital triggering working but our scope do not have this functionality??
  stat=ps2000aSetDigitalAnalogTriggerOperand(handle,PS2000A_OPERAND_OR);

  if(stat==PICO_OK)
    LogMessage("ps2000aSetDigitalAnalogTriggerOperand()");
  else
    {
      LogMessage("PICO Status %d\n",stat);
      return false;
    }
  */
  return true;
}

bool Device::setDigitalPort(PS2000A_DIGITAL_PORT p)
{
  PICO_STATUS stat;
 
  stat=ps2000aSetDigitalPort(
              handle,
              p,
              port[p].enabled,
              port[p].logiclevel
              );

     
  if(stat==PICO_OK)
    {
      LogMessage("Configured digital port %d, ps2000aSetDigitalPort()\n",p);
      return true;
    }

  LogMessage("PICO Status %d\n",stat);
 
  return false;
}

bool Device::setDataDevBuffer(int32_t ch)
{
  PICO_STATUS stat;
 
  if(ch==PS2000A_DIGITAL_PORT0)
    {
      stat=ps2000aSetDataBuffer
   (
    handle,
    ch,
    devBuff[0],
    dev_buff_len[0],
    0,
    downSampleRatioMode
    );
    }

  if(ch==PS2000A_DIGITAL_PORT1)
    {
      stat=ps2000aSetDataBuffer
   (
    handle,
    ch,
    devBuff[1],
    dev_buff_len[1],
    0,
    downSampleRatioMode
    );
    }

   if(stat==PICO_OK)
    {
      devbuffer_set=true; // We have set the data buffer up!
      LogMessage("Set data buffer! ps2000aSetDataBuffer()\n");
      return true;
    }
   else
     {
       devbuffer_set=false; // We failed to set the data buffer up!
       LogMessage("Failed to set the data buffer\n");
       LogMessage("channel 0x%04X\n",ch);
       LogMessage("devBuff[0] %p\n",devBuff[0]);
       LogMessage("devBuff[1] %p\n",devBuff[1]);
       LogMessage("dev_buff_len[0] %d\n",dev_buff_len[0]);
       LogMessage("dev_buff_len[1] %d\n",dev_buff_len[1]);
       LogMessage("segments %d\n",segments);
       LogMessage("downsample ratio mode %d\n",downSampleRatioMode);
     }

  LogMessage("PICO Status %d\n",stat);

  return false;
}


bool Device::startStreaming()
{
  PICO_STATUS stat;
  if(devbuffer_set)
    {
      used_sample_interval=requsted_sample_interval;

      stat=ps2000aRunStreaming
   (
    handle,
    &used_sample_interval,
    sample_interval_time_unit,
    maxPreTriggerSamples,
    maxPostTriggerSamples,
    autoStop,
    downSampleRatio,
    downSampleRatioMode,
    dev_buff_len[present_port_ind]
    );
     
      if(stat==PICO_OK)
   {
     LogMessage("Start streaming! ps2000aRunStreaming()\n");

     scopeProcess0_sig.message="GS";         // Tell process task to copy data stream
     SDL_CondSignal(scopeProcess0_sig.cond); // Send signal

     return true;
   }

      LogMessage("PICO Status %d\n",stat);
    }
  else
    LogMessage("No data buffer allocated\n");

  return false;
}

bool Device::stopStreaming()
{
  PICO_STATUS stat;

  stat=ps2000aStop(handle);

   if(stat==PICO_OK)
    {
      devbuffer_set=false;    
      scopeProcess0_sig.message="NONE"; // Tell process task to stop copying the data stream
                                        // No signal needed
      LogMessage("Stop streaming!, ps2000aStop()\n");
      return true;
    }

  LogMessage("PICO Status %d\n",stat);

  return false;
}

// Data is ready for transfer from scope
// Not part of the device object
void lpPs2000AReady(
          int16_t handle,
          int32_t noOfSamples,
          uint32_t startIndex,
          int16_t overflow,
          uint32_t triggerAt,
          int16_t triggered,
          int16_t autoStop,
          void *nParameter
          )
{
  dev->func_lpPs2000AReady(
            handle,
            noOfSamples,
            startIndex,
            overflow,
            triggerAt,
            triggered,
            autoStop,
            nParameter
            ); // Call our own device class function
}

bool Device::getStream()
{
  PICO_STATUS stat;

    stat=ps2000aGetStreamingLatestValues
    (
     handle,
     lpPs2000AReady,
     NULL
     );

  if(stat==PICO_OK)
    {
      return true;
    }

  return false;
}

void Device::func_lpPs2000AReady( 
             int16_t handle,
             int32_t noOfSamples,
             uint32_t startIndex,
             int16_t overflow,
             uint32_t triggerAt,
             int16_t triggered,
             int16_t autoStop,
             void *nParameter
               )
{

  memcpy(&appBuff[present_port_ind][startIndex],&devBuff[present_port_ind][startIndex],noOfSamples*sizeof(int16_t));

  /*
  printf("nandle %d\n",handle);
  printf("noOfSamples %d\n",noOfSamples);
  printf("startIndex  %d\n",startIndex);
  printf("overflow    %d\n",overflow);
  */

  if(triggered>0)
    printf("trigger!\n");

}

unsigned int Device::getNoSamples()
{
PICO_STATUS stat;
uint32_t noOfValues;

stat=ps2000aNoOfStreamingValues
      (
       handle,
       &noOfValues
       );

  if(stat==PICO_OK)
    {
      LogMessage("Number of samples available %d\n",noOfValues);
    }
  else
     LogMessage("Failed to get number of samples\n");

  return noOfValues;

}

void Device::getDataPointer(int16_t **ap,uint32_t *len)
{
  *ap = appBuff[present_port_ind];
  *len = dev_buff_len[present_port_ind];
}

void Device::maplist2Channel(PS2000A_CHANNEL ch,const char *key,Value *v)
{

  if(!strcmp(key,"enabled"))
    {
      if(v->value=="Enabled")
   channel[ch].enabled=1;
      else
   channel[ch].enabled=0;
    }

  if(!strcmp(key,"type"))
    {
      if(v->value=="AC")
   channel[ch].type=PS2000A_AC;
      else
   channel[ch].type=PS2000A_DC;
    }
 
  if(!strcmp(key,"range"))
    {
      channel[ch].range=(PS2000A_RANGE)str2range[v->value];
    }

  if(!strcmp(key,"offset"))
    channel[ch].analogOffset=0.0f;


  setChannel(ch); // Apply to device
}

void Device::maplist2Directions(const char *key,Value *v,int offset)
{
  // Modify direction array
  directions[v->position+offset].direction=(PS2000A_DIGITAL_DIRECTION)str2direction[v->value];

  LogMessage("Digital channel %d\n",v->position+offset);
  LogMessage("Direction str   %s\n",v->value.c_str());
  LogMessage("Direction enum  %d\n",(PS2000A_DIGITAL_DIRECTION)str2direction[v->value]);
 
  setDirections(); // Update directions
}

// Return the used sampling rate as a string
string Device::getSamplingRateStr()
{
  double freq;
  string rate;
  char tmp[20];

  freq=1.0/(unit2factor[sample_interval_time_unit]*((double)dev->used_sample_interval));

  ValueHz(freq,tmp);

  rate=tmp;

  return rate;
}

void Device::ValueHz(double val,char *str)
{
  if(fabs(val)<999e3)
    {
      sprintf(str,"%09.3f/[KHz]",val*1.0e-3);
      return;
    }

  if(fabs(val)<999e6)
    {
      sprintf(str,"%09.3f/[MHz]",val*1.0e-6);
      return;
    }

  if(fabs(val)<999e9)
    {
      sprintf(str,"%09.3f/[GHz]",val*1.0e-9);
      return;
    }


  sprintf(str,"%09.3f/[THz]",val*1.0e-9);

  return;
}

bool Device::getMaxDownsampling()
{
  PICO_STATUS stat;
 
  stat=ps2000aGetMaxDownSampleRatio
   (
    handle,
    dev_buff_len[present_port_ind]*downSampleRatio,
    &maxDownSampleRatio,
    downSampleRatioMode,
    0
    );

  if(stat==PICO_OK)
    {
      LogMessage("Maximum downsampling ratio: %d, ps2000aGetMaxDownSampleRatio()\n",maxDownSampleRatio);
      return true;
    }

  LogMessage("PICO Status %d\n",stat);

  return false;
}
mrrg
Newbie
 
Posts: 0
Joined: Mon Nov 14, 2016 4:44 pm

Re: Digital Triggering

Postby Hitesh » Thu Dec 01, 2016 4:12 pm

Hi mrrg,

Apologies for the delay in getting back to you.

Just to confirm, are you using a PicoScope 2205 MSO (light blue case) or a PicoScope 2205A MSO (small form factor with dark blue case)?

Which version of the PS2000A Linux Driver are you using? Have you updated to using the latest available libps2000a package?

If you are able to provide information on the actual parameter values passed to the following function calls (including structure fields), I can try to reproduce the problem here:

  • ps2000aSetChannel()
  • ps2000aSetDigitalPort()
  • ps2000aSetTriggerChannelConditions()
  • ps2000aSetTriggerDigitalPortProperties()
  • ps2000aSetDataBuffer()
  • ps2000aRunStreaming()

Many thanks,
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 General Software Discussions

Who is online

Users browsing this forum: No registered users and 0 guests