Hi,
We are developing DataAcquisition project using NiDaqmx(NIPCI-6221) on VC++.
We need to read data from VoltageReadTask having more than one channel and need to display the data as live graph.For that we used
DAQmxRegisterEveryNSamplesEvent along with it's CallBack method.We are quite confusing with passing parameters ,usage of
DAQmxCfgSampClkTiming etc.,.I am also placing some part of I am using..
"g_VReadTaskHandle" is voltageread task handle which is having 3 channels
"NVRead" is a variable that holds number of channels
"AnalogBuf" is the Buffer which is sent to CallBack method to hold data.
we passing 10000 for Sampling rate.
AnalogBuf = new float64[NVRead*SamplingRate];
//Set the sample clock timing
DAQmxErrChk(DAQmxCfgSampClkTiming(g_VReadTaskHandle,"OnboardClock",(SamplingRate*NVRead), DAQmx_Val_Rising,DAQmx_Val_ContSamps ,(long)(SamplingRate/NVRead)));
//Register Callback event
DAQmxErrChk(DAQmxRegisterEveryNSamplesEvent(g_VReadTaskHandle,DAQmx_Val_Acquired_Into_Buffer,(unsigned long)(SamplingRate),0,VoltageRead,(double*)AnalogBuf));
DAQmxErrChk (DAQmxStartTask(g_VReadTaskHandle));
This is CallBack method we are using...
int32 CVICALLBACK VoltageRead(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData)
{
int count =0;
int32 error=0;
int32 read;
char errBuff[2048]={'\0'};
DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,nSamples,10.0,DAQmx_Val_GroupByChannel, (double*)callbackData,nSamples,&read,NULL));
Error:
if( DAQmxFailed(error) )
{
DAQmxGetExtendedErrorInfo(errBuff,2048);
CleanupTask(taskHandle);
CString cst1;
cst1.Format("DAQmx Error: %s\n",errBuff);
AfxMessageBox(cst1);
}
return 0;
}
Thanks in Advance..