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 session object and add two analog input 'Voltage' channels on cDAQ1Mod1 with channel ID 0 and 1:

s = daq.createSession('ni');
addAnalogInputChannel(s,'cDAQ1Mod1',0:1,'Voltage');

Add an additional channel on a separate device, cDAQ1Mod6 with channel ID 0. For NI devices, use either a terminal name, like ai0, or a numeric equivalent like 0. Store this channel in the variable ch.

ch = addAnalogInputChannel(s,'cDAQ1Mod6','ai0','Voltage')
ch = 

Data acquisition analog input channel 'ai0' on device 'cDAQ1Mod16':

      Coupling: DC
TerminalConfig: Differential
         Range: -10 to +10 Volts
          Name: empty
            ID: 'ai0'
        Device: [1x1 daq.ni.CompactDAQModule]
 ADCTimingMode: ''

View the session object to see the three channels:

s
s = 

Data acquisition session using National Instruments hardware:
   Will run for 1 second (1000 scans) at 1000 scans/second.
   Number of channels: 3
      index Type  Device   Channel   MeasurementType        Range       Name
      ----- ---- --------- ------- ------------------- ---------------- ----
      1     ai   cDAQ1Mod1 ai0     Voltage (SingleEnd) -10 to +10 Volts
      2     ai   cDAQ1Mod1 ai1     Voltage (SingleEnd) -10 to +10 Volts
      3     ai   cDAQ1Mod6 ai0     Voltage (Diff)      -10 to +10 Volts

Acquire the data and store it in the variable, data and plot it:

data = startForeground(s);
plot(data)

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

ch.TerminalConfig ='SingleEnded';
ch.Name = 'Velocity sensor';
ch
ch = 

Data acquisition analog input channel 'ai0' on device 'cDAQ1Mod6':

      Coupling: DC
TerminalConfig: SingleEnded
         Range: -10 to +10 Volts
          Name: 'Velocity sensor'
            ID: 'ai0'
        Device: [1x1 daq.ni.CompactDAQModule]
 ADCTimingMode: empty

Acquire the data and store it in the variable, data, and plot it:

data = startForeground(s);
plot(data)

Related Topics