Multiple channels Streaming mode ps6000A

Post your C and C++ discussions here
Post Reply
victosan
Newbie
Posts: 1
Joined: Thu Jun 13, 2019 6:28 pm

Multiple channels Streaming mode ps6000A

Post by victosan »

Good morning,

I need to design a application that can stored continually the signal of the four channel of a picoscope model 6403DE. I designed a c code that I work perfectly when only one channel is activated. The problem is when I select 4 channels, then I receibed a status error in the ps6000aGetStreamingLatestValues() function:

// Data is unavailable because a run has not been completed.
#define PICO_NO_SAMPLES_AVAILABLE 0x00000025UL

Somebody have any idea of the reason of this error and why the oscilloscope it is not storing the raw data in the buffers?

Best regards,
Victor

Code: Select all

/* Headers for Windows */
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
//#include 
//#include 
//#include 
//#include 

#include 
#include  // para el timing

#define Sleep(a) usleep(1000*a)
#define scanf_s scanf
#define fscanf_s fscanf
#define memcpy_s(a,b,c,d) memcpy(a,c,d)

typedef enum enBOOL{FALSE,TRUE} BOOL;

int32_t cycles = 0;

#define BUFFER_SIZE 	10000 // Used for block and streaming mode examples

// AWG Parameters
#define	AWG_DAC_FREQUENCY		200e6
#define	AWG_PHASE_ACCUMULATOR	4294967296.0

int32_t _kbhit()
{
        struct termios oldt, newt;
        int32_t bytesWaiting;
        tcgetattr(STDIN_FILENO, &oldt);
        newt = oldt;
        newt.c_lflag &= ~( ICANON | ECHO );
        tcsetattr(STDIN_FILENO, TCSANOW, &newt);
        setbuf(stdin, NULL);
        ioctl(STDIN_FILENO, FIONREAD, &bytesWaiting);

        tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
        return bytesWaiting;
}

PICO_STATUS status;
int16_t handle;
int8_t  *serial;
int16_t inputRanges [11] = {10,20,50,100,200,500,1000,2000,5000,10000,20000};
PICO_DEVICE_RESOLUTION resolution;
PICO_CHANNEL ch,chmax;
PICO_CONNECT_PROBE_RANGE range;
PICO_COUPLING coupling;
PICO_BANDWIDTH_LIMITER bandwidth;
PICO_ACTION action,action2;
PICO_RATIO_MODE downsampling;
PICO_DATA_TYPE datatype; 
PICO_TIME_UNITS timeunits;


