Using Callback VIs to Handle Interrupts (ELVIS RIO Control Toolkit)
- Updated2023-02-21
- 3 minute(s) read
An interrupt is a signal indicating an event that needs immediate attention. You can use interrupts to alert the target to a high-priority condition that requires the interruption of the current block diagram code that the target is executing. To trigger an interrupt, you can use the Interrupt Express VI or Interrupt Low Level VIs.
You must use callback VIs to handle interrupts. The Callback VI contains code that handles interrupts and runs when the interrupt triggering occurs.
Considerations for Callback VIs
When you create or use a callback VI, take the following factors into consideration:
- Callback VIs are of a time-critical priority, which is the highest priority in block diagram code on RT targets. This means that the priority of callback VIs is higher than that of any Timed Loops on RT targets. To avoid unexpected timing behavior, do not add a Timed Loop to the block diagram of callback VIs.
- You can use callback VIs to unregister or destroy interrupts. When you unregister or destroy an interrupt, the interrupt triggering stops. Destroying an interrupt also releases the resources associated with the interrupt.
- To communicate between a callback VI and a non-callback VI, you must use global variables or function global variables, which help access and pass data among VIs.
- A callback VI can use one or two CPUs, as described in the following table.
Scenario | Use Case | Note | ||
---|---|---|---|---|
One CPU Used | The block diagram of the callback VI includes only one While Loop. This loop does not contain pieces of code running in parallel. | The non-callback code keeps executing when the callback VI runs. | ||
Two CPUs Used |
|
|
Creating a Callback VI
To create a callback VI, you must ensure the connector pane of the VI meets the following requirements:
- The connector pane uses the 4 x 2 x 2 x 4 pattern.
- The data type of the top-left terminal is unsigned 8-bit integer.
- The top-left terminal is a recommended terminal.
You can also create callback VIs from templates by completing the following steps:
- In LabVIEW, select File»Create Project to launch the Create Project dialog box and create a new NI ELVIS RIO CM project.
- In the Project Explorer window, right-click the NI ELVIS RIO CM target, select Create Callback VI, and select one of the following options:
- IO IRQ—Creates a callback VI that handles I/O interrupts, such as analog and digital input interrupts.
- Timer IRQ—Creates a callback VI that handles timer interrupts.
- In the Specify a name for the callback VI dialog box, specify a name for the VI and click Save.
- Click OK when LabVIEW finishes creating the VI and adding this VI to the NI ELVIS RIO CM target. You can find the callback VI when you expand the NI ELVIS RIO CM target.
Opening a Callback VI
In the Project Explorer window, you can always double-click a callback VI under the target to open and edit this VI. When you add multiple callback VIs under the target, use one of the following methods to locate the callback VI that a VI uses:
- Double-click the Callback VI reference that you wire to the Register Analog Input Interrupt VI or the Register Digital Input Interrupt VI to open the callback VI that a Low Level VI uses.
- Right-click the Interrupt Express VI and select Open Callback VI from the shortcut menu to open the callback VI that the Express VI uses.
Related Information