Dear forum-users,
I am using a PCI 4461 and I program it with Visual C 6. I want to realise a continous buffered output with it, putting continously new samples into the buffer. Does anybody know how to write samples to the buffer without stopping the task?
The continous output I realise like this:
#include <NIDAQmx.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else
float64 data[2];
int32 CVICALLBACK DoneCallback(TaskHandle taskHandle, int32 status, void *callbackData);
int32 CVICALLBACK EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData);
int main(void)
{
int32 error=0;
TaskHandle taskHandle=0;
int32 write=0;
char errBuff[2048]={'\0'};
int i=0;
clock_t tic,toc;
double dauer;
for(;i<2;i++)
data[i] = 1.0;
/*********************************************/
// DAQmx Configure Code
/*********************************************/
DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
DAQmxErrChk (DAQmxCreateAOVoltageChan(taskHandle,"Dev1/ao0","",-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"",1000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,2));
DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(taskHandle,DAQmx_Val_Transferred_From_Buffer,2,0,EveryNCallback,&write));
DAQmxErrChk (DAQmxRegisterDoneEvent(taskHandle,NULL,DoneCallback,NULL));
DAQmxErrChk (DAQmxWriteAnalogF64(taskHandle,2,0,10.0,DAQmx_Val_GroupByChannel,data,&write,NULL));
DAQmxErrChk (DAQmxStartTask(taskHandle));
tic=clock();
printf("Generating voltage continuously. Press Enter to interrupt\n");
getchar();
Error:
if( DAQmxFailed(error) )
DAQmxGetExtendedErrorInfo(errBuff,2048);
if( taskHandle!=0 ) {
/*********************************************/
// DAQmx Stop Code
/*********************************************/
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
toc=clock();
dauer=(double)(toc-tic)/(double)(CLOCKS_PER_SEC*1e-3);
printf("\n%f ms",dauer);
}
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 totalwrite=0;
/*********************************************/
// DAQmx Write Code
/*********************************************/
if( nSamples==2 )
{
printf("\noutput %d samples. Total %d\r",nSamples,totalwrite+=nSamples);
fflush(stdout);
}
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;
}
The callback I use to see, that the desired numbers of samples has been output.
Thanks a lot for your help,
Hanna