06-17-2014 02:13 PM
Hello Labview guys,
I am a very new using event structures, I have developed a very small VI that should open a sub VI. The problem is that when you click on the main program the button run it does nothing and then you are not able to stop it clicking the stop button. The weird thing is that if have open the subVI and click run on the main VI it starts running. Believe me I don't know what to do. Does anybody here can help me out on this issue?
I will really appreciate your support
SergeArmz
PD
I'm attaching both codes for reference
06-17-2014 02:26 PM
I would consider using a case statement instead of an event structure, almost making a state machine and using the button is change states. also having 2 boolean inputs to the outside while stop button (even with 1 of then negated) can conflict really easily, maybe consider adding an OR Gate on the outside of the event structure. Adding a Value to the timeout input of the event structure would be a good idea. i would also use an out terminal instead of a waveform indicator on the output of your subVI.
Best of luck
06-17-2014 02:45 PM
When you click the button it does start the subVI. However, the subVI front panel remains closed, so you cannot stop it. Since the event structure by default locks the front panel (of Main.vi) until the code inside the event case completes, the program locks up.
There are several things you should do to fix this:
1. Never put any code inside an event case which takes more than a few milliseconds to execute. When the event needs to start a lengthy process, the lengthy process must be in a separate loop parallel to the loop containing the event structure. Look at the Producer/Consumer (Events) Design Pattern or template to see a recommended way of handling this situation.
2. The subVI needs to be set up to display its front panel. Go to VI properties >> Window Appearance >>Customize and check "Show front panel when called" and "Close afterwards if originally closed"
3. Remove the Timeout Event case. It will never execute, so why have it?
4. Remove the Not and the wiring from the Play button to the stop terminal. It will always be false, so just let the default tunnel value do its job.
Lynn
06-17-2014 03:06 PM
Thanks johnsold,
As I told you guys I'm a newbie on the event structures stuff, I did the steps you mentioned and it works well, it showed up the sub VI, the only thing I have not fixed is the matter to stop the sub VI clicking the stop botton on the main VI, what am I missing there?
thanks again
SergeArmz
06-25-2014 11:42 AM
Hello SergeArmz,
I would like to share with you the following link where you can find a very simple way (VI Server) to stop a SubVI's execution from the Main VI. The VI Server is a collection of functions that allows programmatic access to LabVIEW objects and functionalities.
http://digital.ni.com/public.nsf/allkb/E38991F4A3892B6F86256E44004C5963?OpenDocument
This example doesn´t use the event structure, but serves as a basis for understanding how the VI Server works in order to call and stop a subVI.
For example in your application
In the other hand, when you click the stop botton in the Main VI you can stop-close the subVI and the Main VI.
Best Regards.
06-25-2014 12:30 PM
If the subVI is to pop up when it runs, generally you would not be trying to stop it from the front panel of the main VI. That seems like a good way to confuse the user. What does this button stop? What does that button stop? Why does this one stop both VIs and that one only stops one VI? As Antonio S. showed, you can do it, but you may want to think about how to give your users a consistent experience.
Lynn
06-25-2014 01:18 PM
@johnsold wrote:
If the subVI is to pop up when it runs, generally you would not be trying to stop it from the front panel of the main VI. That seems like a good way to confuse the user. What does this button stop? What does that button stop? Why does this one stop both VIs and that one only stops one VI? As Antonio S. showed, you can do it, but you may want to think about how to give your users a consistent experience.
Lynn
Not to mention he showed a deprecated method. Besides, killing VI executions should just be avoided in general. You should let the VI stop itself so that it has a chance to perform some clean up. Maybe use a User Event or a Queue to send a stop command would be much preferable than just killing it.