|On this page…|
The fact that analog input and analog output objects make use of data stored in the engine and clocked I/O leads to the concept of a "running" device object and the generation of events.
However, because Data Acquisition Toolbox™ software does not support buffered digital I/O (DIO) operations, DIO objects do not store data in the engine. Additionally, reading and writing line values are not clocked at a specific rate in the way that data is sampled by an analog input or analog output subsystem. Instead, values are either written directly to digital lines with putvalue, or read directly from digital lines with getvalue.
Therefore, the concept of a running DIO object does not make sense in the same way that it does for analog I/O. However, you can "run" a DIO object to perform one task: generate timer events. You can use timer events to update and display the state of the DIO object. Refer to the diopanel example.
The only event supported by DIO objects is a timer event. Timer events occur after a specified period of time has passed. Properties associated with generating timer events are given below.
Table 10-4. Digital I/O Timer Event Properties
Indicate if the device object is running.
Specify the callback function to execute whenever a predefined period of time passes.
Specify the period of time between timer events.
A timer event is generated whenever the time specified by TimerPeriod passes. This event executes the callback function specified for TimerFcn. Time is measured relative to when the device object starts running (Running is On). Starting a DIO object is discussed in the next section.
Some timer events might not be processed if your system is significantly slowed or if the TimerPeriod value is too small. For example, a common application for timer events is to display data. However, because displaying data can be a CPU-intensive task, some of these events might be dropped. For digital I/O objects, timer events are typically used to display the state of the object.
To see how to construct a callback function, refer to Create and Execute Callback Functions or the example below.
You use the start function to start a DIO object. For example, to start the digital I/O object dio:
After start is issued, the Running property is automatically set to On, and timer events can be generated. If you attempt to start a digital I/O object that does not contain any lines or that is already running, an error is returned.
A digital I/O object will stop executing under these conditions:
The stop function is issued.
An error occurred in the system.
When the device object stops, Running is automatically set to Off.
This example illustrates how to generate timer events for a DIO object. The callback function daqcallback displays the event type and device object name. Note that you must issue a stop command to stop the execution of the object.
Note: You cannot use the legacy interface on 64-bit MATLAB®. See Working with the Session-Based Interface to acquire and generate data on a 64-bit MATLAB.
You can run this example by typing daqdoc7_2 at the MATLAB Command Window.
Create a device object — Create the digital I/O object dio for a National Instruments® board. The installed adaptors and hardware IDs are found with daqhwinfo.
dio = digitalio('nidaq','Dev1');
dio.TimerFcn = @daqcallback dio.TimerPeriod = 5.0
Start the digital I/O object. You must issue a stop command when you no longer want to generate timer events.
The pause command ensures that two timer events are generated when you run daqdoc7_2 from the command line.
delete(dio) clear dio