Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Linear Position reading zero in C

New to using NIDAQmx. I need to do a simple test and log some linear position readings from a quadrature encoder. I create a task in Measurement & Automation Explorer in which I create a Linear Position channel and configure as shown below. I can see that my encoder readings are correct.

But what I need to do is log this data, so following the ANSI C examples I wrote a small C program to open this task and read. But every reading returns 0.

I'm sure I'm missing something very simple, how can I read the data from this task? Thanks

 

        int32		error=0;
	TaskHandle	taskHandle=0;
	float64		data;
	char		errBuff[2048]={'\0'};
	int32		read;

	/*********************************************/
	// DAQmx Configure Code
	/*********************************************/
        DAQmxErrChk(DAQmxLoadTask("MyLinearPositionTask", &taskHandle));

	/*********************************************/
	// DAQmx Start Code
	/*********************************************/
	DAQmxErrChk (DAQmxStartTask(taskHandle));

	/*********************************************/
	// DAQmx Read Code
	/*********************************************/
	uInt32 numSamples;
	DAQmxGetReadAvailSampPerChan(taskHandle, &numSamples);
	while (1)
	{
//data is always 0 DAQmxErrChk(DAQmxReadCounterScalarF64(taskHandle, 10000.0, &data, NULL)); // printf("Data acquired: 0%f\n", data); } Error: if( DAQmxFailed(error) ) DAQmxGetExtendedErrorInfo(errBuff,2048); if( taskHandle!=0 ) { /*********************************************/ // DAQmx Stop Code /*********************************************/ DAQmxStopTask(taskHandle); DAQmxClearTask(taskHandle); } if( DAQmxFailed(error) ) printf("DAQmx Error: %s\n",errBuff); printf("End of program, press Enter key to quit\n"); getchar(); return 0;

 

MAX.png

0 Kudos
Message 1 of 3
(3,157 Views)

Hi mashman,

 

Have you tried using the logging feature of Measurement & Automation Explorer rather than creating a C program?

0 Kudos
Message 2 of 3
(3,100 Views)

Thanks for your reply. My problem was that I didn't realize I needed an external clock. I setup a counter to use an my clock and once I did that I was able to collect data.

0 Kudos
Message 3 of 3
(3,098 Views)