05-03-2014 04:35 PM
I am new to subpanels and am kind of overwhelmed by the various responses I've read on the forums about this issue. Some people use named references, others user events, others queues...and right now I guess I've yet to see an example that was really clear for me to understand.
In my case I have lots of different controls and indicators within my subpanel. Two main things I need to do:
1. I need to pass the VI that gets loaded into the subpanel a single string and a single numeric
2. When there is an event on the subpanel (either a value change event for any control, or a mouse up event), I need to pass out a reference to the control that caused the event. The top-level VI will then process the top level event.
So that's it....2 inputs (1 string, 1 numeric), 1 output (a ctrl ref). Both inputs will be changing regularly as data from a telnet connection is read, and the output is driven entirely by user interaction with the subpanel (i.e. it's independent of the inputs).
What's the easiest way to do this?
thanks
05-03-2014 05:02 PM
I was thinking about it some more...the ctrl reference that I said I wanted to pass out - it could just as easily be a string. The label of the control has indices as part of it's name that I use to index an array to extract a string. There's no reason I couldn't do that within the subpanel and simply pass out the string itself.
So to modify my question slightly - the VI loaded into the subpanel takes in a string and a numeric and outputs a string, and I want the top level VI to execute an event structure each time the output string changes.
thanks...
05-03-2014 05:22 PM
Post your code. Very hard to help otherwise.
05-03-2014
06:31 PM
- last edited on
04-30-2025
09:01 AM
by
Content Cleaner
I assumed my question was generic enough to not warrant posting it...all I did anyway was follow NI's example, located here:
https://www.ni.com/docs/en-US/bundle/labview/page/loading-a-front-panel-in-a-subpanel-control.html
So they are loading a VI called subpanel.vi. If there's a string and numeric control within subpanel.vi, how do you pass data to them from the parent VI?
05-05-2014 07:57 AM
In general, it is not a good idea to allow the main VI to affect items in your subpanel VI. You can pass out the value, but a reference will likely run you into trouble.
I recommend using User Events for a subpanel VI to the main VI. Depending on how your subpanel VI is set up, I would go either a queue or user events. What I typically do is create an Action Engine to hold the user event or queue. So then your just use the Action Engine to send the commands to whoever is listening for it.
05-05-2014 08:11 AM - edited 05-05-2014 08:13 AM
@bmishoe wrote:
I was thinking about it some more...the ctrl reference that I said I wanted to pass out - it could just as easily be a string. The label of the control has indices as part of it's name that I use to index an array to extract a string. There's no reason I couldn't do that within the subpanel and simply pass out the string itself.
So to modify my question slightly - the VI loaded into the subpanel takes in a string and a numeric and outputs a string, and I want the top level VI to execute an event structure each time the output string changes.
thanks...
If that's how you want to handle it, you should have 3 inputs, String, Value and User event, and inside the VI you check if the string has changed, in which case you generate an event. The Main VI will subscribe to the event and execute it.
The event has ofcourse string data so you'll send the data up to Main vi.
Easier would ofcourse to simply have the string output from the subvi and update the main vi's indicator each time. 🙂
Whether you show it in a subpanel or as a popup vi is just a visual thing, the VI should work the same.
/Y
05-05-2014 08:14 AM
2 questions:
1. did you mean to say the user event was an input, instead of saying it was an output? I understand the concept of what you're saying, but don't understand why the event would be an input instead of an output.
2. can you point me to an example of how to create a user event?
In my testing this morning, I was able to generate an event in the SubVI and stick it in a queue, then at the main VI I polled the queue and processed the event...a user event sounds like a much cleaner solution since no polling would be involved.
thanks
05-05-2014
08:16 AM
- last edited on
04-30-2025
09:02 AM
by
Content Cleaner
actually this looks like a really good example...
http://zone.ni.com/reference/en-XX/help/371361H-01/lvconcepts/user_events/
05-05-2014 09:32 AM
Yes, that example is really good, if you imaging the bottom loop as your sub-vi you'll have the user event ref as input so you can Generate event inside it. As the image shows you'll need to activate Dynamic event input on the event structure to subscribe to the user event.
If your application grows and you need lots of different events you can make a general event (same solution with queue) with a Cluster containing a type-def'd Command-enum and a variant. That way you can send a user event with any datatype (which need to be converted in the event processing)
e.g.
Update value: double
Update status: string
Samples:array of singles
Error:error cluster
/Y