Read and Write Main VI Control/Indicator Value from a Sub-VI

Updated Feb 12, 2018

Reported In

Software

  • LabVIEW

Programming Language

  • LabVIEW G

Issue Details

I have some controls and indicators in my main VI, and I want to access their value in a sub-VI. I have used Global Variable to share values in my project which can't not change displaying in front panel. How can I read and write value of main VI control or indicator in a sub-VI?

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 would help you to create a reference node of a control or indicator, pass it to a sub-VI and read/write the control/indicator in sub-VI.
  1. Open the program diagram of your main VI.
  2. Right-click the control/indicator that you want to access in sub-VI. Click Create>>Reference to create the reference node of this control/indicator, then drop it on the diagram.
  3. To pass a reference to a sub-VI, you have to add a control of "reference" type. There are several ways to do that, and the most convenient method is to copy a constant of this type and paste on the sub-VI front panel:
    1. Right-click the reference node you created in main VI diagram, and select Create>>Constant.
    2. Select the constant node and press <Ctrl+X> to cut it.
    3. Open the sub-VI front panel and press <Ctrl+V>. The constant node will be pasted and automatically changed to a control of the same type.
  4. Link a terminal of the sub-VI to the "reference" control, so that you can pass the reference of main VI to the sub-VI.
  5. In the sub-VI, add a Property Node from Function Panel>>Programming>>Application Control and wire it to the "reference" control. 
  6. Click the Property Node and select Value in the drop-down menu. You can right-click it and select Change to Read/Write to change the direction.

This node can not only access the value, but also a lot of other control/indicator property. Refer to LabVIEW 2017 Help for more information.

WAS THIS ARTICLE HELPFUL?

Not Helpful