Example Code

Displaying a subvi indicator value on a main vi front panel in real time

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

This example demonstrates how to change the value of a Front Panel element from a SubVI. 

 

Description

Did you ever have a subvi running, with some numerical calculations taking place, but your main vi looks frozen because the update does not occur until the subvi is done?

These two example VI's show how to get the SubVI indicator's values and display it on the Main VI Front Panel during execution. In other words, as the SubVI is executing, the indicator value is shown on the Main VI, even though the SubVI front panel is not visible. This technique can be used with any type of indicator, even a progress bar.

You can see that an indicator has been created in the Main VI. From this indicator, a reference has been created. This reference is passed to the SubVI as an input.  In the SubVI, a control refnum was created to accept the reference input from the main. A value property node was created.  The control reference was wired to the value property node. The SubVI indicator is wired to the value input of the property node.

When the SubVI executes, the instantaneous value of the indicator is passed into the property node.  This value immediately shows up on the Main VI Front Panel.

 

To create from scratch, follow these steps:

1.  Create an indicator of the appropriate type on the main vi front panel.

2.  In the block diagram, right click on the indicator and select Create - Reference. The reference object is place on the block diagram.

3.  Create a subvi with code that writes values to an indicator which you want to be displayed on the main vi.

4.  Create a control refnum on the subvi front panel and tie this control refnum to a terminal pane.

5.  In the subvi block diagram, create a value property node, and wire the control refnum to the property node. You may have to right click on the property node and change the mode to Write.

6.  Wire the subvi indicator to the value input of the property node.

7.  In the main vi, drop the subvi into the block diagram, and wire the reference to the subvi input terminal.

8.  Run the main. It will call the subvi, and the main indicator will be updated in real time as the subvi executes.

 

What happens here is that the Main VI reference passed into the SubVI is actually the memory address of the Main VI's indicator variable. In the SubVI, the value property node writes the value that is wired to it into the memory address specified by the control refnum. Since it is the same address as the Main VI indicator, the main is updated from the SubVI during execution.

 

Requirements

 Software

  • LabVIEW Base Development System 2012 (or compatible)
  • If running in a Real-Time context, you will need the LabVIEW Real-Time Module 2012 (or compatible)

 Hardware

  • No hardware is necessary to use this example VI

 

Steps to Implement or Execute Code

  1. Download and open the attached ZIP-file
  2. Open the [Main] ...VI inside the LabVIEW project and follow the instructions on the Front Panel

 

Additional Information or References

Change Value Of FP Element in SubVI - Front Panel.png

 

Change Value Of FP Element in SubVI - Block Diagram.png
 

**The code for this example has been edited to meet the new Community Example Style Guidelines. The edited copy is marked with the text ‘NIVerified’. Read here for more information about the new Example Guidelines and Community Platform.**
- tbob

Inventor of the WORM Global

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

Comments
nurlaila
Member
Member
on

this is very useful. thanks

Laucalvino
Member
Member
on

Very simple example doing exactly what I needed. Thank you.

MAILFERTSeb
Member
Member
on

Exactly what I was looking for. I supposed it was difficult and... NO, it's not difficult!

Thanks.

QUEKEEWEN
Member
Member
on

How to display multiple indicators by using only a single control refnum

tomasz.janicki.tj
Member
Member
on

Fantastic,

is there any trick to make it work on FPGA targets?

 

Cheers

猫の手
Member
Member
on

This is so much useful.

Do anybody know how to apply this method to cluster? Or do I need to take another way?