From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

subvi does not work properly when called inside a vi

Hello Every body

thanks for your help. i am using a sub vi for sine signal generation. as a vi it works fine. but when i called this subvi inside another VI it gives some problems. for example timer indicator works properly.it reinitializes as well in the sub vi, but in the main VI it does not work properly. means does not count the time.in the sub vi on the fly i can change the values of frequency and amplitude in real time, but when i use as sub vi, it does not reponse as i change the values in the control arrays.similarly pause and continue works properly in the sub vi, but once again in the main VI, it does not work properly.graph indicator also work properly in the sub vi. but here once again it does not work properly in the main VI.the pause resume indicator also does not blink, when it is continue. in the subvi it blinks very well.generally why the sub vi does not work properly inside the VI?i am sending my VI and sub vis.
any tips would be highly appreciated.

thanks
Regards
0 Kudos
Message 1 of 6
(2,796 Views)
if you want your main vi's controls to be able to change the sub vi's parameters on the fly you will need to either use references or globals... take a look at the LabVIEW help regarding references...

Dan
Message 2 of 6
(2,791 Views)
I just want to add some more details to Dan's answer. The subVI is acting exactly like you've coded it. The mistake is in understanding how subVIs work. When you call a subVI (or a function in any other language), you pass some parameters to it, the subVI does it's thing and returns values. the subVI does not accept new parameters from the calling VI until it returns to the caller and the caller runs the subVI again. In your case, you have a subVI with a while loop. You have some front panel control wired to the subVI's stop terminal. When first called, the value is false. So the subVI will keep running until the subVI's stop button becomes true but you cannot change it from main until the subVI finishes and returns so the subVI will never stop. As Dan says, the solution is pass references of front panel controls to the subVI and have the subVI monitor those references for changes and to update references to indicators on Main. You subVI does not need any front panel controls or indicators of it's own.
Message 3 of 6
(2,785 Views)
yes i need to use globals or pass the reference.but how can you give me some example please. like when i would like to pass the timer value to the main VI indicator. or some boolean like blink or other parameter. how it would be. please can you give me an example.

Regards
0 Kudos
Message 4 of 6
(2,771 Views)
here is a quick example of using references....
Message 5 of 6
(2,759 Views)
Sure. Here it is. There's also some shipping examples.
Message 6 of 6
(2,754 Views)