Main Content

addinput

Add input channel to device interface

Since R2020a

Description

addinput(d,deviceID,channelID,measurementType) adds the input channel channelID from device deviceID to the specified DataAcquisition interface, d, configured for the specified measurement type.

The channel information is available from the DataAcquisition Channels property.

ch = addinput(___) adds the channel and returns a channel object.

[ch,idx] = addinput(___) adds the channel and also returns the channel index from the DataAcquisition interface. The channel index indicates only the sequence in which channels are added to the DataAcquisition; not to be confused with the device channel ID.

example

Examples

collapse all

Add multiple audio input channels to a DataAcquisition, and use indices to view their settings.

d = daq('directsound');
ch1 = addinput(d,"Audio0","1","Audio");
[ch2,idx2] = addinput(d,"Audio1","1","Audio");
d.Channels
    Index     Type      Device     Channel    Measurement Type        Range            Name   
    _____    ______    ________    _______    ________________    ______________    __________

      1      "audi"    "Audio0"      "1"          "Audio"         "-1.0 to +1.0"    "Audio0_1"
      2      "audi"    "Audio1"      "1"          "Audio"         "-1.0 to +1.0"    "Audio1_1"

Access one of the channel settings using its index.

d.Channels(idx2).Range
  Range with properties:

    Units: ''
      Max: 1
      Min: -1

Add a voltage input channel to a DataAcquisition, and modify some of its settings.

d = daq("ni");
ch = addinput(d,"Dev1",1,"Voltage");
get(ch)
       Coupling: DC
 TerminalConfig: Differential
          Range: -10 to +10 Volts
           Name: 'Dev1_ai1'
             ID: 'ai1'
         Device: [1x1 daq.ni.DeviceInfo]
MeasurementType: 'Voltage'

Set range and terminal configuration of the input channel.

ch.Range = [-2.5 2.5];
ch.TerminalConfig = "SingleEnded"
ch = 

    Index    Type    Device    Channel      Measurement Type              Range               Name   
    _____    ____    ______    _______    _____________________    ____________________    __________

      1      "ai"    "Dev1"     "ai1"     "Voltage (SingleEnd)"    "-2.5 to +2.5 Volts"    "Dev1_ai1"

Input Arguments

collapse all

DataAcquisition interface, specified as a DataAcquisition object, created using the daq function.

Example: d = daq()

Device ID specified as a character vector or string, as defined by the device vendor. Obtain the device ID by calling daqlist.

Example: "Dev1"

Data Types: char | string

Channel ID specified as a numeric value, character vector, or string; often indicating the physical location of the channel on the device. Supported values are specific to the vendor and device. You can add multiple channels by specifying the channel ID as a numeric vector, or a cell array of character vectors. The index returned for this channel in the DataAcquisition display indicates the position of this channel. This channel ID is not the same as channel index in the DataAcquisition: if you add a channel with ID 2 as the first channel in a DataAcquisition, the DataAcquisition channel index is 1.

Tip: For best performance when adding multiple channels, specify the channels as a vector in one call to addinput, rather than calling addinput for each channel.

Example: "ai2"

Data Types: char | string | numeric | cell

Channel measurement type, specified as a character vector or string. measurementType represents a vendor-defined measurement type. Valid measurement types include the following:

Measurement TypeSubsystem

'Voltage'

Analog Input

'Current'

Analog Input

'Thermocouple'

Analog Input

'Accelerometer'

Analog Input

'RTD'

Analog Input

'Bridge'

Analog Input

'Microphone'

Analog Input

'IEPE'

Analog Input

'Digital'

Digital I/O

'EdgeCount'

Counter Input

'Frequency'

Counter Input

'PulseWidth'

Counter Input

'Position'

Counter Input

'Audio'

Audio Input

Not all devices support all types of measurement.

Example: "Voltage"

Data Types: char | string

Output Arguments

collapse all

Channel, returned as a channel object with properties depending on the measurement type as described in Channel Properties.

Channel index, returned as a numeric value. With this index, you can access the array of the DataAcquisition Channels property.

Version History

Introduced in R2020a