(Not recommended) Add digital channel
adds one or more digital channels to the session
s, on the device
deviceID, with the specified port and single-line
combination and channel measurement type.
Before adding digital channels, create a session using
Direction property value of bidirectional
channels before you read or write digital data.
To input and output decimal or hexadecimal values, use these conversion functions:
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:
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
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
s— Data acquisition session
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.
deviceID— Device ID
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.
channelID— Channel ID
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
'Dev1' as the first channel in a session, its
session index is
measurementType— Channel measurement type
Channel measurement type specified as a character vector or string.
measurementType represents a vendor-defined measurement
type. Supported measurements are:
ch— Digital channels
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.
idx— Channel index
Channel index returned as a numeric value. Use this index to access the
channels in the array of the session
sessionobject interface is not recommended
Not recommended starting in R2020a
Use of this function with a
session object is not recommended. To
access a data acquisition device, use a
with its functions and properties instead.
For more information about using the recommended functionality, see Transition Your Code from Session to DataAcquisition Interface.