01-26-2010 03:14 PM
i'm looking for one or more analog-output examples in which a waveform is generated on the fly. for comparison, all the examples shipping with NI-DAQmx continuously and repeatedly output the same data; i'd like to be able to change the output values. non-renegeration may be the (non-obvious) phrase that i'm missing in my searches. any suggestions, please?
this seems to be about what i'm looking for:
http://zone.ni.com/devzone/cda/epd/p/id/4872
only in c/c++ instead of labview.
Solved! Go to Solution.
01-26-2010 09:25 PM - edited 01-26-2010 09:25 PM
Hi David,
This example should be helpful--it sounds like what you want to do.
DAQmx - Continuously Generate Voltage - Non Regeneration - LabWindows/CVI
The DAQ part is:
//ConfigureDAQmxCreateTask("",&taskHandle);
DAQmxCreateAOVoltageChan(taskHandle,chan,"",min,max,DAQmx_Val_Volts,NULL);
DAQmxSetWriteAttribute (taskHandle, DAQmx_Write_RegenMode, DAQmx_Val_DoNotAllowRegen);
DAQmxCfgSampClkTiming(taskHandle,"",rate,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000);
// Write Data
DAQmxWriteAnalogF64(taskHandle,bufferSize,0,10.0,DAQmx_Val_GroupByChannel,data,&written,NULL);
// Start Task
DAQmxStartTask(taskHandle));
// Continuously Write Data in a Loop
while( gRunning ) {
DAQmxWriteAnalogF64(taskHandle,bufferSize,0,10.0,DAQmx_Val_GroupByChannel,data,&written,NULL);
}
// Clear task when finished
DAQmxClearTask(taskHandle);
The data written to your task must keep up with the rate that it is being clocked out or you will receive a buffer underflow error (i.e. the array of data must be large enough so that you write enough data per loop iteration). The DAQmx Write is a blocking call, so if you try to write more data than the space that is available in your output buffer the loop will wait here until space becomes available and it completes its Write or the specified timeout is reached.
Best Regards,
01-27-2010 02:44 PM
thanks very much for the link and assistance!
John P wrote:
The DAQmx Write is a blocking call, so if you try to write more data than the space that is available in your output buffer the loop will wait here until space becomes available and it completes its Write or the specified timeout is reached.
this is the important detail that wasn't apparent from the documentation -- it was unclear to me, without any example, how to time the addition of new data. this c-based example would be a great addition to the examples installed with ni-daq!
thanks, again!
-david