LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Running background VIs without halting the calling VI

Hi all,
 
I've been programming in LabVIEW (currently using 7.0, 7.1 and 8.0 on three different machines!) for a few years and am having trouble working out a quick and simple methodology for programming the following requirement:
 
I have a VI which acts as a front panel, from where a user can call up other VIs that perform certain operations. On this front panel are a series of indicators which need to be constantly updated at a rate of approx' twice a second. The problem I have is: if a subvi is called, the calling vi (front panel) halts until this subvi is finished. However, the subvi makes changes to some of the values that the front panel displays, so the front panel must not freeze otherwise the indicators will not be updated. I know there are ways of calling subvi's by reference, and flagging the Do Not Wait for this vi boolean such that it then runs in the background in parallel, but there must be a simple way of coding the "frontpanel.vi" diagram so that it keeps updating regardless of running subvis?
 
Attached is an example of what I mean.  The values are updated to a Global, and the front panel reads the global every 500ms. When the subvi OperationA.vi is called, the front panel halts, and hence the changing Global value is not updated on the front panel indicator. This attachment is a LV 7.0 library. If anyone makes changes, please export as 7.0 if possible. I do have access to 7.1 and 8.0 on other machines if necessary.
 
Any help much appreciated Smiley Happy
 
Many thanks,
 
Riggy
 
 
0 Kudos
Message 1 of 28
(4,110 Views)
One thing you could do is use references to those front panel controls instead of global variables. Pass a reference to the subvi, then use the "value" property node in the subvi to set the value on the front panel. It will update when you set it. I do this regularly and it seems to be what you want.
Message 2 of 28
(4,094 Views)
Hi Marc A,
 
Would this still halt the front panel vi? Smiley Indifferent
 
Plus I have about 50 indicators for many different things, it would a nightmare to send them all as references into each and every subvi I create.
 
Thanks for your advice Smiley Happy
 
Riggy
0 Kudos
Message 3 of 28
(4,084 Views)

LabVIEW runs multithreaded, so VI's started in parallel also run in parallel. I use this in my programs e.g. to permanently check 'safety switches' (of course the life critical are wired in hardware) and e.g. Display warning lights, run an alarm buzzer, ...

The tricky thing is to get such an parallel running VI started and stopped correctly. I use the following scheme:

a) use a global variable to pass run/stop status
b) set up a sequence as following:
  1st frame: set the global to 'RUN' 
  2nd frame: run the main application part and the sub-vi in parallel
c) to stop the parallel running VI the main loop must set the global to 'STOP'. Otherwise you will not be able to exit this frame of the sequence.

I should have an simple example somewhere (LabVIEW 8.2). Let me know if you need it.

  Roland

0 Kudos
Message 4 of 28
(4,082 Views)

Yes, the front panel would still halt operation, but you can change the values of the controls without any code running in the front panel by using references. I understand what you mean though about having a lot of them. The other option is to use globals like you are doing, but calling the subvi dynamically so that it starts to run and your main VI continues to run as well. Although I wouldn't personally go this route if it's just for updating front panel controls. I try to avoid globals as much as possible.

If you aren't familiar with calling VIs dynamically, it's done by using Open VI Reference, then using an invoke node to call the Run VI method. Then just wire false to the "wait until done" input.

0 Kudos
Message 5 of 28
(4,077 Views)
RExler, good information there. However, he is talking about calling a subVI and having it run in parallel with the calling VI. What you are talking about is running 2 subVIs simultaneously, which LabVIEW handles automatically as separate threads.
0 Kudos
Message 6 of 28
(4,075 Views)

Hi RExlter,

Thanks for the advice. In truth my application is far more complicated and parts of my code already use dynamic linking to call certain subvis and leave them running in the background on an internal loop without waiting for them to finish. These background subvi's constantly take measurements and monitor switches to ensure certain criteria are met etc. to allow the code to continue. Unfortunately, I don't want OperationA, as shown in my attachment, to be called this way if I can help it - which is why I was hoping there would be a simple method I hadn't thought of for calling it and continuing the main code. It seems I may have to re-write all the code to do either what you suggest or what MarcA suggests.  I'll think about it and work out what will be best.

Many thanks everyone for your assitance!

Best wishes,

and Merry Christmas!

Riggy

0 Kudos
Message 7 of 28
(4,065 Views)
Hi Marc A,
 
Again, thank you for your advice. Yes, I am beginning to see that I will have to do this, or somehow try using dynamic linking (as you describe). I will think on this overnight, and get on with some hard re-coding tomorrow Smiley Sad
 
Thanks again,
 
Merry Christmas!
Riggy
0 Kudos
Message 8 of 28
(4,066 Views)

Good luck to you.

I have come to certain situations where I want to do exactly what you want. I have wanted to do it so that I could pass inputs to a VI by wire but have it run dynamically, however I never found a way to do it. I figured that if the subVI didn't return any values, there should be a way to have it run in the background.

Maybe we'll see this feature added at some point, but there might also be something that I'm not aware of which would create problems.

0 Kudos
Message 9 of 28
(4,062 Views)
Riggy-

I think I have a solution for you.  First, wrap the whole block diagram of the subvi in a boolean case structure.  Then, make a boolean control (wired to the connector) called "Init" (or something).  Wire "Init" to the big case selector, and make your program run in the false case.  In the true case, set a local variable copy of Init to "false", but do nothing else.

So in your main program, first call the subvi with Init set to true, and all of your variables wired to pass the data.  This sets the control values, but returns immediately.  Then create a reference to the VI and use the "Run VI" method with "Wait Until Done" set to false.  Then the subvi will run in the background with all the data you passed, but the main program will continue as nomal.  This works for me.

Micah

edit: hurrrrr boolean logic

Message Edited by Micah Boyd on 01-17-2007 12:42 PM

0 Kudos
Message 10 of 28
(3,986 Views)