12-05-2008 02:42 PM
Hi,
I’m trying to build an MFC application with MSVC++6, where I would continuously acquire
samples from 2 channels of a USB-6289. I’m using the DAQmx C functions. I use the following codes to continuously get data:
DAQmxErrChk(DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai0,Dev1/ai1","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk(DAQmxReadAnalogF64(taskHandle,1000,-1,DAQmx_Val_GroupByChannel,data,2000,&read,NULL));
DAQmxErrChk
(DAQmxRegisterEveryNSamplesEvent(taskHandle,DAQmx_Val_Acquired_Into_Buffer,1000,0,EveryNCallback,NULL));
DAQmxErrChk (DAQmxRegisterDoneEvent(taskHandle,0,DoneCallback,NULL));
static int32 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];
/*********************************************/
// DAQmx Read Code
/*********************************************/
DAQmxErrChk(DAQmxReadAnalogF64(taskHandle,1000,-1,DAQmx_Val_GroupByChannel,data,2000,&read,NULL));
if( read>0 ) {
fflush(stdout);
}
Error:
if( DAQmxFailed(error) ) {
DAQmxGetExtendedErrorInfo(errBuff,2048);
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
return 0;
}
}
static 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);
//MessageBox("errors in DoneCallBack");
DAQmxClearTask(taskHandle);
//MessageBox(errBuff);
}
return 0;
}
I have two questions:
1. how to save the data into an excel file? Can anyone show me some sample codes please?
2.Are
the data acquired from the two channels simultaneously? If I set the
starting time at 0, sample frequency 1khz, can I directly multiply the
sample number by 0.001 to calculate time (as shown below)?
Time channel1 channel2
0.001 d11 d21
0.002 d12 d22
....
Thank you!
12-05-2008 03:24 PM - edited 12-05-2008 03:24 PM
You aren't going to get much help with Visual C++ programing when asking questions in the LabVIEW forum. ![]()
Try the Measurement Studio for Visual C++ forum.
12-08-2008 01:19 PM
Regards,
Dan King