LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VI calling itself (run top level)

 

Just out of curiosity, is it possible for a top level VI to call itself?

 

For example, I have an ini configuration file w/ different settings for a simple power supply sweep. I would like to run different configurations one after another. The power supply vi is called 'supply sweep'.

 

While the program 'supply sweep' is running, if I use an invoke node to call 'supply sweep', the execution state is "run top level". The program outputs an error b/c the top level vi cannot call itself. I've tried making the vi re-entrant, but no luck yet.

 

 

Is there a way to get this to work? What is a better solution than creating multiple programs of the same program (i.e. 'supply sweep' calls 'supply sweep 2' which calls 'supply sweep 3', etc, etc.)

 

Thanks!

0 Kudos
Message 1 of 19
(4,572 Views)

Hi newbie217x, can you please show your vi?

 

Mike

0 Kudos
Message 2 of 19
(4,559 Views)

Why you make n identical programs that just use different ini file?

Either make a selection dialog in the Init-section so the user can select Supply N or just loop through all ini file in the designated folder calling the sweep-main in each situation (maybe with a skip-option).

 

But just out of curiosity: it is possible to implement this kind of recursion. Not sure if it directly works with top-level VIs and native recursion, but you just can launch new instances of them dynamically with VI-Server.

 

Felix

0 Kudos
Message 3 of 19
(4,534 Views)

I haven't tried the top level vi as re-entrant yet.

 

I have written my share of re-entrant vi's though and they are a bit of an artform.

In short you can't just drop them down onto the block diagram.

 

They need to use "open vi reference" and make sure you choose the options bitmask wisely, I think 0x08 would be a good choice.

 

You can then use a strictly typed reference to use the call by reference node wich will allow you to wire by connector pane

 

This is just a guess and hope it gets you going.

 

Alternatively, Create a main VI shell,

 

Than call the vi re-entrant 'supply sweep' vi from within.

 

 

 

iTm - Senior Systems Engineer
uses: LABVIEW 2012 SP1 x86 on Windows 7 x64. cFP, cRIO, PXI-RT
0 Kudos
Message 4 of 19
(4,519 Views)

I am attaching a generic vi to hopefully better illustrate what I am trying to accomplish. If you run program 1, it will call program 2 which will attempt to call itself again.

 

The solution I am looking to get is one in which program 2 can successfully call itself again w/o error. As a first pass, I've made program 2 re-entrant, but this doesn't seem to solve the issue. So far, the temp solution I have is to make a new program called program 3 which is identical to program 2. This seems rather redudant, and depending on the configuration file... program 2 may call itself 2,3,4,5, etc. times. It would be optimal to only have 1 instance of program 2.

 

 

Download All
0 Kudos
Message 5 of 19
(4,489 Views)

Based on the little that you've told us, I think you're barking up the wrong tree. I don't see why you need to use recursion to do what you want. You said you want to run different configurations one after another. Why do you think you need recursion to do this? Please describe better what you're really trying to do.

0 Kudos
Message 6 of 19
(4,482 Views)

The reason i need the recursion, is because I need to run nested sweeps.

 

I have a top-level vi that reads through a configuration file to call various subvis to perform specific subroutines.

 

Example:

 

Item #1

power supply sweep

2 to 5 V

+6 V rail

 

item #2

power suply sweep

5 to 10 V

+25 V rail

 

item #3

scope capture

 

The top level program reads the configuration file, and processes the items. The first item, item #1 is a power supply sweep, so it launches the subvi 'power supply sweep'. The controls on the power supply sweep are updated based off of the configuration file. So in this first case, it sets the +6 V rail to 2 V. Once finished, the configuration file reads that another power supply sweep is requested for item #2. Since item #1, the subvi is currently active, I would like a way to nest item #2 immediately following. That is why I am trying to make the subvi 'power supply sweep' recursive. That way, I can re-run the program and feed in the nested value of 5 V to the +25 V rail. Once this value is set, a third nested sweep 'scope capture' is run. Since 'scope capture' is a unique name, I am able to execute this subvi w/o issue. The issue is launching 'power supply sweep' twice since it has the same name.

 

I'm basically just trying to figure out a way for a program to call itself again in the interest of building multiple / infinite nested loops.

 

0 Kudos
Message 7 of 19
(4,470 Views)

You are not looking for recursion, you are looking for reentrant.  (I'm not even sure you even need that.)

 

Recursion is when a file calls itself.  Which is not what you described at all.  Reentrancy is when a given subVI is able to be called more than one time at the same time.

 

Overall, with what you are describing, you should search for the phrase "state machine" and base your architecture on that.

0 Kudos
Message 8 of 19
(4,459 Views)

Sorry, my mistake, this is a re-entrant problem. Hmm... most of the code I am using is already in place, and I only need to make the slight modification as stated above.

 

Is there not a way to accomplish this? (top level vi calling itself again). Program 2 is already set to re-entrant

0 Kudos
Message 9 of 19
(4,454 Views)

So, what is wrong with reading a configuration in a loop?


"Should be" isn't "Is" -Jay
0 Kudos
Message 10 of 19
(4,448 Views)