Simultaneously Acquire Data and Generate Signals
This example shows how to acquire and generate data using two National Instruments™ modules operating at the same time.
Create a DataAcquisition
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
Set up Hardware
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.
Add an Analog Input Channel and an 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")
Create and Plot the Output Signal
output = cos(linspace(0,2*pi,1000)');
plot(output);
title("Output Data");
Generate and Acquire Data
Use readwrite
to generate and acquire scans simultaneously.
data1 = readwrite(dq, output);
Plot the Acquired Data
plot(data1.Time, data1.Variables); ylabel("Voltage (V)") title("Acquired Signal");
Generate and Acquire Data for Twice the Previous Duration
data2 = readwrite(dq, [output; output]);
Plot the Acquired Data
plot(data2.Time, data2.Variables); ylabel("Voltage (V)") title("Acquired Signal");