LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to call multiple subvi?

I am creating a menu panel where I can call and control each new sub vi I call. It is only allowing me to call one at a time. How do I go about doing this? I have placed the sub vi and an ok button in an event structure. I am a beginner as you can tell, so any help is appreciated.
0 Kudos
Message 1 of 10
(4,503 Views)

The event case to launch a subVI can't complete executing until everything inside of it (namely the subVI itself) finishes executing. This is fundamental in the dataflow paradigm, so you'll see it everywhere in LabVIEW. A structure can't complete executing and release its outputs until everything inside of it finishes.

What you'll want to do is call the VI asyncronously. This will not be a normal subVI call. Instead, you'll need to use a technology called VI Server to programmatically load and run the VI without waiting for it to finish. Here's a general page with some tips to get started on this. Hope this helps!

Jarrod S.
National Instruments
0 Kudos
Message 2 of 10
(4,495 Views)
Thanks!
0 Kudos
Message 3 of 10
(4,481 Views)
Hi again. I've read through the articles you've linked, but I am still confused about the vi servers. How do I go about setting up a server?
0 Kudos
Message 4 of 10
(4,469 Views)
I hope the name isn't confusing you. LabVIEW is the server in this case, and is already set up in most cases. VI Server is just a general name for a set of technologies that allow you to automate LabVIEW VIs and LabVIEW as a whole. If you've ever used property nodes before, then you've already used VI Server and didn't know it.

The idea here is that VI Server calls can be used to launch VIs. The VIs in question are located in the Application Control palette. You will want Open VI Reference (input a path to the VI), a few property nodes and invoke nodes, and finally Close Reference to release your resources when you're done, just like you would close a file when you're done.

Here's an example of what I mean. Hope this helps! (This was written in LV 7.1)
Jarrod S.
National Instruments
0 Kudos
Message 5 of 10
(4,460 Views)
Thanks. I think I was just confused by the way ti was worded.
0 Kudos
Message 6 of 10
(4,450 Views)
Jarrod

I came accross your post regarding calling multiple subvis using the VI Server.  can I somehow incorporate the call by reference so that i can pass parameters to the subvi that i want to call but not wait until it finishes
- James

Using LV 2012 on Windows 7 64 bit
0 Kudos
Message 7 of 10
(4,323 Views)
You can't use a Call by Reference Node, unfortunately. This is a dynamic call in the sense that you control when to load and unload the VI, but a Call by Reference node executes the VI in the same manner as a subVI. It waits for the call to complete and then outputs the return data.

If you want to pass in parameters to a VI you are calling without waiting for it to finish, then you need to use some invoke nodes with your VI reference called Control Values >> Set Control Value (Variant). This has two inputs, a control label string input and a variant input. You wire in the name of the control you want to set (watch for typos!) and then wire in the appropriate data type into the variant input. You must call this invoke node N times for the N controls you want to set. This process is a little more cumbersome, but will be necessary in this case.

Alternatively, you could set your parameters using global variables that the caller writes and the asynchronous VI reads, but this is a sloppy approach if you're calling a lot of VIs, or multiple instances of the same VI, etc.
Jarrod S.
National Instruments
Message 8 of 10
(4,315 Views)
If the number of subVIs you want to call is not too large, try putting them in parallel loops with a case structure (simple state machine with producer consumer flavor). The cases would be Idle, Run, Stop, Exit. Send commands (Idle, Run, Stop, Exit) and parameters via queues. Another queue can return status and any data generated by the subVI. The parallel loops all start when the main program starts and enter the Idle state until they receive a command from the main program. The subVIs would be in the Run cases. Make sure each loop has a short wait to assure CPU sharing.

Lynn
Message 9 of 10
(4,310 Views)
Thanks for the tips and the quick response.
- James

Using LV 2012 on Windows 7 64 bit
0 Kudos
Message 10 of 10
(4,304 Views)