07-16-2011 08:08 PM
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!
07-17-2011 04:36 AM - edited 07-17-2011 04:38 AM
Hi newbie217x, can you please show your vi?
Mike
07-17-2011 03:18 PM
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
07-17-2011 09:42 PM
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.
07-18-2011 03:31 PM
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.
07-18-2011 04:01 PM
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.
07-18-2011 05:27 PM
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.
07-18-2011 06:46 PM
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.
07-18-2011 07:12 PM
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
07-18-2011 07:37 PM
So, what is wrong with reading a configuration in a loop?