This example shows how to acquire and generate data using two National Instruments modules operating at the same time.
Use daq
to create a DataAcquisition
dq = daq("ni")
dq = DataAcquisition using National Instruments hardware: Running: 0 Rate: 1000 NumScansAvailable: 0 NumScansAcquired: 0 NumScansQueued: 0 NumScansOutputByHardware: 0 RateLimit: [] Show channels Show properties and methods
This example uses a compactDAQ chassis NI c9178 with NI 9205 (cDAQ1Mod1 - 4 analog input channels) module and NI 9263 (cDAQ1Mod2 - 4 analog output channels) module. Use daqlist
to obtain more information about connected hardware.
The analog output channels are physically connected to the analog input channels so that the acquired data is the same as the data generated from the analog output channel.
Use addinput
to add an analog input voltage channel. Use addoutput
to add an analog output voltage channel.
addinput(dq, "cDAQ1Mod1", "ai0", "Voltage") addoutput(dq, "cDAQ1Mod2", "ao0", "Voltage")
output = cos(linspace(0,2*pi,1000)');
plot(output);
title("Output Data");
Use readwrite
to generate and acquire scans simultaneously.
data1 = readwrite(dq, output);
plot(data1.Time, data1.Variables); ylabel("Voltage (V)") title("Acquired Signal");
data2 = readwrite(dq, [output; output]);
plot(data2.Time, data2.Variables); ylabel("Voltage (V)") title("Acquired Signal");