Acquire Data from Multiple Channels
This example shows how to acquire data from multiple channels, and
from multiple devices on the same chassis. In this example, you acquire voltage data
from an NI 9201 device with ID cDAQ1Mod4 and an NI 9205 device with
ID cDAQ1Mod1.
Create DataAcquisition Object and Add Channels from Two Devices
Create a DataAcquisition
object. Add two analog input voltage channels for cDAQ1Mod1 with
channel IDs 0 and 1 using the addinput
function.
d = daq("ni"); addinput(d,"cDAQ1Mod1",0:1,"Voltage")
ch =
Index Type Device Channel Measurement Type Range Name
_____ ____ ___________ _______ ________________ __________________ _______________
1 "ai" "cDAQ1Mod1" "ai0" "Voltage (Diff)" "-10 to +10 Volts" "cDAQ1Mod1_ai0"
2 "ai" "cDAQ1Mod1" "ai1" "Voltage (Diff)" "-10 to +10 Volts" "cDAQ1Mod1_ai1"Add an additional channel for a separate device, cDAQ1Mod6 with
channel ID 0. For NI devices, use either a terminal name, like ai0,
or a numeric equivalent like 0. Then view all channels on the
DataAcquisition object.
ch = addinput(d,"cDAQ1Mod6","ai0","Voltage"); d.Channels
Index Type Device Channel Measurement Type Range Name
_____ ____ ___________ _______ ________________ __________________ _______________
1 "ai" "cDAQ1Mod1" "ai0" "Voltage (Diff)" "-10 to +10 Volts" "cDAQ1Mod1_ai0"
2 "ai" "cDAQ1Mod1" "ai1" "Voltage (Diff)" "-10 to +10 Volts" "cDAQ1Mod1_ai1"
3 "ai" "cDAQ1Mod6" "ai0" "Voltage (Diff)" "-10 to +10 Volts" "cDAQ1Mod6_ai0"Acquire and Plot Data from All Channels
Acquire data for a duration of one second using the DataAcquisition
object d, store it in the variable data as a
matrix, and plot the acquired data.
data = read(d,seconds(1),OutputFormat="Matrix"); plot(data) title('Acquired Data from Multiple Channels'); xlabel('Sample Number'); ylabel('Voltage (V)'); legend('ai0 -cDAQ6Mod1','ai1 -cDAQ6Mod1','ai0 -cDAQ6Mod3');

Configure Second Device Channel
Edit and display the properties of the channel ai0 on
cDAQ1Mod6. For more information, see Channel Properties.
ch.TerminalConfig ="SingleEnded"; ch.Name = "Velocity_sensor"; ch
ch = Index Type Device Channel Measurement Type Range Name _____ ____ ___________ _______ ____________________ __________________ _________________ 1 "ai" "cDAQ1Mod6" "ai0" "Voltage (SingleEnd)" "-10 to +10 Volts" "Velocity_sensor"
Acquire Data from All Channels
Acquire data for a duration of one second and store it in the variable
data as a matrix.
data = read(d,seconds(1),OutputFormat="Matrix");Plot Data from Each Device Separately
Plot acquired data in two subplots: the first plot shows voltage signals from Device 1, and the second plot shows the signal from Device 2.
figure; subplot(2,1,1); plot(data.Time,[data.cDAQ6Mod1_ai0 data.cDAQ6Mod1_ai1]); title('Acquired Data from Device 1'); xlabel('Time (s)'); ylabel('Voltage (V)'); subplot(2,1,2); plot(data.Time,data.Velocity_sensor); title('Acquired Data from Device 2'); xlabel('Time (s)'); ylabel('Voltage (V)');
