Data Acquisition Toolbox | ![]() ![]() |
Writing and Reading Digital I/O Line Values
After you add lines to a digital I/O (DIO) object, you can:
Writing Digital Values
You write values to digital lines with the putvalue
function. putvalue
requires the DIO object and the values to be written as input arguments. You can specify the values to be written as a decimal value or as a binary vector (binvec). A binary vector is a logical array that is constructed with the least significant bit (LSB) in the first column and the most significant bit (MSB) in the last column. For example, the decimal value 23 is written in binvec notation as [1 1 1 0 1] = 20 + 21 + 22 + 24. You might find that binvecs are easier to work with than decimal values because there is a clear association between a given line and the value (1 or 0) that is written to it. You can convert decimal values to binvec values with the dec2binvec
function.
For example, suppose you create the digital I/O object dio
and add eight output lines to it from port 0.
To write a value of 23 to the eight lines contained by dio
, you can write to the device object.
Alternatively, you can write to individual lines through the Line
property.
To write a binary vector of values using the device object and the Line
property:
The second input argument supplied to dec2binvec
specifies the number of bits used to represent the decimal value. Because the preceding commands write to all eight lines contained by dio
, an eight element binary vector is required. If you do not specify the number of bits, then the minimum number of bits needed to represent the decimal value is used.
Alternatively, you can create the binary vector without using dec2binvec
.
Rules for Writing Digital Values
Writing values to digital I/O lines follows these rules:
![]() | Referencing Individual Hardware Lines | Reading Digital Values | ![]() |