Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Samples lost

Hello,

I use NI DAQ PCI 6533 DIO card and i have a strange behaviour. I must acquire 2142 bytes when i push a button on hardware board.

I try to acquire them by DAQmx_Val_ContSamps and by DAQmx_Val_FiniteSamps. And both doesn't work. When i use ContSamps i lose 2 samples on the end of the acquisition. There are on PCI board buffer and i can't take them. If i use FiniteSamps, i must push 3 times the button for start the acquisition and it's not okay. I do while loop to acquire samples and in ContSamps i only push 1 times button and it's okay but 2 samples are missing.

With the ContSamps i used thsi code :

 

fichier=fopen(nom_fichier,"wb");
DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
DAQmxErrChk (DAQmxCreateDIChan(taskHandle,"Dev1/port0","",DAQmx_Val_ChanForAllLines));
DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"/Dev1/PFI2",1844674407370955161,DAQmx_Val_Rising,DAQmx_Val_ContSamps,100));
DAQmxErrChk (DAQmxCfgDigEdgeStartTrig(taskHandle,"/Dev1/PFI6",DAQmx_Val_Falling));
DAQmxErrChk (DAQmxCfgInputBuffer(taskHandle,50000000));
DAQmxErrChk (DAQmxSetReadOverWrite(taskHandle,DAQmx_Val_OverwriteUnreadSamps));
DAQmxErrChk (DAQmxSetReadRelativeTo(taskHandle,DAQmx_Val_CurrReadPos));
DAQmxErrChk (DAQmxStartTask(taskHandle));
while(escape==0)
{DAQmxErrChk (DAQmxReadDigitalU8(taskHandle,-1,0.001,DAQmx_Val_GroupByChannel,data,1000,&sampsRead,NULL));

if( sampsRead>0 )
{
totalRead_tmp += sampsRead;
totalRead+= sampsRead;
Progressbar_read+= sampsRead;
strcpy(phrase,"Acquisition de : ");
sprintf(nombre,"%lld",totalRead);
strcat(phrase,nombre);
strcat(phrase," données");
if(nb>1)
{ item = (int)SendMessage(hCtrl, LB_GETCOUNT, 0, 0);
SendMessage(hCtrl, LB_DELETESTRING,item-2, 0);
SendMessage(hCtrl, LB_INSERTSTRING, item-2, (LPARAM)(LPCTSTR)phrase);}
else
{ item = (int)SendMessage(hCtrl, LB_GETCOUNT, 0, 0);
SendMessage(hCtrl, LB_DELETESTRING,item-(nb+1), 0);
SendMessage(hCtrl, LB_INSERTSTRING, item-(nb+1), (LPARAM)(LPCTSTR)phrase);}

fwrite(data,1,sampsRead,fichier);
nb_rec++;
}}
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);

i tried to change few parameter like sampsPerChanToAcquire and samplesMode and rate(DAQmxCfgSampClkTiming), numSampsPerChan arraySizeInSamps (DAQmxReadDigitalU8) DAQmxReadRelativeTo and ReadOverWrite but no sucess.

I hope find the answer here.

Thanks.

Jeremy

 

0 Kudos
Message 1 of 4
(6,282 Views)

I test with the example of NI but no sucess. It had 2 samples lost but i find them for the next acquistion.

/*********************************************************************
*
* ANSI C Example program:
*    ReadDigPort.c
*
* Example Category:
*    DI
*
* Description:
*    This example demonstrates how to read values from a digital
*    input port.
*
* Instructions for Running:
*    1. Select the digital port on the DAQ device to be read.
*    Note: The Data Read indicator is in hexadecimal.
*
* Steps:
*    1. Create a task.
*    2. Create a Digital Input channel. Use one channel for all
*       lines. In this case, the port itself acts as an individual
*       channel.
*    3. Call the Start function to start the task.
*    4. Read the digital data. This read function reads a single
*       sample of digital data on demand, so no timeout is necessary.
*    5. Call the Clear Task function to clear the Task.
*    6. Display an error if any.
*
* I/O Connections Overview:
*    Make sure your signal input terminals match the Port I/O
*    Control. In this case wire your digital signals to the first N
*    digital lines on your DAQ Device.
*
*********************************************************************/

