Data Acquisition Toolbox | ![]() ![]() |
Referencing Individual Hardware Lines
As described in the preceding section, you can access lines with the Line
property or with a line object. To reference individual lines, you must specify either MATLAB indices or descriptive line names.
MATLAB Indices
Every hardware line contained by a DIO object has an associated MATLAB index that is used to reference the line. When adding lines with the addline
function, index assignments are made automatically. The line indices start at 1 and increase monotonically up to the number of line group members. The first line indexed in the line group represents the least significant bit (LSB), and the highest indexed line represents the most significant bit (MSB). Unlike adding channels with the addchannel
function, you cannot manually assign line indices with addline
.
For example, the digital I/O object dio
created in the preceding section has the MATLAB indices 1 through 8 automatically assigned to the hardware lines 0 through 7, respectively. To swap the first two hardware lines so that line ID 1 is the LSB, you can supply the appropriate index to hwlines
and use the HwLine
property.
Alternatively, you can use the Line
property.
Descriptive Line Names
Choosing a unique, descriptive name can be a useful way to identify and reference lines -- particularly for large line groups. You can associate descriptive names with hardware lines with the addline
function. For example, suppose you want to add 8 lines to dio
, and you want to associate the name TrigLine
with the first line added.
Alternatively, you can use the LineName
property.
You can now use the line name to reference the line.
Example: Adding Lines for National Instruments Hardware
This example illustrates various ways you can add lines to a DIO object associated with a National Instruments AT-MIO-16DE-10 board. This board is a multiport device whose characteristics are described in Line and Port Characteristics.
To add eight input lines to dio
from port 0:
To add four input lines and four output lines to dio
from port 0:
Suppose you want to add the first two lines from port 0 configured for input, and the first two lines from port 2 configured for output. There are four ways to do this. The first way requires only one call to addline
because it uses the hardware line IDs, and not the port IDs.
The second way requires two calls to addline
, and specifies one line ID and multiple port IDs for each call.
The third way requires two calls to addline
, and specifies multiple line IDs and one port ID for each call.
Lastly, you can use four addline
calls -- one for each line added.
![]() | Line and Port Characteristics | Writing and Reading Digital I/O Line Values | ![]() |