01-25-2017 05:45 AM
Hi guys.
I'm working on a quite simple application. It's basically a test sequencer based on queued messages and I would like the UI to update after each test. I am trying to use two parallel loops, the first one handling all the UI events and queueing test cases and the second loop just dequeueing elements and running corresponding tests. What I cannot seem to accomplish is communicating back to the UI from the loop running tests. If I could trigger an event when an element is dequeued I could update the UI based on that, but I don't see a way this could be done. Initially the tests that are to be run are read from a table.
I could do a dirty solution with timeout event and comparing queue size to the initial test cases array size, but I feel like there should be a better way. Any help would be appreciated!
I am attaching a picture of my code to give you a better understanding.
Solved! Go to Solution.
01-25-2017 06:02 AM
Look into User Events. They are a way to send messages to a loop with an Event Structure and very useful.
01-25-2017 06:23 AM
The other way ist to implement a second message queue with the lower loop as sender and the upper loop as receiver.
01-25-2017 07:44 AM
Thanks for the quick replies! User events seems to be the best way for me, since I already have an event structure in the main loop that I can use.
01-27-2017 06:11 AM
I'll use this same thread to extend my question a little instead of creating a new topic. I have implemented a user event that fires after each test so that I can update my UI. Is there a way to have more than one user event with the same reference? Currently I am able to fire one event, but let's say I would like to fire a different kind of event after each test. Would I need a new reference (from the Create user event block) for each different event or is there a way to pass information about the event type in one reference? When I try to add events to my event structure, there is only one event that I can currently add: <My event>: User Event. There is probably a simple solution to this I just can't come up with.
Again I have a "dirty" solution in mind, passing an enum in the event data and executing different code in a case structure inside my event structure, but I feel that is not the optimal way. I have not been able to find a clear answer to this after several hours of googling (might be I can't come up with the correct words...).
01-27-2017 05:48 PM
jmog wrote:
Again I have a "dirty" solution in mind, passing an enum in the event data and executing different code in a case structure inside my event structure, but I feel that is not the optimal way.
I typically do not use that trick for User Events. I use it all the time for queues though.
The "clean" way would be to have multiple events. You just have to make sure you register for all of them. Hint: the Register For Events is expandable, so you can register for many events at once. Or you can bundle your events into a cluster and register the cluster. Or you can do what I like to do: bundle the registrations into a cluster and wire that into the dynamic event terminal.
01-30-2017 02:59 AM
That's not a dirty solution, unless most of us are dirty. 😄
You can very well use the "general queue standard" of a cluster of string/enum + variant. I would agree it's slightly better to use the ability to register several events, but not a must.
/Y
01-30-2017 03:20 AM
Thanks for the tips guys. I suppose using an enum in the event data just felt like a loophole, so I figured there should be another way 😉 I created a couple of different user events now and bundled the references up to make the block diagram neat. I decided to make a subvi for opening the references, since it took a lot of space. Even more so if I had more user events with the current style.
01-30-2017 02:26 PM
Nesting data into the user event data (like an enum) is pretty common, but is up to the developer on how they want to implement it.
Another method worth mentioning is the Channel Wires officially in 2016 which can be used to send data between loops. Theres tons of installed examples, and one of the newer ones posted publicly supports event registration.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord