LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

return value from sub vi?

Dear All,

How can I return a value (number) from a sub vi to the main application? Does it need to be in a certain format?
I´m a beginner in LabView, so please do not retain yourself from a detailed explanation 🙂

regards
oistvan
0 Kudos
Message 1 of 7
(5,526 Views)

Hello Oistvan,

you can tranfer easily data (numbers, clusters, arrays, references...) from and to subvis. you just have to connect the front panel controls and indicators to external terminals.
To do so, go to the front panel, and right click on the vi icon (top right of the window). select "view terminals". from there, you can either add or substract terminals, or choose from one of LV templates.

typically, to input data to the subvi you will want to connect the correlated control to a terminal on the left side of the icon. to extract data from the subvi, you'll prefere to connect to related indicator to the right side of the icon of your subvi.

Connection: select a free square from the terminal icon, with the hand or the wire mouse. then select the control/indicator you want to connect to it. the terminal will color itself with the typical color of the kind of datatype (orange for double, green for boolean, blue for integer...).

Now in the main vi, after "relink to subvi" (right click on the subvi icon), you'll be able to connect data to and from your subvi, exactly as for any regular LV function.

note: you can connect any data to those terminals. if the data type is completely incorrect, the wire will break.
if the data type connected is compatible, (eg. dbl to uInt), LV will automatically typecast and convert the data type you connect, and will notify you by putting a small red dot on the icon. it is preferable to use same data type, to avoid truncation or other undesirable effects on your data transfer.

Good luck!

-----------------------------------------------------------------------------------------------------
... And here's where I keep assorted lengths of wires...
0 Kudos
Message 2 of 7
(5,520 Views)
A good way to learn the basics is to go through the resources that ship with LV. For example, there is a Getting Started with LabVIEW document that you can open from a link on the LV Getting Started screen (the one that shows when you don't have anything else open). This screen also includes a link to LabVIEW Fundamentals, a Windows help file with a lot of basic information in it.

Finally, do a lot of rummaging around in the examples that ship with LV - there's a bunch you can learn form them.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 3 of 7
(5,506 Views)
Your question is a bit unspecific.
 
If you want the subVI return a values when finished, you would use an output connector assigned to an indicator (any indicator!) of the subVI as Gabi mentioned.
If you want to monitor a subVI value from the calling VI while the subVI is not yet finished executing, things get a bit more complicated but are easily possible, too.
 
 
0 Kudos
Message 4 of 7
(5,498 Views)
How do I monitor a subVI value from the calling VI while the subVI is not yet finished executing?
0 Kudos
Message 5 of 7
(5,292 Views)
This question is also a bit unspecific, as it depends on what you mean by "monitor". Do you want the value displayed on the parent VI's front panel? In this case a straightforward method is to use control references. Pass the reference to the indicator to the subVI, and the subVI can write to the indicator using the reference. There's an example that ships with LabVIEW that shows you how to use control references. Open the Example Finder (Help -> Find Examples), search for "references" and open the example called "Property Nodes".

Another method is to have the subVI write to a global variable. The parent VI would need to periodically read the value of the global variable. This means you would need to have a parallel loop running in your parent VI since the parent VI will be stuck at the subVI call, waiting for it to return. This method is clumsy.

Another method is to open the front panel of the subVI. If the subVI writes the value to an indicator you can see it. You can use the VI Server to open the subVI front panel, or set up the subVI to open its front panel when called. For the former you can again look at examples. For the latter, you set this in the subVI's properties.


Message Edited by smercurio_fc on 07-28-2008 04:58 PM
0 Kudos
Message 6 of 7
(5,288 Views)
Thank you!  I have been using method 3 (opening the front panel of the subvi) but we all hate having windows unexpectedly pop open, so I'm going to use method 1 (control references).
0 Kudos
Message 7 of 7
(5,265 Views)