int main(void)
{

	int8_t * buffers[4];
	int8_t * appBuffers[4]; // Application buffers to copy data into
	float *  gauss[4]; 
	float    max,y1,y2,y3,ymax;
	int32_t  sampleCount= 525600000;
	uint64_t npulses[4],npulblock[4],npulin[4];
	int16_t triggg;
	int8_t  th;
	int16_t     g_autoStopped;
	double * sampleInterval;
	double sampleint;
	int16_t autoStop = FALSE;
	int32_t isum,ib,is,isp,istamp;
	int32_t isg,imax;
	int32_t ipul,ip;
	int32_t istop,istart;
	struct timeval timest;
	double tcpu, tcpuref, tcput,dif;
	double treal, trealref, trealt;
	double timestamp;
	double va,aka2;
        
	PICO_STREAMING_DATA_INFO data1,data2,data3,data4;
	PICO_STREAMING_DATA_INFO *kk;
	//= [{data1,data2,data3,data4}];
	PICO_STREAMING_DATA_TRIGGER_INFO kk2;
	
	FILE * pulsesfile[4];
	FILE * binary_out_file;
        // OPEN THE OSCILLOSCOPE        
        serial=NULL;
	status = ps6000aOpenUnit(&handle,serial,resolution);
	if (status == PICO_OK)
	{
		printf(" PICO CONECTED \n");
		printf(" %d \n",handle);
	}

	//Open Files
	
	pulsesfile[0] = fopen("c0.txt", "w");  // w for write, b for binary
        pulsesfile[1] = fopen("c1.txt", "w");  // w for write, b for binary
        pulsesfile[2] = fopen("c2.txt", "w");  // w for write, b for binary
        pulsesfile[3] = fopen("c3.txt", "w");  // w for write, b for binary
        binary_out_file = fopen("out.stream", "wb");

	// Define the channel propierties
	
	coupling = PICO_DC_50OHM;	
        range = 5;
        bandwidth = PICO_BW_FULL;
        aka2 = 20;
        chmax = PICO_CHANNEL_E; // Canales maximo
        
        for (ch = PICO_CHANNEL_A; ch < chmax; ch++)
        {
        	status = ps6000aSetChannelOn(handle,ch,coupling,range,0,bandwidth);
        }
        
        // Charge the buffers where we store the data
        
        action = PICO_CLEAR_ALL | PICO_ADD;
        action2 = PICO_ADD;
        downsampling = PICO_RATIO_MODE_RAW;
        datatype = PICO_INT8_T;
        
        for (ch = PICO_CHANNEL_A; ch < chmax; ch++) // create data buffers
	{        	
        	npulses[ch]=0;
	      	buffers[ch] = (int8_t*) calloc(sampleCount, sizeof(int8_t));
		status = ps6000aSetDataBuffer(handle,ch,buffers[ch],sampleCount,0,datatype,downsampling,action);
		printf(" %hi \n",status);
		gauss[ch] = (float*) calloc(sampleCount, sizeof(float));
		npulses[ch]=0;
	}
	
	// Define the pointer where the information of the buffer is stored 
	
	kk = (PICO_STREAMING_DATA_INFO*) calloc(chmax,sizeof(PICO_STREAMING_DATA_INFO));

	// Define the trigger for the signals
	
	printf("Voltage Channels %d V \n",inputRanges[range]);

        printf("Select Trigger mV \n");
        scanf("%hd",&triggg);
        printf("Trigger %i mV\n",triggg); 
        
        th=  triggg * 127/inputRanges[range];
        printf("Trigger %hd bit\n",th); 
        
        
        // Inicate the streaming capture
        
        g_autoStopped = FALSE;
        
        sampleint = 64;
        sampleInterval = &sampleint;
        timeunits=PICO_NS;
        
        status = ps6000aRunStreaming(handle,sampleInterval,timeunits,0,sampleCount,autoStop,1,downsampling);

	printf(" RunStreaming Status: %hi \n",status);
	
	
	for (ch = PICO_CHANNEL_A; ch < chmax; ch++) // create data buffers
	{  
		kk[ch].channel_ = ch;	
		kk[ch].type_ = datatype;
		kk[ch].mode_ = downsampling;
		kk[ch].noOfSamples_ = 100;
		kk[ch].startIndex_ = 0;
		kk[ch].overflow_ = 0;
	}
	
	kk2.triggerAt_ = 0;
	kk2.triggered_ = 0;
	kk2.autoStop_ = 0;
	ib=0;	
	
	// Start the computer clock 
	
	gettimeofday(&timest,NULL);
	va=timest.tv_sec+timest.tv_usec/1.e6;
        tcpuref=va;
        trealt=0.;

        
        while (!_kbhit() && !g_autoStopped) // streaming mientras no se toca teclado o no se para solo
	{
		//  Define the time of the computer
		
		usleep(2000000); 
		
		gettimeofday(&timest,NULL);   // Computer Time
		
		va=timest.tv_sec+timest.tv_usec/1.e6;
		tcpu=va-tcpuref;  // tiempo real desde el ultimo trozo de adquisicion
		tcput=tcput+tcpu;
		tcpuref=va;
  		
  		// Call the streaming data  RAW
  		   
		status = ps6000aGetStreamingLatestValues(handle,kk,chmax,&kk2);
		
		printf("Get Values Status: %hi \n",status);
		
		//  Value of the oscilloscope clock 
		
		trealref=trealt;
              	treal=kk[0].noOfSamples_*sampleint*1.e-9;   // tlive contenido en este trozo de adquisicion
       	trealt=treal+trealt;                      //tlive acumulado       	    	

		for (ch = PICO_CHANNEL_A; ch < chmax; ch++) // Signal Analysis 
		{
			npulblock [ch] = 0;
			npulin [ch] = 0;
			
			printf("Vic %d %d %d \n",kk[ch].channel_,kk[ch].noOfSamples_,kk[ch].startIndex_); // control of the buffer filling
			
			for (is=kk[ch].startIndex_; is < kk[ch].startIndex_+kk[ch].noOfSamples_-1; is++ )                            			
			{
				gauss[ch][is]=0;
               	}
               
 	 		ip=0;

			for (is=kk[ch].startIndex_; is < kk[ch].startIndex_+kk[ch].noOfSamples_-1; is++ )
			{
			        // Looking for the signal triggered
			        
				if(buffers[ch][is] > th && ip == 0)
				{
					max=-1000.;
					istamp=is;
					ip=1;
				}
				
				if((buffers[ch][is] < th && ip == 1))
				{
					istop=is;
					ip=0;
					dif=(istop-istamp)*sampleint;
					npulblock[ch]=npulblock[ch]+1;
					if( dif > 1000)
					{
						npulses[ch]=npulses[ch]+1;
						dif=0;
						for(isg = istamp-20;isg < istamp+100;isg++)
             					{ 
							gauss[ch][isg]=((aka2+2*aka2*aka2)*gauss[ch][isg-1]-aka2*aka2*gauss[ch][isg-2]+2*buffers[ch][isg])/(1.+aka2+aka2*aka2);
               	               	      	if(gauss[ch][isg] > max)
               	               	      	{
								max=gauss[ch][isg];
               	               	         	imax=isg;
               	               	         }
						}
						npulin[ch]=npulin[ch]+1;
						y1=gauss[ch][imax-1];
                               		y2=gauss[ch][imax];
           	               		y3=gauss[ch][imax+1];
						ymax=((y3-y1)*(y3-y1))/(16*(y3+y1)/2-y2)+y2;
				
						if(npulses[ch] < 10)
						{
							ipul=0;
							for( isp = istamp - 20; isp < istamp + 100; isp++)
							{
								ipul++;
								fprintf(pulsesfile[ch]," %i %i %f\n", ipul,buffers[ch][isp],gauss[ch][isp]);
							}
						}
						timestamp = trealref+((istamp-kk[ch].startIndex_)*sampleint*1.e-9);
						fwrite(&ch,sizeof(int16_t),1,binary_out_file);
						fwrite(&timestamp,sizeof(double),1,binary_out_file);
						fwrite(&ymax,sizeof(float),1,binary_out_file);
					}	
				}
			
			}
			// Restare the buffer if is filled
			if(status != PICO_OK)
			{ 
				status = ps6000aSetDataBuffer(handle,ch,buffers[ch],sampleCount,0,datatype,downsampling,action2);
			}		
		}
		
		// Control of the evolution of the computer clock vs oscilloscope clock
		
		printf("%.6f %.6f %.6f %.6f Time CPU Time Pico Diff \n",tcput,trealt,trealref,trealt-tcput);
		//
		//printf("%ld \n",npulin[0]);

	}	
	
	for (ch = PICO_CHANNEL_A; ch < PICO_CHANNEL_E; ch++) // create data buffers
	{  
		fclose(pulsesfile[ch]);
	}
	fclose(binary_out_file);
	
	status = ps6000aStop(handle);
	printf("Stopt Status: %hi \n",status);
	status = ps6000aCloseUnit(handle);
	printf("Close Status: %hi \n",status);
}

Post Reply