LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Input updates of a sub-VI with while loop

Solved!
Go to solution

Hi there guys! This is my first serious experience with LabVIEW, so the question may seem trivial to you but it's not obvious to me how to neatly solve this. So I'm making a setup which incorporates a number of flow controllers, a temperature controller, some basic DAQ tasks, some valves and a mass spectrometer. All these need to be automized through LabVIEW. I started off by making a VI for each of the separate tasks which is going fine. Now I need to combine these into one master experiment VI, and of course I'm running into trouble.

 

The problem is that I want of course to control this experiments having some selected buttons/dials/whatever on the front panel of the main VI. However, each of these VI's is running a while loop in which does continuous communication/data acquisition/whatever. Of course I want to change parameters online. if I just naively attach them to the input of the sub-VI these will only be read when the sub-VI is started, not during every iteration of the while loop.

 

I have added a very basic example of the problem, so we are all on the same page. The main VI has a button, the state of which should update something into the sub-VI. However once the sub-VI is started it takes control of the execution and the main-VI appears to be ignored (seems to hang) even if the program has plenty of free time to read the buttons and update the input. What is the official solution to this kind of problem? From my programming experience I would prefer to keep the sub-VI intact, so I can use it as a reusable standard library. Of course a similar question can be asked for the sub-VI output which will only be updated after the execution is completed (which is never during normal operation).

 

ps. I'm using LABView 8.6 on XP

Download All
0 Kudos
Message 1 of 10
(7,141 Views)

Hey Jasper,

 

i think you are not alone with your problem.

If you have a Sub-VI in your code it will start working when all inputs are allocated with values. Then it will start, run untill it's finished and return the output values.

In your case you have a while loop inside your Sub-VI, so either you stop your Sub-VI over the associated Frontpanel or you create anything in your code that will automaticly stop your sub vi, or the last thing you get rid of the while loop inside your Sub-VI and make a loop in your Main-VI.

You can edit the properties of your Sub-VI so that the Frontpanel opens when it's executed. Just go into "File" -> "VI Properties". Choose "Window Appearance", click "Customize" and hit the two fiels called "Show front panel when called" and "Close afterwards if originally closed".

 

Stefan

0 Kudos
Message 2 of 10
(7,131 Views)

Thank you for the prompt reply! I still have some questions left though.

 

* For the first option I would have 5 front panels showing lots of buttons of things I can and want to change between experiments, but do absolutely not want changed within any single experiment. So there would be an overkill in windows and buttons, part of which I dont even want to be pressed. It could work if I'm careful, but is not quite as elegant as having only the main VI front panel which shows the 4-5 things I want to influence/show within that particular experiment.

* Getting rid of the while loops in the sub-VI requires each of the tasks to be split into 3 sub-VIs? Initialization, iteration and cleanup? Then I would create for each of my tasks a seperate while loop in the main VI and run these in parallel? I guess that will work even though it'll bloat my main VI.

 

There is no way ever to pass execution back to the main VI while a sub-VI is still running? Can one main VI have multiple sub-VI's even run in parallel at all?

0 Kudos
Message 3 of 10
(7,113 Views)
Solution
Accepted by topic author JasperS

The best way to set up a program in LV is to first initalize your settings, then start a while loop where you communicate/aquire data or whatever and then, after the while loop is finished close and cleanup your references.

Inside the while loop you can put your code into several Sub-VIs and it is possible to run those in parallel but I defenetly don't recommend the use of while loops in Sub-VIs, especially without opening the front panel or an stopp criteria.

If your code is completly executed up to your Sub-VI, the main.vi will wait for the sub-Vi to finish before continuing the code.

 

 

Download All
Message 4 of 10
(7,093 Views)

Thanks again!

 

I will go change my code. Chop up all the VI's in 3 parts. Back to the drawing board then!

Still I think it is strange there is a fundamental difference in how parallellism/execution is treated if you have everything in one main VI versus with sub-VI's.

Sub-VI's lost some of their attractiveness for me today.. 🙂

0 Kudos
Message 5 of 10
(7,079 Views)

I don't wanna say Sub-VI are bad. I love them in many ways. But in my opinion you need to think about using them.

Especially when you tell me your initalizing and cleaning up. Do you really need to do this every time? Isn't it sufficient to do this at startup once and then when you're done with your program?

And if you want to exchange data between different VIs there are a few possibilities.

0 Kudos
Message 6 of 10
(7,072 Views)

Owyeah I forgot. Your code is in version 9, while I have only LabVIEW 8.6 available.

Could you put them here again saved in a way I can open them also?

 

Thanks!

0 Kudos
Message 7 of 10
(7,071 Views)
Sorry. Now it should work.
Download All
0 Kudos
Message 8 of 10
(7,049 Views)

hi,

 

 

 sorry for posting here cos i have posted my question in forum but i didnt get  the solution...

 

 

but from ur answer i think i'll get my solution...

 

i dont want to open  the front panel of the subvi....

i create the sub vi (3 terminal) which has two input(no_of_pins- it'll initiates the For loop and  then Enumerator to  select the signal to be display)  and one output is Graph( it'll display according by the signal was selected)..

 

 

 My request is pls run only subvi and give no of pin as more than 1 and select the enum for signal... u'll find the waveform in the graph....

 

 

And now my question is:

 

now i create new VI as name as MAIN_Prg.vi should have two control (ie one for the FOR loop and another one is Enumerator for the Signal) and only one indicator  as Graph to show the waveform....

 

the problem after im selecting the signal from the enumerator  the signal waveform is updatin in the subvi and the graph indicator is empty.....

 

i think my question is clear for u....

 

i begineer for the labview.... pls help me to finish this task.... 

 

Regards,
N. Srinivasan
Download All
0 Kudos
Message 9 of 10
(6,849 Views)

srinivasan.accent@gmail.com wrote:

hi,

 

 

 sorry for posting here cos i have posted my question in forum but i didnt get  the solution...

 

 

but from ur answer i think i'll get my solution...

 

i dont want to open  the front panel of the subvi....

i create the sub vi (3 terminal) which has two input(no_of_pins- it'll initiates the For loop and  then Enumerator to  select the signal to be display)  and one output is Graph( it'll display according by the signal was selected)..

 

 

 My request is pls run only subvi and give no of pin as more than 1 and select the enum for signal... u'll find the waveform in the graph....

 

 

And now my question is:

 

now i create new VI as name as MAIN_Prg.vi should have two control (ie one for the FOR loop and another one is Enumerator for the Signal) and only one indicator  as Graph to show the waveform....

 

the problem after im selecting the signal from the enumerator  the signal waveform is updatin in the subvi and the graph indicator is empty.....

 

i think my question is clear for u....

 

i begineer for the labview.... pls help me to finish this task.... 

 


 

Knock off all of the duplicate threads. Post the same question again and I'm reporting you to the moderator. Your question has already been answered!
0 Kudos
Message 10 of 10
(6,836 Views)