simultaneously acquire data and generate signals -凯发k8网页登录
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 date 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");