LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I use a sub VI to read/write to objects on the calling VI's front panel?

Hi,
I'm trying to break a LabView program down into sub VI's called by the main VI and for example want to create a sub VI that will initialise the value of indicators and controls on the front panel of my main VI. I've tried creating a global VI with these in and refering to them in my sub vi. It runs without any errors but they do not get updated in the main VI after the sub vi has changed them. Is this the right way to do this and if so why won't it work?

Thanks,
Dave G
0 Kudos
Message 1 of 3
(2,909 Views)
Give the sub-VI references to the controls and indicators. In the sub-VI you wire the reference inputs to property node(s) and write to the value property. You can obtain the references manually by right-clicking on the control/indicator and create the reference, or you can do it dynamically by using the controls property of the front panel, filter out the ones you need e.g. by name and then send the remaining array of refs to the sub-VI.

Using value properties is not ideal though (execute in the user interface thread etc). Another solution is to make a global (I always use functional globals instead) and make the main VI read the global(s) after the sub-VI has run and set the control and indicator values.

The solutions above are only necessary if the def
aults change and you will build an application of the VIs / want the value saved outside the VI. Otherwise you can just use an invoke node to reset all or individual control and indicators to default, and you can make new values default and save the VI with those...
Message 2 of 3
(2,910 Views)

How do you write to the Globals file using this method?

Scenario:  I have implemented this method (also suggested in a recent post) to read and write control values to a Global file.  The reading part functions well.  The problem is when writing to the Global file.

Case 1:  Writing with Global.vi open.

When writing to the Global.vi file while it is open, the written values appear as expected.  The Global file is closed.  When re-opening the Global.vi file, the recently written values are replaced by the original ones, as if they were not saved.  Note that the Global file was not "saved" manually prior to closing.

Case 2:  Writing with Global.vi closed.

When writing to the Global.vi file while it is closed, the recently written values do not appear after opening the file.

I suspect that the values may be written to the Global.vi file but are not saved.  How do you save values to a Global file when using references to write the values?

 

0 Kudos
Message 3 of 3
(2,749 Views)