LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calling Sub VIs more than once.

If I am going to use the same sub VI more than once at the same time do I need to have multiple copies. I read somewhere about a setting for using re-entrant code. I have a sub VI that will control part of a card. There are 16 cards. The 16 cards have 4 functions. There is a separate VI for each function. The cards will be processed in parallel. Do I need to have a separate copy of the sub VIs for each card?
0 Kudos
Message 1 of 11
(3,790 Views)
You can make the VI reentrant by going under VI Property/Execution and then check the checkbox for Reentrant Execution.

Hope this helps,
Dan
0 Kudos
Message 2 of 11
(3,778 Views)
Does that mean that I will need to do this if I am going to call it more than one time?
Just trying to clarify.

Thanks
0 Kudos
Message 3 of 11
(3,773 Views)
When a VI is non-reentrant, it receives a location in the computer memory to run, and can only run once at any given time. This means that if you call the VI from two different places at the same time, one place will wait until the VI has finished running and only then will run the VI. If you set the VI to reentrant, each instance of the VI in your program will receive its own chunk of memory and they can run in parallel. This would be a problem, for example, if you're trying to use your serial port from two places at the same time.
If your VI has parameters for calling your card (like an address or reference) then you can make it reentrant. While making a copy of the VI doesn't mean you need to create another copy of the VI on the hard drive, there's also no reason for duplicating code. If you find that you need to duplicate code, think about what you can do to avoid this.
By the way, search this site for "functional globals" for some information about "the right way" to pass data between different VIs using the properties of non-reentrant VIs.
Hope this helped.

___________________
Try to take over the world!
Message 4 of 11
(3,761 Views)
When I go to the Execution options. Reentrant is greyed out. Any Suggestions?
0 Kudos
Message 5 of 11
(3,732 Views)
I'm not sure, and I'm not near a PC with LV at the moment, but I think if you set the VI priority to subroutine, you can't set it to be reentrant.

___________________
Try to take over the world!
0 Kudos
Message 6 of 11
(3,724 Views)
Hello Charles,

The subroutine priority should not prevent a VI from being declared reentrant.

Is only the reentrant option grayed out? Or all execution options unavailable? If all are unavailable it would indicate that the VI is locked or missing its block diagram.

You can unlock the VI by selecting the Security option under VI settings and selecting Unlocked. If the diagram is missing you will not be able to change the VIs properties.

Regards,

Matt F
0 Kudos
Message 7 of 11
(3,681 Views)
Thanks Matt.
I never actually got around to checking that...

___________________
Try to take over the world!
0 Kudos
Message 8 of 11
(3,675 Views)

I want to run a VI more than once at a time, but not as a subVI. Can it be done? There are multiple furnaces that I am tracking with a VI, but I want it to be such that each one can be tracked separately from the others.

 

I simply used a ring and a case structure around the DAQmx create channel subVI.

0 Kudos
Message 9 of 11
(3,237 Views)

If you know the number of VIs in advance, the easiest thing to do is to place several copies of the VI on the block diagram and make sure they are not connected. This will cause them to run in parallel.

 

If you need to start running them and keep the calling VI running, you will want to use the Run VI method. You can search for "dynamic loading" or "dynamic VIs" to see some more details an examples. There should also be some example in the example finder (Help>>Find Examples).


___________________
Try to take over the world!
0 Kudos
Message 10 of 11
(3,193 Views)