#include <stdio.h>
#include <NIDAQmx.h>

#define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else

int main(void)
{
	/*********************************************/
	// 1. Variable Definitions
	/*********************************************/
	int32			error=0;				// Error Number
	char			errBuff[2048]={'\0'};   // Error Buffer
	TaskHandle		taskHandleIn=0;			// Reading Task Handle
	uInt8			dataIn[3000]={0};		// Read Buffer
	int32			read;					// Bytes Read
	int32			written;				// Bytes Written
	int i=0;								// Count Variable	
	int j=0;								// Count Variable
	/*********************************************/
	// 2. Fill Output Buffer with Sequential Data
	/*********************************************/
	
	/*********************************************/
	// 3. DAQmx Configure Code
	/*********************************************/
	//Create Tasks
	DAQmxErrChk (DAQmxCreateTask("In",&taskHandleIn));
	//Create DI and DO Channels
	DAQmxErrChk (DAQmxCreateDIChan(taskHandleIn,"Dev1/port0","",DAQmx_Val_ChanForAllLines));
	//Import Clock Config
	DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandleIn,"PFI2",10000000,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,2142));
	//Configure Read Start Trigger
    //DAQmxErrChk (DAQmxCfgDigEdgeStartTrig(taskHandleIn,"PFI6",DAQmx_Val_Falling));
	/*********************************************/
	// 5. DAQmx Start Code
	/*********************************************/
	DAQmxErrChk (DAQmxStartTask(taskHandleIn));
	/*********************************************/
	// 6. DAQmx Read Code
	/*********************************************/
	DAQmxErrChk (DAQmxReadDigitalU8(taskHandleIn,2142,20.0,DAQmx_Val_GroupByChannel,dataIn,2142,&read,NULL));
	/*********************************************/
	// 7. Print Read Data
	/*********************************************/
	printf("Press any key to see read data...\n");
	getchar();
	while(j < 2142)
	{
	printf("dataIn: %X\n", dataIn[j]);
	j++;
	}
	/*********************************************/
	// 8. Error Handling and Exit Code
	/*********************************************/
Error:
	if( DAQmxFailed(error) )
		DAQmxGetExtendedErrorInfo(errBuff,2048);
	if( taskHandleIn!=0 ) {
		/*********************************************/
		// 9. DAQmx Stop Code
		/*********************************************/
		DAQmxStopTask(taskHandleIn);
		DAQmxClearTask(taskHandleIn);
	}
	if( DAQmxFailed(error) )
		printf("DAQmx Error: %s\n",errBuff);
	printf("End of program, press Enter key to quit\n");
	getchar();
	return 0;
}

 

It's the most esay program and it doesn't work. I don't find more idea of you can help me.

 

Is it my PCI card which have a problem?

0 Kudos
Message 2 of 4
(6,275 Views)

We find a curious thing. The board does correctly the acquisition of 2142 samples in falling edge but not in Rising edge.And we must do the acquistion on the rising edge. So we invert the clock, and now the rising Edge works but not Falling Edge. How it's possible. My data are correctly transmitted to the PCI card. We look it whit a logic analyser and look for any glitch but we found anything.

Please help us because the acquistion must work in 2 weeks and we tried many options or configuration for the 6533 card.

0 Kudos
Message 3 of 4
(6,231 Views)

I found a solution. My problem was i triggered on rising edge of the trigger signal (active low signal). And the trigger didn't go from high to low for the last samples. And if i trigger on the rising edge of my signal, this signal must go down after for i can take the last sample.

This problem is resolve but now i have a new problem.

I acquire a finite sample (2142 samples) but i want do this acquisition more times. And if i stop the task and start again the task, i lost the next data packet. I need to find a solution for restart the acquisition or retriggerable the acquisition. It's always 2142 samples per packet but i don't know the number of these packets.

And if i do a constant acquistion, i always have 2 samples lost (for acquistion in 8 bits or 16 bits) and 1 sample lost (for acquisition in 32 bits).

Can i decrease the time between the stop task and the start task (when i restart the task)?

I hope to find help here !!

Jeremy.

0 Kudos
Message 4 of 4
(6,142 Views)