02-17-2009 10:10 PM
Hello all,
I have a great interest in developing programs that can be used efficiently in different modes of operation (as stand-alone vi's and as subvi's). My goal is to be able to switch states while using the minimal amount of programming code to do so. The common denominator in my programs is that they use the event structure. Before getting into more advanced programs, I wanted to start with the most basic example.
The program I want to write should do the following:
(1) When used as a stand-alone vi, the program should run when the 'run button' changes values. The program stops by the user pressing the 'stop button'.
(2) When used as a sub-vi, a TRUE boolean wired to the connector pane will initiate the program by starting the event. At the end of the event, a TRUE boolean should be wired to the stop button of the while loop so the program stops immediately after completion.
(3) Ideally, the event structure in both instances will be triggered by the same mechanism. I would like to avoid having to use multiple event triggers for the same action. (This would be useful so that the program is more intuitive to use for new users)
The current program I have written so far is unable to do so. I tried using a case structure that changed the value of the 'run button' based on the state of the 'use as subvi' boolean. The problem I am running into is that the 'run button' I am using operates on mecahnical latch action, so I cannot change the value during run-time. To overcome this, I simply introduced another boolean that works as a switch. I am hoping that there is a quick, and easy fix to get around this problem. Thanks for the help!
02-17-2009 10:23 PM
HI
If I am reading this correctly, then you just need to go to the false case of case structure and
connect the false constant instead of wire you have connected.
Hope this helps
Regards
Santosh
02-17-2009 10:58 PM
02-17-2009 11:22 PM
I think then need to use two events for this, if you want to use boolean mechanical action as latch.
Use user defiend events or dynamic register events or the same that you are doing now
02-17-2009 11:26 PM
Why don't you connect the run button to the connector pane of this VI? When you want to run it, you connect a True it its connector.
You would still have an issue as to how to stop the subVI from its calling program. In which case you may want to pass in a reference to a Stop button from the calling program. Then you can OR it with the stop button within the subVI. Or use a notifier or queue. Or use a functional global variable that has a set or get to control whether the subVI runs. Or even a normal global variable.
There are still a lot of details missing as to exactly what you want this program to do. It looks like you have the entire program executing within a single case of the event structure which is not really how event structures are meant to work. I would step back and get this working has a standalone program. Once you have that figured out, throwing in the hooks to make it work as a subVI from a calling program won't be so bad. But when its a subVI, do you want to run as its own loop? Do you want it to pause the operation of your calling VI until the subVI finishes?
What does the RunSubVI (Hide) button do? Tha makes it sound like you have a subVI running below this one? And if so, you have terminology "Is subVI calling?" Do you really mean the VI above this one, or the subVI of this one?
02-18-2009 01:05 PM
Hi RavensFan,
I like the idea of wiring the 'Run' button into the connector pane, but the main reason I introduced the boolean 'Use as subvi' was to make it easier for the user to understand (we've been using the same naming convention for past programs). The second boolean, 'Runsubvi (Hide)' is only there because it helps overcome the problem of changing the value of a mechanical latch during run-time. I apologize for the confusion, I should have been more clear in my description. Also, the event structure has many more events in the stand-alone application that have been removed in this example for simplicity sake. When used as a subvi, I just want a single event (the one that corresponds to the 'run' button) to execute. The other events are reserved for use in the stand-alone application. I hope that makes sense. Here is a revised vi of what I would like to be able to accomplish. Again, I have come up with other ways to make this program work, but ideally I would like to do it with as little programming code as possible. Thanks again for all the help!
02-19-2009 09:21 AM
You will still have to define how you want this subVI to behave if it is called as a subVI vs. called as standalone.
Start with this structure attached.
I would make the subVI button a hidden control. It is connected to the connector pane. Here if it is standalone, the button is defaulted to false, and the loop runs until the stop button is pressed.
If you make it a subVI, wire a true constant to the connector that is connected to that subVI button. Now it will run a single time and return back to the calling program.
If you want to make this a subVI that runs continuously, then you will need to add a mechanism where either the front panel is opened when called, or the calling program is able to send it a command to tell it when to end its loop. There are numerous threads in the forum that discuss either of these options.
It is hard to tell you exactly what you want to do because the code you provided doesn't give an indication as to what the program is really supposed to do.
02-19-2009 09:31 AM