06-17-2008 03:13 PM
#include
<stdio.h>#include <math.h>
#include
"C:\NI-DAQ\DAQmx-ANSI-C-Dev\include\NIDAQmx.h"#define
DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; elseint32 CVICALLBACK EveryNSamplesCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples,
void *callbackData);void
Cleanup (void);static
TaskHandle taskHandle=0;static
int32 totalWrite=0;static
float64 data[4000];int
main(void){
int error=0; char errBuff[2048]={'\0'}; int i=0; for(;i<2000;i++) {data[i] = 4;
data[i+2000] = 4;
}
/*********************************************/ // DAQmx Configure Code /*********************************************/DAQmxErrChk (DAQmxCreateTask(
"",&taskHandle));DAQmxErrChk (DAQmxCreateAOVoltageChan(taskHandle,
"Dev1/ao0:1","",-10.0,10.0,DAQmx_Val_Volts,NULL));DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,
"",2000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,2000)); /*********************************************/ /* Tell the code to do another event once a certainnumber of samples have been written*/
/*********************************************/DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(taskHandle,DAQmx_Val_Transferred_From_Buffer,2000,0,EveryNSamplesCallback,NULL));
/*********************************************/ // DAQmx Start Code /*********************************************/DAQmxErrChk (DAQmxStartTask(taskHandle));
/*********************************************/ // DAQmx Write Code /*********************************************/DAQmxErrChk (DAQmxWriteAnalogF64(taskHandle,2000,0,10.0,DAQmx_Val_GroupByChannel,data,NULL,NULL));
printf(
"Generating samples continuously. Press Enter key to interrupt\n");getchar();
DAQmxErrChk (DAQmxStopTask(taskHandle));
printf(
"\nWrote %d total samples.\n",totalWrite); /*********************************************/ // DAQmx Wait Code /*********************************************/DAQmxErrChk (DAQmxWaitUntilTaskDone(taskHandle,10.0));
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); return 0;}
int32 CVICALLBACK EveryNSamplesCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples,
void *callbackData){
int32 error=0;
int32 write;
char errBuff[2048]={'\0'}; int j=0;float64 data2[4000];
for(;j<2000;j++) {data2[j] = 2;
data2[j+2000] = 2;
}
/*********************************************/ // DAQmx Write Code /*********************************************/DAQmxErrChk (DAQmxWriteAnalogF64(taskHandle,2000,0,10.0,DAQmx_Val_GroupByChannel,data2,&write,NULL));
if( write>0 ) {printf(
"Wrote %d samples. Total %d\r",write,totalWrite+=write);fflush(stdout);
}
Error:
if( DAQmxFailed(error) ) {DAQmxGetExtendedErrorInfo(errBuff,2048);
/*********************************************/ // DAQmx Stop Code /*********************************************/DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
printf(
"DAQmx Error: %s\n",errBuff);}
return 0;}
void
Cleanup (void){
if( taskHandle!=0 ){
/*********************************************/ // DAQmx Stop Code /*********************************************/DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
taskHandle = 0;
}
}
06-18-2008 12:02 PM
Hello Astro Mark,
The NI-DAQmx C Reference Help file states that if you configure timing for your task, that the task is a buffered task. Furthermore, if you don't manually configure the buffer size using DAQmxCfgOutputBuffer, DAQmx automatically configures the buffer when you configure sample timing. I recommend explicitly configuring the output buffer using the DAQmxCfgOutputBuffer function, and give it the appropriate parameters to see if you can eliminate the error.
Best wishes,
Wallace F.
06-19-2008 08:37 AM
06-19-2008 08:50 AM
06-19-2008 10:22 AM