10-08-2009 10:30 AM
Hi!
In my current project I would like to have the user open multiple windows of the same VI. I've made a re-entrant VI:
This is, currently, a very simple VI that just has a numeric control, a loop, and a stop button. I then have a VI that calls the re-entrant VI. I'd like it so that each time the user presses the "Call Re-Entrant VI" button, a new window of this VI is spawned and run.
The first time the button is pressed, the re-entrant VI opens and runs fine. The title of the VI in the title bar is "Re-Entrant.vi:1 (clone)" (as expected). When I try to launch another instance I get this error:
I'm running LabVIEW 2009.
Thanks for your time.
Solved! Go to Solution.
10-08-2009 10:40 AM
I think you can't do this with a static VI reference, because this always points to the same instance of the (reentrant) VI.
You need to open a new instance using Open VI Reference with the 0x08 option (prepare for reentrant run).
Hope this helps,
Daniel
10-08-2009 10:59 AM
That worked as far as getting multiple windows open. However, the VI instances don't run. Even if I enable the option "Run when openned" in the VI Properties under Execution, they don't run when called.
My preference is to not use the Open VI Reference VI to create a reference. If it is the only way, then I will have to. I like the static VI reference because I like the extra layer of pre-run error checking LabVIEW provides me when I use static VI references. If I change the name of the VI all the static VI references are automatically changed. I also do not have to worry about where the VI is in the directory structure during development, or after I have built my project into an executable. I also think it makes the block diagram easier to read.
Thanks for your help!
10-08-2009 11:03 AM - edited 10-08-2009 11:06 AM
Probably you can use a static VI reference, then use a property node to get the VI name, then wire the VI name to "Open VI Reference". I think you have to use the "Open VI Reference" function to open multiple instances of a reentrant VI.
What error do you get when you try to run the several instances?
10-08-2009 11:18 AM
I can run them by pressing the "Run" button. They just don't run when I call them. The "Run" command I'm sending in the invoke node is not starting them. And the option "Run when openned" is not working either.
There is a link to an example under the 0x08 in the "Open VI Reference" VI help, but it isn't openning anything on my machine.
Thanks for the idea on using the static VI reference. I ended up going with the "Path" property and fed that into the "Open VI Reference" VI.
10-08-2009 11:24 AM
If I enable "Wait for done" in the Run Invoke node, the VI clone opens in a "run" state. However, my calling VI is now hung-up waiting for the VI to stop.
Hmmm....
10-08-2009 11:29 AM - edited 10-08-2009 11:33 AM
Here we go. The Close Reference VI was causing my re-entrant VI to stop execution. What do you think of this:
This appears to work. I'd probably want to get the path of my referenced re-entrant VI outside of my loop (since this will remain constant throughout the programs execution). My guess is the Auto Dispose Ref feature will mean that as these windows are closed by my user, their garbage will be collected properly....?
Thanks for your help.
Edit: how odd that my Error Cluster constant in the VI Snippet wasn't saved to the image properly.
10-08-2009 02:59 PM
10-08-2009 03:17 PM
The issue has to do with the references to the VIs not being closed properly. The "Auto Dispose Ref" did not seem to be doing what I had thought it was doing and these references were left in memory limbo. That was why LabVIEW would not let me make modifications to the Re-Entrant.vi after running my code. So now the problem is, if I close the reference after openning it the VI doesn't run. I have made the following modification but dislike my method because I have to pass my array of references through each event in my event node. Probably be better with a queue or maybe there is an entirely different approach I should be doing all together.
10-08-2009 03:43 PM
Thanks for the update. I think the VI references are not disposed when the SubVI has finished, but I would expect them to be disposed when the caller terminates. Doesn't seem to be the case.
Thanks for sharing, the code looks good and I like the approach with getting the VI path from the static VI reference.