I’m dreading trying to describe this well. I’m unable to share any code.
I have a hardware device that I interface with via a vendor supplied DLL. It is not unheard of to need to control and coordinate multiples of these instruments. It’s a pain to communicate with directly so I’m writing a driver to make it easier for other LV devs to use, they won’t need to interface directly with the DLL. It has an inconvenient method for receiving asynchronous messages from the instrument that I have abstracted to a few LV user events (the different events are like different topics, one for device errors, one for device events, one for device asynchronous responses, etc).
I made it a “session” based API (very similar to the ESF framework floating around here), every VI is set to be reentrant. There’s an “Obtain.vi” that returns a DVR that is passed around to all the API method VIs and of course a “Release.vi” to close/cleanup the session/DVR. As mentioned earlier, the instrument reports various things in an asynchronous manner (eg. not always instantaneously in response to a command) and I’ve got a reentrant “Observer.vi” that is launched for to monitor these and fires off the appropriate LV user event which the other developers will register for (there’s an API method vi to get these user event refs) in order to do whatever they might want with this asynchronous data.
So far so good, right? Well, call it poor planning or oversight, but as I began to make a sort of test panel or API example I hit a wall when recalling there can be more than one instrument to control and that the developers using this API may not know how many there will be at edit time.
The whole thing is fine except for these events. I don’t see a way to subscribe to these events for an undetermined number of devices. There are 4 different events that contain data of different types. The DVR ref itself is part of the payload (I store the event ref including the DVR in its class data using variants as it seems LV does not like self references in class private data) so that it’s easy to identify the session that was the source of the event. That’s not the problem. The problem is that each session has its own event refs and I don’t see how to make them all execute the same frame of an event structure (which is what the end developers will want to do when using my driver) no matter if there’s 1,3, 7, etc number of sessions at runtime! I don’t see an easy way to somehow have event refs arrayed, or if it’s realistic/possible to do.
I began thinking back to how DQMH clone modules work, all clones share the same exact event refs and it’s up to the end user of those modules to use a case structure or similar to sort out which module fired the event if that is important for their purposes. Is that the right way to do things, do I need to fundamentally change the paradigm where instead of having completely separate sessions I need to have them tied/coordinated together in some way (under the hood, so to speak) such that the first session opened creates all the events and later sessions check for Not A Ref (is that a good method?) to determine whether to use the already created event refs themselves? I just can’t come up with a way for each session to have unique event refs and for that to work for a developer needing listen for an unknown number of sessions’ events.
Alternatively, I looked into clustering the current event refs that are unique/created for each session (currently I just output 4 unique event refs on 4 terminals from the “Get Events.vi” method), and then putting them into an array to register but that doesn’t seem to work and would also require the using dev to keep an array of these clusters on a shift register to in order to add/remove them from their event registration as needed. But like I said, it doesn’t seem to work (broken wire to event reg node) when I try to put a cluster of these four events into an array to register.
Any help, comments, thoughts, prior experiences would be greatly appreciated. Hoping I don’t have too much rework ahead of me.
Solved! Go to Solution.
I may be misunderstanding you, but it sounds like you are trying to register an array of a cluster of user events? That does not work, but you can rearrange your data structure and make it work. See if this gives you an idea:
Your device is then identified by the index in the user event array. You can also do the registration dynamically in the event structure, adding some meta information and allowing the user to change the device at run time.
Of course you can also send a source identifier with each user event.
Do arrays of User Events not work? Not arrays of clusters; I wouldn't expect that to work.