Data Acquisition Toolbox | ![]() ![]() |
Add hardware channels to an analog input or analog output object
Syntax
chans = addchannel(obj,hwch)
chans = addchannel(obj,hwch,index)
chans = addchannel(obj,hwch,'names')
chans = addchannel(obj,hwch,index,'names')
Arguments
Description
adds the hardware channels specified by chans = addchannel(obj,hwch)
hwch
to the device object obj
. The MATLAB indices associated with the added channels are assigned automatically. chans
is a column vector of channels.
adds the hardware channels specified by chans = addchannel(obj,hwch,index)
hwch
to the device object obj
. index
specifies the MATLAB indices to associate with the added channels.
adds the hardware channels specified by chans = addchannel(obj,hwch,'names')
hwch
to the device object obj
. The MATLAB indices associated with the added channels are assigned automatically. names
is a descriptive channel name or cell array of descriptive channel names.
adds the hardware channels specified by chans = addchannel(obj,hwch,index,'names')
hwch
to the device object obj
. index
specifies the MATLAB indices to associate with the added channels. names
is a descriptive channel name or cell array of descriptive channel names.
Rules for Adding Channels
hwch
depend on the hardware you access. For National Instruments and Measurement Computing hardware, channels are "zero-based" (begin at zero). For Agilent Technologies hardware and sound cards, channels are "one-based" (begin at one).
HwChannel
property and the associated MATLAB indices are stored in the Index
property.
hwch
must be 1
. For stereo mode, the first hwch
value specified must be 1
.
Note
If you are using National Instruments AMUX-64T multiplexer boards, you must use the addmuxchannel function to add channels.
|
More About MATLAB Indices
Every hardware channel contained by a device object has an associated MATLAB index that is used to reference the channel. Index assignments are made either automatically by addchannel
or explicitly with the index
argument and follow these rules:
index
is not specified and no hardware channels are contained by the device object, then the assigned indices automatically start at one and increase monotonically. If hardware channels have already been added to the device object, then the assigned indices automatically start at the next highest index value and increase monotonically.
index
is specified but the indices are previously assigned, then the requested assignment takes precedence and the previous assignment is reindexed to the next available values. If the lengths of hwch
and index
are not equal, then an error is returned and no channels are added to the device object.
Rules for Adding Channels to National Instruments 1200 Series Boards
When using National Instruments 1200 Series hardware, you need to modify the above rules in these ways:
addchannel
. For example, to add eight single-ended channels to the analog input object ai
:
More About Descriptive Channel Names
You can assign hardware channels descriptive names, which are stored in the ChannelName
property. Choosing a unique descriptive name can be a useful way to identify and reference channels. For a single call to addchannel
, you can
If the number of names specified in a single addchannel
call is more than one but not equal to the number of channels to be added, then an error is returned. If a channel is to be referenced by its name, then that name must not contain symbols. If you are naming a large number of channels, then the makenames
function might be useful. If a channel is not assigned a descriptive name, then it must be referenced by index.
A sound card configured in mono mode is automatically assigned the name Mono
, while a sound card configured in stereo mode is automatically assigned the names Left
for the first channel and Right
for the second channel. You can change these default channel names when the device object is created, or any time after the channel is added.
National Instruments
Suppose you create the analog input object AI1
for a National Instruments board, and add the first four hardware channels (channels 0-3) to it.
The channels are automatically assigned the indices 1-4. If you want to add the first four hardware channels to AI1
and assign descriptive names to the channels,
Note that you can use the makenames
function to create a cell array of channel names. If you add channels 4, 5, and 7 to the existing channel group,
the new channels are automatically assigned the indices 5-7. Suppose instead you add channels 4, 5, and 7 to the channel group and explicitly assign them indices 1-3.
The new channels are assigned the indices 1-3, and the previously defined channels are reindexed as indices 4-7. However, if you assigned channels 4, 5, and 7 to indices 6-8, an error is returned because there is a gap in the indices (index 5 has no associated hardware channel).
Sound Card
Suppose you create the analog input object AI1
for a sound card. Most sound cards have only two channels that can be added to a device object. To configure the sound card to operate in mono mode, you must specify hwch
as 1
.
The ChannelName
property is automatically assigned the value Mono
. You can now configure the sound card to operate in stereo mode by adding the second channel.
The ChannelName
property is assigned the values Left
and Right
for the two hardware channels. Alternatively, you can configure the sound card to operate in stereo mode with one call to addchannel
.
Functions
Properties
![]() | Functions - Alphabetical List | addline | ![]() |