Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

EveryNSamplesCallback Function Called after DAQmxWaitUntilTaskDone

Hello All, 

 

I'm reading data from a file on my computer and trying to produce Analog output via PXI-6733. My codes works well for the most part except the EveryNSamplesCallback function is called an additional time. Below is the most relevant part of the code. 

 

 

iTotalIterations=iNumSamples/EVERY_N_SAMPLES; 
// Floor iTotalIterations

/*********************************************/
// DAQmx Configure Code
/*********************************************/
DAQmxErrChk (DAQmxCreateTask("",&taskHandle));

DAQmxErrChk(DAQmxCreateAOVoltageChan(taskHandle,acChanNum,"",-10.0,10.0,DAQmx_Val_Volts,NULL));

DAQmxErrChk(DAQmxCfgSampClkTiming(taskHandle,"",SAMPLE_RATE,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,iTotalIterations*EVERY_N_SAMPLES));

DAQmxErrChk(DAQmxTaskControl(taskHandle,DAQmx_Val_Task_Commit));

DAQmxErrChk (DAQmxCfgOutputBuffer(taskHandle,BUFFER_SIZE));
// BUFFER_SIZE=EVERY_N_SAMPLES*4;

DAQmxErrChk(DAQmxRegisterEveryNSamplesEvent(taskHandle,DAQmx_Val_Transferred_From_Buffer,EVERY_N_SAMPLES,0,EveryNSamplesCallback,NULL));

DAQmxErrChk (DAQmxSetWriteRegenMode(taskHandle, DAQmx_Val_DoNotAllowRegen));

for(i=0;i<4;i++)
{
    //Get afData64

    DAQmxErrChk(DAQmxWriteAnalogF64(taskHandle,EVERY_N_SAMPLES,0,-1,DAQmx_Val_GroupByChannel,afData64,NULL,NULL));
}

// Buffer Full. Start Task
DAQmxErrChk(DAQmxStartTask(taskHandle));

// Continue Task Until Iterations are completed
// iCurrentIteration is global; updated in EveryNSamplesCallback
while(iTotalIterations>=iCurrentIteration)
{
    // Wait for EveryNSamplesCallback to be called and executed
}
printf("|\nEmptying Output Buffer...\n"); 
DAQmxErrChk(DAQmxWaitUntilTaskDone(taskHandle,-1));

 

 

If I print iCurrentIteration at the end of the code snippet,  it always one greater than iTotalIterations. Call to DAQmxWriteAnalogF64 in my EveryNSamplesCallback looks exactly same as above. 

 

Can someone help me with understanding the reason behind an additional call to EveryNSamplesCallback Function? How can I avoid it? 

 

Thanks.

0 Kudos
Message 1 of 3
(4,369 Views)

Hello All,

 

Let me know if you need any clarification or more details on the questions. Thanks for your help. 

0 Kudos
Message 2 of 3
(4,315 Views)

Neruopotential,

 

Could you try modifying your code. Specifically, 

while(iTotalIterations>=iCurrentIteration)

 Could this become while ((iTotalIterations-1)>=iCurrentIteration) Does this make things work correctly?

Matt P.
Applications Engineer
National Instruments
0 Kudos
Message 3 of 3
(4,299 Views)