Data Acquisition Toolbox | ![]() ![]() |
Adding Channels to an Analog Input Object
After creating the analog input object, you must add hardware channels to it. As shown by the figure in Adding Channels or Lines, you can think of a device object as a container for channels. The collection of channels contained by the device object is referred to as a channel group. As described in Mapping Hardware Channel IDs to MATLAB Indices, a channel group consists of a mapping between hardware channel IDs and MATLAB indices (see below).
When adding channels to an analog input object, you must follow these rules:
You add channels to an analog input object with the addchannel
function. addchannel
requires the device object and at least one hardware channel ID as input arguments. You can optionally specify MATLAB indices, descriptive channel names, and an output argument. For example, to add two hardware channels to the device object ai created in the preceding section:
The output argument chans
is a channel object that reflects the channel array contained by ai
. You can display the class of chans
with the whos
command.
whos chans Name Size Bytes Class chans 2x1 512 aichannel object Grand total is 7 elements using 512 bytes
You can use chans
to easily access channels. For example, you can easily configure or return property values for one or more channels. As described in Referencing Individual Hardware Channels, you can also access channels with the Channel
property.
Once you add channels to an analog input object, the properties listed below are automatically assigned values. These properties provide descriptive information about the channels based on their class type and ID.
Property Name |
Description |
HwChannel |
Specify the hardware channel ID. |
Index |
Indicate the MATLAB index of a hardware channel. |
Parent |
Indicate the parent (device object) of a channel. |
Type |
Indicate a channel. |
You can display the values of these properties for chans
with the get
function.
get(chans,{'HwChannel','Index','Parent','Type'}) ans = [0] [1] [1x1 analoginput] 'Channel' [1] [2] [1x1 analoginput] 'Channel'
If you are using scanning hardware, then the MATLAB indices define the scan order; index 1 is sampled first, index 2 is sampled second, and so on.
![]() | Creating an Analog Input Object | Referencing Individual Hardware Channels | ![]() |