Skip to Main Content Skip to Search
Product Documentation

Hardware Channels or Lines

Adding Channels and Lines

Channels and lines are the basic hardware device elements with which you acquire or output data.

After you create a device object, you must add channels or lines to it. Channels are added to analog input and analog output objects, while lines are added to digital I/O objects. The channels added to a device object constitute a channel group, while the lines added to a device object constitute a line group.

The functions associated with adding channels or lines to a device object are listed below.

Table 4-1. Functions Associated with Adding Channels or Lines

Functions

Description

addchannel

Add hardware channels to an analog input or analog output object.

addline

Add hardware lines to a digital I/O object.

addmuxchannel

Add channels when using a National Instruments AMUX-64T multiplexer. This applies only to Traditional NI-DAQ boards.

For example, to add two channels to an analog input object associated with a sound card, you must supply the appropriate hardware channel identifiers (IDs) to addchannel.

ai = analoginput('winsound');
addchannel(ai,1:2)

You can think of a device object as a channel or line container that reflects the common functionality of a particular device. The common functionality of a device applies to all channels or lines that it contains. For example, the sampling rate of an analog input object applies to all channels contained by that object. In contrast, the channels and lines contained by the device object reflect the functionality of a particular channel or line. For example, you can configure the input range (gain and polarity) on a per-channel basis.

The relationship between an analog input object and the channels it contains is shown below.

For digital I/O objects, the diagram would look the same except that lines would be substituted for channels.

Mapping Hardware Channel IDs to the MATLAB Indices

When you add channels to a device object, the resulting channel group consists of a mapping between hardware channel IDs and the MATLAB indices.

Hardware channel IDs are numeric values defined by the hardware vendor that uniquely identify a channel. For National Instruments and Measurement Computing hardware, the channel IDs are "zero-based" (begin at zero). For sound cards, the channel IDs are "one-based" (begin at one). However, when you reference channels, you use the MATLAB indices and not the hardware IDs. Given this, you should keep in mind that the MATLAB software is one-based. You can return the vendor's hardware IDs with the daqhwinfo function.

For example, suppose you create the analog input object ai for a National Instruments board and you want to add the first three differential channels.

ai = analoginput('nidaq','Dev1');

To return the hardware IDs, supply the device object to daqhwinfo, and examine the DifferentialIDs field.

out = daqhwinfo(ai)
out.DifferentialIDs
ans =
     0     1     2     3     4     5     6     7

The first three differential channels have IDs 0, 1, and 2, respectively.

addchannel(ai,0:2);

The index assigned to a hardware channel depends on the order in which you add it to the device object. In the above example, the channels are automatically assigned the MATLAB indices 1, 2, and 3, respectively. You can change the hardware channels associated with the MATLAB indices using the HwChannel property. For example, to swap the order of the second and third hardware channels,

ai.Channel(2).HwChannel = 2;
ai.Channel(3).HwChannel = 1;

The original and modified index assignments are shown below.

For digital I/O objects, the diagram would look the same except that lines would be substituted for channels.

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS