Pico 4424 - ps4000GetValues

Post your C and C++ discussions here
Post Reply
danis_rom
Newbie
Posts: 0
Joined: Wed Oct 19, 2016 2:53 pm

Pico 4424 - ps4000GetValues

Post by danis_rom »

Hello,
I'm using this code to read data from scope:

Code: Select all

typedef struct 
{
	int16_t handle;
	int *ptrIdPicoDevice;
	int state;// 0 - waiting for trigger/values read, 1- values are in buffer
	int armed;// 1 - a read operation was started for this device
	int16_t *buffers[MAX_NR_PICO_CHANNELS]; // array of buffer for data
	int sampleCount; //nr samples allocated in buffers
	int sampleCountRead;
	int channels[MAX_NR_PICO_CHANNELS];
	int inputRange[MAX_NR_PICO_CHANNELS];
	double sampleRate; //sample rate at which measurement will start
	double triggerPreTrigerSamples;
	int timeout; // trigger timeout
	double startTime; // time when trigger started
	int triggered;// =1 trigger was fired
}StructPicoDeviceState;

 // Pico definition
typedef struct
{
	int idPicoDevice;
	char PicoDeviceName[MAX_SIZE_NAME];
	int model; 
	char serialNr[MAX_PICO_NAME];
	int signalGenerator; //
	int ETS;  // Equivalent Time Sampling
	int firstRange;
	int lastRange;
	int channelCount; //nr of channels
	char calibrationDate[MAX_PICO_NAME];
}StructPicoDevice;

void readPico(int idPicoDevice)
{
	StructPicoDeviceState picoDeviceState;
	int rc=0, i;
	PICO_STATUS status;
	uint32_t sampleCountRead;
	int16_t * buffer;
	StructPicoDevice PicoDevice;

	//get handle from Hash table
	rc=HashTableGetItem(hashPicoTable ,&idPicoDevice , &picoDeviceState, sizeof(StructPicoDeviceState));
	rc = getPicoDeviceById(tablePicoDevice, idPicoDevice, &PicoDevice);

	//==== set channel buffer ====
	for (i = 0; i < PicoDevice.channelCount; i++) 
	{	
		if(picoDeviceState.channels[i])
		{
			if(picoDeviceState.buffers[i] == 0)
				//alloc buffer where values will be saved
				buffer = (int16_t*) malloc(picoDeviceState.sampleCount * sizeof(int16_t));
			else
				buffer = picoDeviceState.buffers[i];
			
			memset(buffer,0, picoDeviceState.sampleCount * sizeof(int16_t));
			
			status =  ps4000SetDataBuffer(picoDeviceState.handle,
																		(PS4000_CHANNEL) i,
																		buffer,
																		picoDeviceState.sampleCount
																		);	
			picoDeviceState.buffers[i] = buffer;
		}
	}

	//read data from buffers
	if((status = ps4000GetValues(picoDeviceState.handle, 0 , &sampleCountRead, 1, 0, 0, NULL)) != PICO_OK)
	{
		rc= -1;
		picoDeviceState.sampleCountRead = -1 ;
	}
	else
	{
		picoDeviceState.sampleCountRead = sampleCountRead;
	}
	
	HashTableInsertItem(hashPicoTable, &idPicoDevice, &picoDeviceState); 	
	return ;
}
before that, I configured and started the device with ps4000SetChannel, ps4000RunBlock , like in "ps4000con.c"

Is working good, but sometimes I receive error code 13 when calling ps4000GetValues.

I know that this error PICO_INVALID_PARAMETER means, but I don't understand what could go wrong.

I use:
PicoScope® 6 - PC-Oszilloskop-Software Version: 6.11.12.1692
Copyright © 1995-2016, Pico Technology Ltd.

Modell: PicoScope 4424
Seriennummer: AZ808/068
USB-Version: 2,0
Kalibrierungsdatum: Dienstag, 9. Oktober 2012
Hardwareversion: 1
Treiberversion: 1.2.6.4
Firmwareversion: 1.0.5.0 / 1.0.7.0

Greatings,

Daniel

danis_rom
Newbie
Posts: 0
Joined: Wed Oct 19, 2016 2:53 pm

Re: Pico 4424 - ps4000GetValues

Post by danis_rom »

I made some examples with different ways of reading Values.

Try 1.
Function_Start_Read_Pico

- ps4000SetChannel
-ps4000GetTimebase
-ps4000RunBlock(...,CallBackBlock,..)

wait for values:
while (gState==0)
DelayWithEventProcessing(0.1);

-ps4000SetDataBuffer
-ps4000GetValues

In this case I always get the values


Try 2 - I use 2 functions:
1.Function_Start_Pico

- ps4000SetChannel
-ps4000GetTimebase
-ps4000RunBlock(...,CallBackBlock,..)

2. Function_Read_Pico

wait for values:
while (gState==0)
DelayWithEventProcessing(0.1);

-ps4000SetDataBuffer
-ps4000GetValues

In this case I get sometimes error 13 from ps4000GetValues.
I tried on 3 Computers, and sometime returns 13 when calling ps4000GetValues

Martyn
Site Admin
Site Admin
Posts: 4491
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: Pico 4424 - ps4000GetValues

Post by Martyn »

I would suggest trying with a value assigned to sampleCountRead.
Martyn
Technical Support Manager

danis_rom
Newbie
Posts: 0
Joined: Wed Oct 19, 2016 2:53 pm

Re: Pico 4424 - ps4000GetValues

Post by danis_rom »

Hello Martyn,

I just found my error in code and wanted to write it here, but I see you just suggest it. :)
Yes this was the Problem, the variable sampleCountRead had different values (not initialized) and pointed to different values ...

Extract from Help:
noOfSamples, on entry: the number of samples requested; on exit,
the number of samples actually returned.
Thank you for your support,

Daniel

Post Reply