This content is not available in your preferred language.

The content is shown in another available language. Your browser may include features that can help translate the text.

Read and Write Main VI Control/Indicator Value from a SubVI

Updated Jan 3, 2019

Reported In

Software

  • LabVIEW

Programming Language

  • LabVIEW G

Issue Details

  • I want to update my top-level VI controls and indicators with the "live" status of the subVI control and indicators values while the subVI is executing. How do I do this?
  • I have some controls and indicators in my main VI, and I want to access their value in a subVI. How can I read and write values of main VI control or indicator from a subVI?

Solution

In LabVIEW, each control or indicator on the front panel has its own reference that can be passed to any part of the project and be used to access any property, including the value. The following steps explain how to create a reference node of a control or indicator, pass it to a sub-VI, and read/write the control/indicator in the sub-VI.
 

In the Main VI,

  1. Open the block diagram and right-click the control/indicator that you want to access in the sub-VI.
  2. Click Create >> Reference to create the reference node of this control/indicator, then drop it on the block diagram.

In the Sub-VI,

  1. Open the front panel and add a Control Refnum. There are several ways to do that:
    1. Copy a constant of this control type from the main VI and paste it onto the sub-VI's front panel:
      1. Right-click the reference node you created in main VI, and select Create >> Constant.
      2. Select the constant node and press <Ctrl+X> to cut it.
      3. Open the subVI front panel and press <Ctrl+V>. The constant node will be pasted and automatically changed to a control of the same type.
    2. Create a Control Refnum directly to the Sub-VI's front panel:
      1. Right-click the subVI's front panel, and select Controls Palette >> Modern >> Refnum >> Control Refnum.
      2. Select the appropriate VI Server Class based on the type of control in the main VI. Right-click the Control Refnum and select Select VI Server Class >> Generic >> GObject >> Control >> [select type of control]
  2. In the sub-VI's block diagram (see Figure 1), create an implicit Property Node for the refnum. It can be found at Functions Palette >> Programming >> Application Control >> Property Node.
  3. Wire the Control Refnum to the reference input of the implicit Property Node.
  4. Click the drop-down list of the Property Node and select Value as the input parameter.
  5. Right-click the parameter and select Change to Write to allow for inputs into the parameter.
  6. Wire the varying data to the Value input of the implicit Property Node.
 
Figure 1: Sub-VI DigNum Refnum Passed to a Property Node 
 
  1. Link the Control Refnum to a terminal on the connector pane of the sub-VI, so that the reference can be passed from the main VI to the sub-VI.

In the Main VI,

  1. Open the block diagram (see Figure 2) and wire the reference node to the newly created terminal of the sub-VI.
 
 
Figure 2: Numeric Control Reference Passed to the Sub-VI
 

Additional Information

When running the main VI, any changes made to the control in sub-VI will be updated in the main VI as well because they are linked through the control reference. 

The property node used can be utilized to access not only the value, but also a variety of other control/indicator properties. Refer to LabVIEW 2018 Help for more information.

WAS THIS ARTICLE HELPFUL?

Not Helpful