LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Changing the value of a control in a subvi

I think the answer is out there somewhere but I've read through many threads found with searches similar to this topic so sorry to repost...
 
I would like to change the value of a top-level VI control from a sub-vi.  The data is being used as a parameter, I was thinking about using a local/global but I've seen this discouraged.  Is there a way I can do it with references, property, or invoke nodes (or some other suggested method) ?
 
I am guessing that if I am not using globals I will need to wire into the sub-vi?
 
Dave
0 Kudos
Message 1 of 7
(3,862 Views)
I'd like to clarify what I am trying to do a bit more...
 
The sub-vi has a control of the same type as the top-level vi.  The inital control value is being passed into the sub-vi from the top-level vi.  The sub-vi uses the control value in several places through local variables (reading and writing to it)
 
I would like to modify the vi so the top-level vi control value changes whenever the sub-vi changes the control value that is passed to it.
 
My last attempt was to make a refnum control in the sub-vi (by dragging from top-level block diagram to sub front panel) and then creating a property node from that refnum control.  Using the property node "value" did not give me the value of the control from the top-level vi as I had hoped.  Wiring it to a terminal that was expecting the same type of control (a cluster of two numerics) caused a wiring conflict.
 
I noticed elsewhere in the code that the programmer used a text file to save options (unfortunately the control I am working on was not originially included in the options).  There is a vi that, when called, either reads or writes to the text file.  From a C/C++ programming perspective it seems quite odd to me not to just keep all this data in memory and pass it around.  Is using a file to store variables a typical practice in LV programming (even when they are retrieved multiple times during program execution) ?
0 Kudos
Message 2 of 7
(3,858 Views)


@davey31415 wrote:
My last attempt was to make a refnum control in the sub-vi (by dragging from top-level block diagram to sub front panel) and then creating a property node from that refnum control.  Using the property node "value" did not give me the value of the control from the top-level vi as I had hoped. 
Make the refnum control an input connector of the subVI, the wire it to a value property node.
In the main VI, create a reference to your desired control and wire it to that connector when you call the subVI.
0 Kudos
Message 3 of 7
(3,854 Views)

I must not have wired the reference, I think I did everything else.

How about using files to store/retrieve data?  It seems to me it would make more sense to use a reference to a cluster throughout the entire program unless data needs to be saved between program uses. 

 

 

0 Kudos
Message 4 of 7
(3,836 Views)


@davey31415 wrote:
How about using files to store/retrieve data?  It seems to me it would make more sense to use a reference to a cluster throughout the entire program unless data needs to be saved between program uses. 
That really depends on the purpose. Files have the advatage that updated data is typically not lost if the program or computer crashes. 😉
0 Kudos
Message 5 of 7
(3,824 Views)


@altenbach wrote:


@davey31415 wrote:
My last attempt was to make a refnum control in the sub-vi (by dragging from top-level block diagram to sub front panel) and then creating a property node from that refnum control.  Using the property node "value" did not give me the value of the control from the top-level vi as I had hoped. 
Make the refnum control an input connector of the subVI, the wire it to a value property node.
In the main VI, create a reference to your desired control and wire it to that connector when you call the subVI.



Okay, I've tried that, here's the error I'm running into:

You have connected wires of 2 different types: source is cluster of 2 elements, sink is cluster refnum of 2 elements.

Is there some way to make these compatible (like a cast maybe) ?

Dave

0 Kudos
Message 6 of 7
(3,806 Views)

Never mind, I was creating a property node for the refnum (I guess that's obvious from the error message when you think about it).  I was wondering why there wasn't a reference input for the property node.  I overlooked the 'Property' item near the bottom of the context menu.  I think in the future I will just select 'Property Node' from the Application palette.  Thanks for the assistance!

 

Dave

 

0 Kudos
Message 7 of 7
(3,802 Views)