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 a DataAcquisition object and add two analog input voltage channels for cDAQ1Mod1 with channel IDs 0 and 1:

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.

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 one second of data and store it in the variable data, and then plot it:

data = read(d,seconds(1),"OutputFormat","Matrix");
plot(data)

Change the properties of the channel ai0 on cDAQ1Mod6 and display ch:

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 the data and store it in the variable, data, and plot it:

data = read(d,seconds(1),"OutputFormat","Matrix");
plot(data)

Related Topics