| Data Acquisition Toolbox | ![]() |
Reading Digital Values
You can read values from one or more digital I/O lines with the getvalue function. getvalue requires the digital I/O object as an input argument. You can optionally specify an output argument, which represents the returned values as a binary vector. Binary vectors are described in Writing Digital Values.
For example, suppose you create the digital I/O object dio and add eight input lines to it from port 0.
dio = digitalio('nidaq',1);
addline(dio,0:7,'in');
To read the current value of all the lines contained by dio and return the result to out
portval = getvalue(dio)
portval =
1 1 1 0 1 0 0 0
To read the current values of the first four lines contained by dio and return the result to out
lineval = getvalue(dio.Line(1:5))
lineval =
1 1 1 0 1
You can convert a binvec to a decimal value with the binvec2dec function. For example, to convert the binary vector lineval to a decimal value
out = binvec2dec(lineval)
out =
23
Rules for Reading Digital Values
Reading values from digital I/O lines follows these rules:
1 by default.getvalue always returns a binary vector (binvec). To convert the binvec to a decimal value, use the binvec2dec function. | Writing and Reading Digital I/O Line Values | Example: Writing and Reading Digital Values | ![]() |