11-16-2022 10:54 AM
Hello!
I'm looking for a way to programmatically trigger an event in an event structure which would normally be triggered by a custom menu selection. I want to re-use the code there. Putting the code into a sub VI would also be a solution, but kinda effortive.
Why I want to do that? As part of the start of my program it shall do a first setup, like reading an INI file. In that INI file it contains a path to a file that shall be auto-loaded, the same way as I could open another one from the menu.
Found tutorials about how to create dynamic events. But when I add a dynamic user event to the event case, the original source becomes unavailable. The option to merge several events
into one case appeared to me like a logical OR.
-->
Solved! Go to Solution.
11-16-2022 11:00 AM - edited 11-16-2022 11:01 AM
You should be able to add your user event to the list of events covered by that case. Edit the events for that case and add it in.
Edit: I see you considered the above; what was wrong with that approach?
11-16-2022 11:05 AM
Um, isn't that obvious? As I wrote, the menu item tag source vanishes when adding the other case.
11-16-2022 11:11 AM
Is this about the VIRef terminal missing?
You can solve this by handing off the handling of the event. Idiomatic LabVIEW would recommend building a second "consumer" loop to forward the "Initialize" command to. You could also have the "Menu selection" event fire off the user event and handle everything in that case.
11-16-2022 11:32 AM
You can have a case structure just after your event structure, containing common actions that can be called by multiple event cases.
11-17-2022 04:08 AM
@LLindenbauer: please compare the two images. The first one has one case, for the menu selection. The second has two cases. Adding the second made first one unusable.
@drjdpowell: the primary goal is to go into the same event from two different case triggers. By adding the second case I can surely do that, but casing the menu selection is then not available anymore from the MenuItemTag (first image) source, so I would probably have to program some menu item reading code which wouldn't be necessary. The problem is that there is no other way to get a reference from the menu item. I cannot create a user event for a menu action.
11-17-2022 04:23 AM
What is your structure ?
Are you doing the action in the event or in another loop (producer/consumer architecture for example) ?
In such an architecture you can have separated events that will load the same step to execute in the consumer queue.
11-17-2022 04:35 AM - edited 11-17-2022 04:46 AM
I wonder why no one looks at the pictures I showed above. Accessing the custom menu triggers an event, the MenuItemTag is read into a multicase (not shown in the simplified VI). OK, new image:
That works fine. Adding another case to the same event kills the tag:
<-- doesn't work anymore. OK, so what options do we have? If I change the case to:
it will give a menu ref which I can process, but trying to add the other case here does this:
which is pretty much the same as above. You cannot mix events in one case which are dependent on refs or specific sources. Seems illogical to me.
11-17-2022 04:49 AM
@MaSta wrote:
the primary goal is to go into the same event from two different case triggers.
As you already found out only data which is common to both (multiple) events will be available in a single event case. There is nothing you can do about it. How should LabVIEW fill the Item Tag value, when you generate your boolean user event?
@MaSta wrote:
I cannot create a user event for a menu action.
You can create a user event with the information from the menu you need (just Item Tag, or a cluster of Item Tag, Item Path and whatever you need) and generate this event in the menu selection case, which will forward the information to the user event case. Yes, now you have two cases, but perform the operation only in one case.
11-17-2022 04:59 AM
Your User-Event needs to have the same information as your event that is triggered in the same Event-Case.
Just add a Cluster with that Information (I missed the VIRef). Make sure you give that Information if you call that event manualy!