LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to run a VI parallel to another?

Hi, I am a newbie in LabView and I want to know how to run a VI parallel to another one. I have a SubVI in my program and every time this SubVI is running the program can't react for example for pressing a button. I have to wait until the SubVI is finished. How can I solve this problem?

Thank you
Marco
0 Kudos
Message 1 of 3
(3,075 Views)

Your question is very general, so it's hard to give a precise answer, but I would guess that the subVI and your button are found in the same loop, right?

In LV, there is one very important principle - a "piece of code" will only execute when all the wires leading to it have delivered their data.

If my assumption is correct, what is happening, most likely, is that your subVI takes time to run and the loop will not go to the next iteration until all the code in the current iteration has finished running. That's why you will see that the button was pressed, but nothing happens, because it wasn't read yet, and won't be read until the next iteration.

Making code run parallel in LV is very easy - just place in the diagram so that there is no connection between the two different parts of code. If you place 2 unconnected loops, they will both run in parallel. This is probably the simplest solution to your problem, but you will need some way to synchronize the loops (like when do you run the subVI?). It's customary to have one loop which will be dedicated only to user interface, and you can add as many other loops as necessary. If this doesn't help you, I suggest you post your code (File>>Save with Options>>Development Distribution), so we can provide a specific answer.

To learn more, I suggest you read the LabVIEW user manual. Also, try searching this site and google for LabVIEW tutorials. Here and here are a couple you can start with. You can also contact your local NI office and join one of their courses.
In addition, I suggest you read the LabVIEW style guide.


___________________
Try to take over the world!
0 Kudos
Message 2 of 3
(3,070 Views)
Hi Marco
 
It is always a "hot potatoe" if you want your programm to react on user input if some processing (sub-vi) is running.
 
If you use the producer/consumer - pattern, you have the possibilitie to catch user inputs and execute the operations after each other. This is done using a queue. In an event-structure, which reacts on user inputs, elements (strings, numbers, ... (I use strict type def enums)) are enqueued. In a second loop, which runs parallel to the event-structure loop, the elements are dequeued and passed to a case structure. If you use an enum, you have the value as selectors in the case structure (e.g.: "Init"). If you make the enum a custom control, which is set to strict type def, you can change the enum in one central place and it is updated in each location it is used.
So if the event is dequeued, the corresponding case is executed. If you enqueue new elements during execution of any case by clicking some buttons or other user input, the corresponding cases are executed in the order the elements were enqueued.
 
I prefer to keep this order. If a case is executing, I usually disable all buttons and menus to avoid some bad conditions.
 
Thomas
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
Message 3 of 3
(3,067 Views)