LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to trigger a user event from two different sources?

Solved!
Go to solution

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. 

 

MaSta_0-1668617348258.png  -->   

MaSta_1-1668617452073.png

 

 

0 Kudos
Message 1 of 20
(2,583 Views)

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?

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 20
(2,578 Views)

Um, isn't that obvious? As I wrote, the menu item tag source vanishes when adding the other case.

0 Kudos
Message 3 of 20
(2,572 Views)

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.

0 Kudos
Message 4 of 20
(2,568 Views)

You can have a case structure just after your event structure, containing common actions that can be called by multiple event cases.

0 Kudos
Message 5 of 20
(2,558 Views)

@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.  

0 Kudos
Message 6 of 20
(2,482 Views)

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.

0 Kudos
Message 7 of 20
(2,478 Views)

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:

MaSta_0-1668681432253.png

That works fine. Adding another case to the same event kills the tag:

MaSta_1-1668681510344.png <-- doesn't work anymore. OK, so what options do we have? If I change the case to:

MaSta_0-1668681703925.png it will give a menu ref which I can process, but trying to add the other case here does this:

MaSta_2-1668681858893.png 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. 

 

 

0 Kudos
Message 8 of 20
(2,475 Views)

@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.

 

ForwardMenuInfo.PNG

0 Kudos
Message 9 of 20
(2,462 Views)

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!

User Reg.png

Message 10 of 20
(2,430 Views)