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 digital I/O 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 had the MATLAB indices 1 through 8 automatically assigned to the hardware lines 0 through 7, respectively. To manually swap the hardware line order so that line ID 1 is the LSB, you supply the appropriate index to hwlines
and use the HwLine
property.
hwlines(1).HwLine = 1; hwlines(2).HwLine = 0;
Alternatively, you can use the Line
property.
dio.Line(1).HwLine = 1; dio.Line(2).HwLine = 0;
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 using 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.
addline(dio,0,'out','TrigLine'); addline(dio,1:7,'out');
Alternatively, you can use the
LineName
property.
addline(dio,0:7,'out'); dio.Line(1).LineName = 'TrigLine';
You can now use the line name to reference the line.
dio.TrigLine.Direction = 'in';
Example: Adding Lines for National Instruments Hardware
This example illustrates various ways you can add lines to a digital I/O 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
addline(dio,0:7,'in');
To add four input lines and four output lines to dio
from port 0
addline(dio,0:7,{'in','in','in','in','out','out','out','out'});
Suppose you want to add the first line from port 0 and port 2 configured for input, and the second line from the same ports configured for output. There are three ways to do this. The first way requires only one call to addline
since it uses the hardware line IDs, and not the port IDs.
addline(dio,[0 1 8 9],{'in','out','in','out'});
The second way requires two calls to addline
, and specifies one line ID and multiple port IDs for each call.
addline(dio,0,[0 2],'in'); addline(dio,1,[0 2],'out');
The third way requires two calls to addline
, and specifies multiple line IDs and one port ID for each call.
addline(dio,0:1,0,{'in','out'}); addline(dio,0:1,2,{'in','out'});
![]() | Line and Port Characteristics | Writing and Reading Digital I/O Line Values | ![]() |