LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Updating Control Through Sub-VI

Solved!
Go to solution

I have two numeric controls on the front panel of my application which I would like to update while a sub-VI is running (to be specific, multiple sub-VIs run the same second sub-VI, and I want the second sub-VI to update the numeric controls). I have found a few ways to do this, but I'm not sure which is best:

 

1) One possibility is sending references to the controls to the sub-VI, and that works fine except that this means I would need to wire references to multiple sub-VIs, and possible even more as I continue developing the application.

 

2) Another option is using a static VI reference, getting the front panel property, getting the controls[] array, then figuring out which indices are the controls I want (which seems like a horrible hack)

 

3) I guess a final option is using a functional global (or just a global) to store a reference to the controls (which I haven't actually tried, but it seems like it should work...)

 

Is there a commonly-accepted method for doing this?

 

PS The numeric controls actually get their values from a functional global, so I essentially just need a way to tell the front panel to re-read the functional global.

Message 1 of 4
(3,314 Views)
Solution
Accepted by JaWiB

Couple of things:

 

1) Use a queue: Put your front panel controls in a loop reading their data from a queue (allowing the loop to suspend waiting for data). Write to the queue from within your "second sub-VI".

 

2) Assuming you're using LV 8.x, try network shared variables and binding your front panel controls to them. Write new data to the shared variable from within your "second" sub-VI, the front panel controls will update automatically....no code required. I have used this method with great success but limit it so that there is only one "publisher" (writer) to any network shared variable but allowing multiple "subscribers" (readers).

 

Both of these work well because your front panel controls are updated only when new data is available. No code continually spinning it's wheels "polling".

Message Edited by Bill@NGC on 08-07-2009 11:32 PM
Message 2 of 4
(3,291 Views)

Thanks! I'll try your solutions tomorrow.

 

Just one more question: do you know offhand if there are any significant performance hits associated with these methods? I've been warned against using global variables, and I assume network shared variables qualify, but perhaps that's only to avoid race conditions (which having only one publisher would avoid, I presume)?

 

I can always do profiling, but I thought I'd ask in case you have immediate insight 🙂

0 Kudos
Message 3 of 4
(3,262 Views)

JaWiB wrote:

Thanks! I'll try your solutions tomorrow.

 

Just one more question: do you know offhand if there are any significant performance hits associated with these methods? I've been warned against using global variables, and I assume network shared variables qualify, but perhaps that's only to avoid race conditions (which having only one publisher would avoid, I presume)?

 

I can always do profiling, but I thought I'd ask in case you have immediate insight 🙂


No.

 

Yes any time you have more than one writer of a widget you have to think about who is doing it when.

 

The Queue approach will give you maximum control since you can look at each update and think about it if required.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 4
(3,243 Views)