From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

Using Control References to Pass Access of Front Panel Controls to SubVIs

Code and Documents

Attachment

You can pass access to front panel object values, properties, and methods to subVIs by using explicitly linked control references. Explicitly linked control references consist of a general property or invoke node with an explicit control reference wire to its input. 

In this example program's main VI, there is a Control Reference constant for the Waveform Chart Indicator and the Boolean Stop Control. The explicit references to these front panel objects are wired to the subVI input terminals.

The subVI has two Control Refnum controls, one corresponding to the Waveform Chart and one to the Stop boolean control. Looking at the subVI block diagram, we can see what is being done with the control and indicator from the main VI. The Waveform Chart Refnum is fed to a Property Node that turns on autoscaling for the chart. This refnum is then passed inside the while loop where it is used to write a value to the chart in the front panel of the main VI. Meanwhile, the Boolean refnum is being used to read the current value of the Boolean control in the main VI's front panel to determine when the user selected the stop button.

This example illustrates how to read and write values from a subVI to controls and indicators in a main VI. A similar example that would be useful involves doing data acquistion in a subVI, displaying the data in the main VI, and terminating the data acquisition being done in the subVI from the main VI.

More more information on creating Control References, see the Concept Document on NI Developer Zone titiled "Control References: Overview".

How to Create This Setup from Scratch

Modifications to the SubVI:

  1. On the front panel place down a Control Refnum from the Controls » Refnum sub-palette
  2. Drop a Push Button from the Controls » Boolean sub-palette into the Control Refnum (similar to the two step process involved in creating an array)
  3. Modify the Connector Pane for the sub VI to include the Control Refnum as an input to the sub VI. Right-click on the icon in the top, right corner of the front panel and select Show Connector (choose an alternate pattern if necessary)
  4. In the block diagram, place the Control Refnum terminal outside of the while loop and wire it up to the left side of loop boundary
  5. Place down a Property Node inside your while loop on your block diagram, from the Functions » Application Control sub-palette
  6. Wire up the Control Refnum to the Reference input of the Property Node
  7. Right-click on the Property and select Properties » Value
  8. Wire the output of the Property to the Conditional Terminal of your while loop

Modifications to the Main Program:

  1. Create a reference from your boolean control that you want to use to control the sub VI (turn it on and off) by right-clicking on the boolean control and selecting Create » Reference
  2. Wire the reference terminal in your block diagram into the corresponding control reference input of the sub VI
  3. If you are using a Stop button, set the mechanical action of the button to Switch Until Released by right-clicking on the button on the front panel and selecting Mechanical Action » Switch Until Released


Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors