LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
mflegel

Name User Events at Runtime

Status: New

I have a base typedef (e.g., a lvclass) that is used to create many different user events (see Create User Event). If many registrations (see Register for Events) are done where the base typedef is the same, the only way to tell which event is which in an Event Structure is by the order of the inputs to Register for Events and/or the anonymous bundling of multiple Register for Events.

 

I would like to dymically 'name' events when they are created with Create User Event and then to call them out specifically in the Event Structure.

 

Dynamically Named User Event.png

7 Comments
drjdpowell
Trusted Enthusiast

The Event Structure is defined statically at edit time, so I'm unclear as to the meaning of defining a User Event name dynamically at run time.  One can already define the User Event name at edit time through naming the data constant:User Event Names.png

SteenSchmidt
Trusted Enthusiast

@mflegel: First off you should never fork the event registration refnum! With that out of the way you can already rename event refnums like this:

 

Renaming events.png

 

The renaming is static at edit-time, but that's the only time you need it anyway, as you only use the name for the selector in the Event Structure.

 

Cheers,

Steen

CLA, CTA, CLED & LabVIEW Champion
SteenSchmidt
Trusted Enthusiast

@James: There are a couple of scenarios where event refnum renaming makes sense. Here's one of them:

 

Reason for renaming events.png

 

Take care,

Steen

CLA, CTA, CLED & LabVIEW Champion
mflegel
Member

For clarification:

- I understand the pitfalls of having multiple event structures for the same registration - the three event structures are for illustration, consider them 'stacked' in the same structure.

- I desire to name the events dynamically at runtine (like queues), not statically at compile time.

 

Note that the renaming examples require a label that is set at compile time.

 

The reason for my desire is that my systems have a lot of re-use that heavily depends on the publisher/subscriber pattern using events as the publishing mechanism. Consider a scenario with multiple publishers are implemented with exactly the same set of re-entrant/cloned VIs (e.g., a class called 'BinaryOutput' that publishes a new boolean value when it detects a change in the hardwre it is responsible for). A system can dynamically create as many instances of BinaryOutput publishers it needs when it starts up, the GUI subscriber dynamically registers for each of them, and the GUI needs to discern which event comes from whom so it can react appropriately. I currently have the publisher name as part of the EventData, but the GUI's event structure is difficult to maintain, and brittle, because it is order dependent.

SteenSchmidt
Trusted Enthusiast

You can't currently fetch the event name at runtime, so there's no need for being able to set this at runtime either. The only place the event name is used (beyond documentation) is in the selection list of the event structure that handles the event, and that is set static at edit time.

 

Unless you also suggest a new prim that can return you the event name from an event refnum? This just seems like an odd way of transporting one of the event data fields.

 

For your described use case I'd make an array of the dynamic number of events and register that in the UI. Then act on each event received in that single event case based on event data (which could include an event identifier).

 

/Steen

CLA, CTA, CLED & LabVIEW Champion
garrettmarsh
Member

Out of curiosity, what is this primitive called, and where can I find it?

event naming.png

tst
Knight of NI Knight of NI
Knight of NI

The primitive is called "coerce to type" and you can find a discussion about it, as well as a snippet with it, in this idea - http://forums.ni.com/t5/LabVIEW-Idea-Exchange/Officially-Support-quot-Coerce-to-Type-quot/idi-p/1213...


___________________
Try to take over the world!