LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Two way communication with parallel loops

Solved!
Go to solution

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.

0 Kudos
Message 1 of 9
(4,537 Views)
Solution
Accepted by topic author jmog

Look into User Events.  They are a way to send messages to a loop with an Event Structure and very useful.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 9
(4,519 Views)

The other way ist to implement a second message queue with the lower loop as sender and the upper loop as receiver.

Greets, Dave
Message 3 of 9
(4,508 Views)

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.

0 Kudos
Message 4 of 9
(4,480 Views)

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

0 Kudos
Message 5 of 9
(4,389 Views)

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 9
(4,374 Views)

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

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 7 of 9
(4,346 Views)

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.

Message 8 of 9
(4,343 Views)

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

0 Kudos
Message 9 of 9
(4,322 Views)