07-21-2010 02:03 PM
Trying to trigger events from a main vi.
I have created a sample vi as a basic unit from a much larger program.
The top level vi calls a subvi that contains an event structure. The subvi runs continously and will exit when the program is stopped by the user.
The top level has controls which are passed to a global, and the global is read in the subvi, which should trigger an event. (it doesn't)
The subvi has to be able to run as either a subvi or a top level.
For context:
The project this comes from is a test system. The subvi prepresents the main control panel for the test system. We wish to automate the test system and so are using the main control panel as a subvi so we can automate a number of individual test. (Frequency response, gain linearity, etc.)
See below for an additional attachment that contains the global variable and project file (can only attach 3 files at a time)
The global is just a stop button and a cluster that contains 3 boolean values.
It doesn't work, I was hoping somebody could explain how to do this without making many changes to the existing subvi. If necessary a case statement could be added that is only active when the program is functioning as a subvi, which would contain the code to trigger the events so the event case can handle it.
Solved! Go to Solution.
07-21-2010 02:04 PM - edited 07-21-2010 02:06 PM
attachment with the global variable and project file
Download all files then open the project
07-21-2010 02:13 PM - edited 07-21-2010 02:16 PM
First things first.
Using 'Global' to communicate between VIs is not the best option.
However you can get you system to work by adapting your sub-vi according to this:
In your MainVI you should just place the Sub-vi. Don't us FP.Open, since that won't start the subVI.
Ton
07-21-2010 03:01 PM
I have modified your main and subvi to give you better architecture. Instead of using globals, it is better to pass references to the subvi so that they can share the data space with the main vi. Clicking on any referenced control on the main can cause an action in the subvi. Also, instead of writing the value to a local or global in the subvi, you must write to the Value(signaling) property node in order to trigger an event. In your main, you called the subvi dynamically, and then you called it implicitly. Not desirable. I changed your code to call it one, implicitly. Study the modified vi's against your original ones. You will see how references and Value(signaling) work. Also, timing is important in that the timeout case in the event structure must be less than or equal to the Wait(ms) time in the lower loop. If not, the lower loop will queue up events faster than the event structure can handle them and you will have problems.
You can delete your globals vi. It isn't needed anymore.
07-21-2010 03:02 PM - edited 07-21-2010 03:07 PM
I'm looking over the code now, I'll update the kudos if this works
07-21-2010 03:17 PM
This works perfectly, give this man some kudos.
I just hope I can integrate this into my main.
Works as standalone, works as a subvi. PERFECT!
11-13-2017 10:00 AM
Hi everybody,
i´ve a similar Problem. I want to do it the other way round. I want to Trigger an Event in my main.vi from a boolean action in my subvi.
The Subvi is called dynamically with the Call by Reference Node. When i press a Latch in my subvi i want to Trigger an Event in my main vi. Can i use this as an Example and just " turn it around" ?!
is it a Problem when my Subvi gets called dynamically in an Event in the Mainvi?
11-14-2017 08:58 AM
Hey Kai,
This post is from 7 years ago so I would recommend creating a new thread with your question to get more visibility! This should help your question get answered faster.