Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Measuring Angular Position with vc++

I couldn't use AI ContAcqIntClk example because I only have 2 Analog Inputs and are already used, and I'm reading an Encoder, so It wouldn't help me either.

I don't know what you mean about poll the Available Samples property, what's that, where can I find it?

0 Kudos
Message 11 of 13
(1,049 Views)

Got it!!

 

I now have the program doing what I want to, I just deleted Sampling Timming, an voila! It's really boring explaining what i did so i will just post the modifications I did to the Ang_Pos_Buff_Count.c example:

 

/*********************************************************************

*

* ANSI C Example program:

* AngularPosition-Buff-Cont.c

*

* Example Category:

* CI

 

*********************************************************************/

#include <stdio.h>

#include <stdlib.h>

//#include <conio.h>

#include <NIDAQmx.h>

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

int i;

int main(void)

{

int error=0;

TaskHandle taskHandle=0;

int32 read;

float64 data[10];

char errBuff[2048]={'\0'};

/*********************************************/

// DAQmx Configure Code

/*********************************************/

DAQmxErrChk (DAQmxCreateTask("",&taskHandle));

DAQmxErrChk (DAQmxCreateCIAngEncoderChan(taskHandle,"Dev2/ctr0","",DAQmx_Val_X4,0,0.0,DAQmx_Val_AHighBHigh,DAQmx_Val_Degrees,360,0.0,""));

// ADJUSTED THIS LINE TO MY DEVICE

//DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"/Dev2/PFI8",1000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000));

// I JUST DELETED (SLASHED) THE LINE ABOVE

/*********************************************/

// DAQmx Start Code

/*********************************************/

DAQmxErrChk (DAQmxStartTask(taskHandle));

printf("Continuously reading. Press Ctrl+C to interrupt\n");

while( 1 ) {

/*********************************************/

// DAQmx Read Code

/*********************************************/

DAQmxErrChk (DAQmxReadCounterF64(taskHandle,1,-1,data,10,&read,0));

// AND CHANGED SOME OF THEESE SETTINGS

printf("Acquired %d samples\n",read);

//for (i=0;i<read;i++)

//{

system("CLS");

printf("%f, ",data[i]);

//}

fflush(stdout);

}

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;

}

 

Pretty simple stuff, but it took me a long time to get here since i didn't know anyting about programming daqmx with vc++, I just want to thank Neil, Arturo, BeCeGa, and many others who have helped me, Thank you guys. Now I will continue working on vc++ windows interface to complete my project, as well as so many other things about daqmx, so I will keep disturbing you guys Smiley Happy.

 

ZZ

 

0 Kudos
Message 12 of 13
(1,047 Views)

I'm glad you got it working.  Don't hesitate to post to the forums again if you get stuck.  We are here to help.

 

Neil S.

0 Kudos
Message 13 of 13
(1,028 Views)