PicoScope 7 Software
Available on Windows, Mac and Linux
. I assume that is why it is ok with channel A but not digital.channelC, channelD, aux, digita: not used.
Code: Select all
cond[0].digital=PS2000A_CONDITION_TRUE;
Code: Select all
PS2000A_CONDITION_FALSE
Code: Select all
PICO_OK
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()
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
//#include
#include
#include
#include
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
#include
#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;ifunc_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;
}