10-25-2022 09:31 PM
I want to output two continuous analog waveforms with USB 6353 board.
I tried this example for a single channel and it worked.
----------------------
AoTask = new Task();
AoTask.AOChannels.CreateVoltageChannel("Dev1/ao0",
"", -10.0, 10.0, AOVoltageUnits.Volts);
AoTask.Control(TaskAction.Verify);
FunctionGenerator fGen1 = new FunctionGenerator(
AoTask.Timing, "200", "1768", "1", "Sine Wave", "1.0");
AoTask.Timing.ConfigureSampleClock("", fGen1.ResultingSampleClockRate,
SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, 1000);
AnalogSingleChannelWriter writer = new AnalogSingleChannelWriter(AoTask.Stream);
writer.WriteMultiSample(false, fGen1.Data);
AoTask.Start();
-----------------------------------------------------------
To use two AO channel, I tried use two AO tasks. But it only start the first one channel.
It seems we pnly allowed to use only one AO task for each DAQ board?
My question is how can I configure and write waveform data to buffer(FIFO) that is used by two AO channels (dev1/ao0 and /dev1//ao1)?
My pseudo code will be like this
--------------------
AoTask = new Task();
// create two AO channels, ao0 and ao1
AoTask.AOChannels.CreateVoltageChannel("Dev1/ao0",
"", -10.0, 10.0, AOVoltageUnits.Volts);
AoTask.AOChannels.CreateVoltageChannel("Dev1/ao1",
"", -10.0, 10.0, AOVoltageUnits.Volts);
AoTask.Control(TaskAction.Verify);
// generate waveform data
Generate_waveform_data(&Data);
// write Data to onboard buffer/FIFO
AnalogmultipleChannelWriter( Data);
//start AO task
AoTask.Start();
------------------------------
my question is, "What are the corresponding functions in DAQmx API should I used for Generate_waveform_data() and AnalogmultipleChannelWriter() pseudo functions?
10-25-2022 10:27 PM
Yes, almost all DAQ cards support only one active AO Task and you've to include all the AO channels you wish to control into the same task for simultaneous control.
This documentation page lists the writer functions - https://www.ni.com/docs/en-US/bundle/ni-daqmx-.net-framework-4.5.1-class-library-getting-started/pag...
Here is an example,
C#
// Given a Task instance "myTask", // Initialize the data AnalogWaveform<double>[] data = new AnalogWaveform<double>[2]; data[0] = new AnalogWaveform<double>(100); data[1] = new AnalogWaveform<double>(100); // Create the writer and attach it to the stream AnalogMultiChannelWriter writer = new AnalogMultiChannelWriter(myTask.Stream); // Perform the write writer.WriteWaveform(true, data);
10-26-2022 12:39 PM
Hi Santo_13,
Thanks for your code example.