Data Acquisition Toolbox    
addchannel

Add hardware channels to an analog input or analog output object

Syntax

Arguments

obj
An analog input or analog output object.
hwch
Specifies the numeric IDs of the hardware channels added to the device object. Any MATLAB vector syntax can be used.
index
The MATLAB indices to associate with the hardware channels. Any MATLAB vector syntax can be used provided the vector elements are monotonically increasing.
'names'
A descriptive channel name or cell array of descriptive channel names.
chans
A column vector of channels with the same length as hwch.

Description

chans = addchannel(obj,hwch) adds the hardware channels specified by hwch to the device object obj. The MATLAB indices associated with the added channels are assigned automatically. chans is a column vector of channels.

chans = addchannel(obj,hwch,index) adds the hardware channels specified by hwch to the device object obj. index specifies the MATLAB indices to associate with the added channels.

chans = addchannel(obj,hwch,'names') adds the hardware channels specified by 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.

chans = addchannel(obj,hwch,index,'names') adds the hardware channels specified by 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.

Remarks

Rules for Adding 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:

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:

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.

Example

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.

See Also

Functions

delete, makenames

Properties

ChannelName, HwChannel, Index


  Functions - Alphabetical List addline