Data Acquisition Toolbox | ![]() ![]() |
Reading and Writing Digital Values
If you have a supported National Instruments board with at least eight digital I/O lines, you can run the following example, which outputs digital values, and then reads back those values.
You should modify this example to suit your specific application needs. If you want detailed information about reading and writing digital values, refer to Chapter 7, Digital Input/Output.
1. Create a device object - Create the digital I/O object dio
for a National Instruments PCI-6024E board with hardware ID 1.
dio = digitalio('nidaq',1);
2. Add lines - Add eight hardware lines to dio
, and configure them for output.
addline(dio,0:7,'out');
3. Read and write values - Create an array of output values, and write the values to the digital I/O subsystem. Note that reading and writing digital I/O line values typically does not require that you configure specific property values.
pval = [1 1 1 1 0 1 0 1]; putvalue(dio,pval) gval = getvalue(dio);
4. Clean up - When you no longer need dio
, you should remove it from memory and from the MATLAB workspace.
delete(dio) clear dio
Note Digital line values are usually not transferred at a specific rate. Although some specialized boards support clocked I/O, the Data Acquisition Toolbox does not support this functionality. |
![]() | Outputting Data | Understanding the Toolbox Capabilities | ![]() |