Block mode not working properly in ps3000a - repost?

Post your Linux discussions here
Post Reply
alowell
Newbie
Posts: 0
Joined: Mon Sep 02, 2019 8:46 pm

Block mode not working properly in ps3000a - repost?

Post by alowell »

Sorry, I think I posted this in the Picoscope 6 for Linux forum, when it probably belongs here.

I'm seeing a strange freeze/hang with ps3000a block mode API. The code I wrote is shown below. The goal of the code is to acquire data on all four channels at 4 ns sample interval into the full 512 MS scope buffer, then to transfer that data to the PC, and then repeat. I'm finding that this all works for a few minutes, but then a call to ps3000aGetValues will hang indefinitely. On at least one occasion, the hang happened at ps3000aIsReady.

I'm on Ubuntu 20.04.3 LTS, using Picoscope driver libps3000a/now 2.1.54-6r2438 amd64 (as reported by apt).

Here is my code:

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;
}


Post Reply