主要内容

addinput

R2026b

Add input channel to device interface

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. Access the channel information from the Channels property of d.

ch = addinput(d,deviceID,channelID,measurementType) adds the channel and returns a channel object.

example

[ch,idx] = addinput(d,deviceID,channelID,measurementType) adds the channel and also returns the channel index from the DataAcquisition interface. The channel index indicates the sequence in which you add channels to the DataAcquisition interface; do not confuse it with the device channel ID.

example

[___] = addinput(d,deviceID,channelID,measurementType,UseTEDS=tf) configures the input channel using TEDS when tf is true. This option is supported for analog input channels on NI™ devices only. (since R2026b)

example

Examples

collapse all

Add multiple audio input channels to a DataAcquisition interface, 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 interface, 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       TEDS Enabled 
    _____    ____    ______    _______    _____________________    ____________________    __________    ____________

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

Since R2026b

If your NI device has TEDS, addinput automatically configures the channel options for you. Create a DataAcquisition interface for the device and add the input with the UseTEDS option.

d = daq("ni");
chTeds = addinput(d,"Dev1","ai1","Thermocouple",UseTEDS=true);

Verify that the channel properties are correctly configured. The channel is now ready for acquisition and does not require any manual configuration.

get(chTeds)
           Units: Celsius
ThermocoupleType: J
     TEDSEnabled: true
           Range: -210 to +1200 Celsius
            Name: 'Dev1_ai0'
              ID: 'ai0'
          Device: [1x1 daq.ni.DeviceInfo]
 MeasurementType: 'Thermocouple'
 

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; typically indicates the physical location of the channel on the device. Supported values depend on the vendor and device. To add multiple channels, specify the channel ID as a numeric vector or a cell array of character vectors or strings.

The channel ID is not the same as the channel index. The index is the position of the channel in the DataAcquisition interface display. For example, if you add a channel with ID 2 as the first channel in a DataAcquisition interface, the index for this channel 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: addinput(d,"Dev1","ai2","Voltage");

Example: addinput(d,'Dev1','ai1','Voltage');

Example: addinput(d,'Dev1',{'ai1','ai2'},'Voltage');

Example: addinput(d,"Dev1",{"ai1","ai2"},"Voltage");

Example: addinput(d,"Dev1",1:2,"Voltage");

Data Types: char | string | numeric | cell

Channel measurement type, specified as a character vector or string. measurementType represents a vendor-defined measurement type. The valid measurement types are:

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

Since R2026b

Option to use TEDS to automatically configure channels, specified as logical 1 (true) or 0 (false). Use this option when you connect an analog input channel of an NI device to a sensor that includes a TEDS chip. When you set this option to true, addinput automatically configures the channel using the TEDS data.

TEDS support depends on the NI device. Refer to device documentation to determine whether your NI device supports TEDS.

Example: addinput(d,"Dev1","ai2","Voltage",UseTEDS=true)

Data Types: logical

Output Arguments

collapse all

Channel, returned as a channel object with properties that depend on the measurement type. For more information, see Channel Properties.

Channel index, returned as a numeric value. Use this index to access the array of the DataAcquisition Channels property.

Version History

Introduced in R2020a

expand all