Main Content

Acquire Data and Generate Signals Simultaneously

This example shows how to acquire data with an NI™ 9205 device of ID cDAQ1Mod1, while generating signals from an NI 9263 device with ID cDAQ1Mod2.

You can acquire data and generate signals at the same time, on devices on the same chassis. When the DataAcquisition contains output channels, the duration of a finite generation and acquisition depends on the number of scans and the scan rate.

Create an NI DataAcquisition object and add one analog input channel on cDAQ1Mod1 and one analog output channel on cDAQ1Mod2:

d = daq("ni");
addinput(d,"cDAQ1Mod1","ai0","Voltage");
addoutput(d,"cDAQ1Mod2","ao0","Voltage");
d.Channels
ans = 

  Index    Type      Device       Channel      Measurement Type             Range                Name   
  _____    ____    ___________    _______    _____________________    __________________    _______________

    1      "ai"    "cDAQ1Mod1"     "ai0"     "Voltage (SingleEnd)"    "-10 to +10 Volts"    "cDAQ1Mod1_ai0"
    1      "ao"    "cDAQ1Mod2"     "ao0"     "Voltage (SingleEnd)"    "-10 to +10 Volts"    "cDAQ1Mod2_ao0"

Define the output signal data for 2500 scans:

outData = linspace(-1,10,2500)';

The generated output signal of 2500 scans will run for 2.5 seconds at a scan rate of 1000 samples per second.

Generate the output signal and acquire the input data:

inData = readwrite(d,outData,"OutputFormat","Matrix");
plot(inData)

Related Topics