LabVIEW ELVIS RIO Control Toolkit

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
  • The block diagram of the callback VI includes two While Loops. Each CPU executes the code running in one While Loop.
  • The block diagram code of the callback VI contains one While Loop. This loop contains two pieces of code that execute in parallel.
  • The non-callback code stops executing until the callback VI finishes running and frees up one CPU.
  • Using two CPUs for a long time can cause a disconnection between the host computer and the target, because keeping this connection requires using the CPU of the target.
    Note  National Instruments recommends that you use callback VIs to execute short code that handles emergent events.

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:

  1. In LabVIEW, select File»Create Project to launch the Create Project dialog box and create a new NI ELVIS RIO CM project.
  2. 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.
  3. In the Specify a name for the callback VI dialog box, specify a name for the VI and click Save.
  4. 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

Building the Connector Pane

Create Project Dialog Box

Global Variables

Interrupt Express VI

Interrupt VIs

Log in to get a better experience