12-13-2011 11:45 AM
I need to acquire the acceleration data with my NI PCI-4474 connected with an accelerometer.
The PCI-4474 is correctly configured under OpenSuse 11.3. This is the nilsdev output:
NI PCI-4474: "Dev1"
I modified the ContAccelSamps-IntClk-AnlgStart.c in the Nidaqmx documentation examples:
/********************************************************************* * * ANSI C Example program: * ContAccelSamps-IntClk-AnlgStart.c * * *********************************************************************/ #include <stdio.h> #include <stdlib.h> #include <NIDAQmx.h> #define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else int32 CVICALLBACK EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData); int32 CVICALLBACK DoneCallback(TaskHandle taskHandle, int32 status, void *callbackData); int main(void) { int32 error=0; TaskHandle taskHandle=0; char errBuff[2048]={'\0'}; /*********************************************/ // DAQmx Configure Code /*********************************************/ DAQmxErrChk (DAQmxCreateTask("",&taskHandle)); DAQmxErrChk (DAQmxCreateAIAccelChan(taskHandle,"Dev1/ai0","",DAQmx_Val_PseudoDiff,-100.0,100.0,DAQmx_Val_AccelUnit_g,50,DAQmx_Val_mVoltsPerG,DAQmx_Val_Internal,0.004,NULL)); DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"OnBoardClock",10000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000)); DAQmxErrChk (DAQmxCfgAnlgEdgeStartTrig(taskHandle,"Dev1/ai0",DAQmx_Val_Rising,30.0)); DAQmxErrChk (DAQmxSetAnlgEdgeStartTrigHyst(taskHandle, 10.0)); DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(taskHandle,DAQmx_Val_Acquired_Into_Buffer,1000,0,EveryNCallback,NULL)); DAQmxErrChk (DAQmxRegisterDoneEvent(taskHandle,0,DoneCallback,NULL)); /*********************************************/ // DAQmx Start Code /*********************************************/ DAQmxErrChk (DAQmxStartTask(taskHandle)); printf("Acquiring samples continuously. Press Enter to interrupt\n"); getchar(); 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; } int32 CVICALLBACK EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData) { int32 error=0; char errBuff[2048]={'\0'}; static int totalRead=0; int32 read=0; float64 data[1000]; /* Change this variable to 1 if you are using a DSA device and want to check for Overloads. */ int32 overloadDetectionEnabled=0; bool32 overloaded=0; char overloadedChannels[1000]; /*********************************************/ // DAQmx Read Code /*********************************************/ DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,1000,10.0,DAQmx_Val_GroupByScanNumber,data,1000,&read,NULL)); if ( overloadDetectionEnabled ) DAQmxErrChk (DAQmxGetReadOverloadedChansExist(taskHandle,&overloaded)); if( read>0 ){ printf("Acquired %d samples. Total %d\r",read,totalRead+=read); for(int i=0; i< read; i++){ printf("%f\n", data[i]); } } if( overloaded ) { DAQmxErrChk (DAQmxGetReadOverloadedChans(taskHandle,overloadedChannels,1000)); printf("Overloaded channels: %s\n",overloadedChannels); } fflush(stdout); Error: if( DAQmxFailed(error) ) { DAQmxGetExtendedErrorInfo(errBuff,2048); /*********************************************/ // DAQmx Stop Code /*********************************************/ DAQmxStopTask(taskHandle); DAQmxClearTask(taskHandle); printf("DAQmx Error: %s\n",errBuff); } return 0; } int32 CVICALLBACK DoneCallback(TaskHandle taskHandle, int32 status, void *callbackData) { int32 error=0; char errBuff[2048]={'\0'}; // Check to see if an error stopped the task. DAQmxErrChk (status); Error: if( DAQmxFailed(error) ) { DAQmxGetExtendedErrorInfo(errBuff,2048); DAQmxClearTask(taskHandle); printf("DAQmx Error: %s\n",errBuff); } return 0; }
Unfortunately the program never calls the EveryNCallback callback...
Acquiring samples continuously. Press Enter to interrupt
Why the board can't acquire and print any data?
12-14-2011 08:08 AM
I solved the problem commenting the following code:
// DAQmxErrChk (DAQmxSetAnlgEdgeStartTrigHyst(taskHandle, 10.0));