Main Content

addDigitalChannel

(Not recommended) Add digital channel

This session object function is not recommended. Use DataAcquisition object functions instead. See Version History.

Description

addDigitalChannel(s,deviceID,channelID,measurementType) adds one or more digital channels to the session s, on the device represented by deviceID, with the specified port and single-line combination and channel measurement type.

Tips

example

ch = addDigitalChannel(s,deviceID,channelID,measurementType) creates and displays the digital channels assigned to ch.

example

[ch,idx] = addDigitalChannel(s,deviceID,channelID,measurementType) additionally creates and displays idx, which is an index into the array of the session object Channels property.

example

Examples

collapse all

Discover available digital devices on your system, then create a session with digital channels.

Find all installed devices.

d = daq.getDevices
d = 

Data acquisition devices:

index Vendor Device ID          Description         
----- ------ --------- -----------------------------
1     ni     Dev1      National Instruments USB-6255
2     ni     Dev2      National Instruments USB-6363

Get detailed subsystem information for NI USB-6255:

d(1)
ans = 

ni: National Instruments USB-6255 (Device ID: 'Dev1')
   Analog input subsystem supports:
      7 ranges supported
      Rates from 0.1 to 1250000.0 scans/sec
      80 channels ('ai0' - 'ai79')
      'Voltage' measurement type
   
   Analog output subsystem supports:
      -5.0 to +5.0 Volts,-10 to +10 Volts ranges
      Rates from 0.1 to 2857142.9 scans/sec
      2 channels ('ao0','ao1')
      'Voltage' measurement type
   
   Digital subsystem supports:
      24 channels ('port0/line0' - 'port2/line7')
      'InputOnly','OutputOnly','Bidirectional' measurement types
   
   Counter input subsystem supports:
      Rates from 0.1 to 80000000.0 scans/sec
      2 channels ('ctr0','ctr1')
      'EdgeCount','PulseWidth','Frequency','Position' measurement types
   
   Counter output subsystem supports:
      Rates from 0.1 to 80000000.0 scans/sec
      2 channels ('ctr0','ctr1')
      'PulseGeneration' measurement type

Create a session with input, output, and bidirectional channels using 'Dev1':

s = daq.createSession('ni');
addDigitalChannel(s,'dev1','Port0/Line0:1','InputOnly');
ch = addDigitalChannel(s,'dev1','Port0/Line2:3','OutputOnly');
[ch,idx] = addDigitalChannel(s,'dev1','Port2/Line0:1','Bidirectional')
ans =

Data acquisition session using National Instruments hardware:
   Clocked operations using startForeground and startBackground are disabled.
   Only on-demand operations using inputSingleScan and outputSingleScan can be done.
   Number of channels: 6
      index Type Device   Channel       MeasurementType     Range Name
      ----- ---- ------ ----------- ----------------------- ----- ----
      1     dio  Dev1   port0/line0 InputOnly               n/a
      2     dio  Dev1   port0/line1 InputOnly               n/a
      3     dio  Dev1   port0/line2 OutputOnly              n/a
      4     dio  Dev1   port0/line3 OutputOnly              n/a
      5     dio  Dev1   port2/line0 Bidirectional (Unknown) n/a
      6     dio  Dev1   port2/line1 Bidirectional (Unknown) n/a

Input Arguments

collapse all

Data acquisition session specified as a session object created using daq.createSession. Use the data acquisition session for acquisition and generation operations. Create one session per vendor and use that vendor session to perform all data acquisition operations.

Device ID as defined by the device vendor specified as a character vector. Obtain the device ID by calling daq.getDevices. The channel specified for this device is created for the session object.

Data Types: char

Channel ID, or the physical location of the channel on the device, specified as a character vector or string. Supported values are specific to the vendor and device. You can add a range of channels using colon syntax, or an array of character vectors or strings. The index for this channel in the session display indicates this channel’s position in the session. If you add a channel with channel ID 'Dev1' as the first channel in a session, its session index is 1.

Data Types: cell | char | string

Channel measurement type specified as a character vector or string. measurementType represents a vendor-defined measurement type. Supported measurements are:

  • 'InputOnly'

  • 'OutputOnly'

  • 'Bidirectional'

Data Types: char | string

Output Arguments

collapse all

Digital channels, returned as an array of channel objects. ch is a 1-by-n array, in which each element is a channel object with vendor-specific device and channel properties. See also the properties in Digital Input and Output.

Channel index returned as a numeric value. Use this index to access the channels in the array of the session Channels property.

Version History

Introduced in R2012b

collapse all

R2020a: session object interface is not recommended

Use of this function with a session object is not recommended. To access a data acquisition device, use a DataAcquisition object with its functions and properties instead.

For more information about using the recommended functionality, see Transition Your Code from Session to DataAcquisition Interface.