PicoScope 7 Software
Available on Windows, Mac and Linux
Code: Select all
#include "libps3000a/ps3000aApi.h"
#include "libps3000a/PicoStatus.h"
#include
#include
#include
#include
using namespace std;
int main(void)
{
PICO_STATUS PS;
//open scope
int16_t Handle;
char Serial[] = "FU835/0008";
PS = ps3000aOpenUnit(&Handle,(int8_t*) Serial);
if(PS != PICO_OK)
{
printf("OpenUnit failed, PS = %d\n",PS);
return -1;
}
if(Handle <= 0)
{
printf("Invalid handle, handle = %d\n",Handle);
return -1;
}
//set channel
PS = ps3000aSetChannel(Handle,PS3000A_CHANNEL_A,1,PS3000A_AC,PS3000A_50MV,0); //1 -> TRUE
if(PS != PICO_OK)
{
printf("SetChannelA failed, PS = %d\n",PS);
return -1;
}
PS = ps3000aSetChannel(Handle,PS3000A_CHANNEL_B,1,PS3000A_AC,PS3000A_50MV,0); //1 -> TRUE
if(PS != PICO_OK)
{
printf("SetChannelB failed, PS = %d\n",PS);
return -1;
}
PS = ps3000aSetChannel(Handle,PS3000A_CHANNEL_C,1,PS3000A_AC,PS3000A_50MV,0); //1 -> TRUE
if(PS != PICO_OK)
{
printf("SetChannelC failed, PS = %d\n",PS);
return -1;
}
PS = ps3000aSetChannel(Handle,PS3000A_CHANNEL_D,1,PS3000A_AC,PS3000A_50MV,0); //1 -> TRUE
if(PS != PICO_OK)
{
printf("SetChannelD failed, PS = %d\n",PS);
return -1;
}
//set digital port (disable digital ports)
PS = ps3000aSetDigitalPort(Handle,PS3000A_DIGITAL_PORT0,0,0); //second from last zero -> FALSE
if(PS != PICO_OK)
{
printf("SetDigitalPort0 failed, PS = %d\n",PS);
return -1;
}
PS = ps3000aSetDigitalPort(Handle,PS3000A_DIGITAL_PORT1,0,0); //second from last zero -> FALSE
if(PS != PICO_OK)
{
printf("SetDigitalPort1 failed, PS = %d\n",PS);
return -1;
}
//get timebase
const int32_t N = 128000000;
uint32_t Timebase = 0;
for(uint32_t i = 0; i < 128; ++i)
{
int32_t Nanoseconds;
int32_t MaxSamples;
PS = ps3000aGetTimebase(Handle, i, N, &Nanoseconds, 0, &MaxSamples, 0);
printf("i = %u, Nanoseconds = %d, MaxSamples = %d\n",i,Nanoseconds,MaxSamples);
if(PS != PICO_OK)
{
printf("GetTimebase failed, PS = %d\n",PS);
}
if(Nanoseconds == 4)
{
Timebase = i;
break;
}
}
//trigger (disable)
//block mode fails without or without call to SetSimpleTrigger
PS = ps3000aSetSimpleTrigger(Handle,0,PS3000A_CHANNEL_A,0,PS3000A_RISING,0,1);
if(PS != PICO_OK)
{
printf("SetSimpleTrigger failed, PS = %d\n",PS);
return -1;
}
//SetDataBuffer
vector> Buffers(4,vector(N,0));
for(int i = 0; i < 4; ++i)
{
PS3000A_CHANNEL CH[4] = {PS3000A_CHANNEL_A,PS3000A_CHANNEL_B,PS3000A_CHANNEL_C,PS3000A_CHANNEL_D};
PS = ps3000aSetDataBuffer(Handle,CH[i],Buffers[i].data(),Buffers[i].size(),0,PS3000A_RATIO_MODE_NONE);
if(PS != PICO_OK)
{
printf("SetDataBuffer failed. i = %d, PS = %d\n",i,PS);
return -1;
}
}
while(1)
{
int32_t Ms;
PS = ps3000aRunBlock(Handle,N,0,Timebase,0,&Ms,0,NULL,NULL);
if(PS != PICO_OK)
{
printf("RunBlock failed, PS = %d\n",PS);
return -1;
}
printf("polling...\n");
while(1)
{
//poll
int16_t Ready;
PS = ps3000aIsReady(Handle,&Ready);
if(PS != PICO_OK)
{
printf("IsReady failed, PS = %d\n",PS);
return -1;
}
if(Ready)
break;
else
usleep(20000);
}
printf("samples ready.\n");
uint32_t NumSamples = N;
int16_t Overflow;
printf("Getting values...\n");
PS = ps3000aGetValues(Handle,0,&NumSamples,0,PS3000A_RATIO_MODE_NONE,0,&Overflow);
if(PS != PICO_OK)
{
printf("GetValues failed, PS = %d\n",PS);
return -1;
}
printf("N = %d, NumSamples = %u\n",N,NumSamples);
}
//close scope
return 0;
}