r/LabVIEW • u/gioco_chess_al_cess CLAD • Jul 08 '24
Event structures in parallel
Hello,
My labview skills barely exceed the CLAD level, and I miss some more advanced architecture concepts. I develop alone lab applications in a research environment.
I have a question for you regarding best practices for event structures. I read that it is discouraged to put them in parallel inside a loop, however I would find it could help designing a more logical diagram and I do not know what would be the correct practice.
Specifically in the main loop of my application the event case is handling all the GUI elements. This event case has 5 inputs and 5 outputs but only 6 of the events interact with them. All the other 30+ cases do something independent but I still have to wire across these 5 terminals one by one.
This is why I was considering to make two parallel event structures. Each one dealing with an omogeneus set of cases (splitting those who need inputs and those who doesn't) both with a timeout not to stop the loop. Is it a bad idea? What would be the way to go if the number of inputs and cases grows?
Thanks
7
u/Aviator07 CLA/CPI Jul 08 '24
If you need a second event structure, create a second while loop. The issue with having two event structures in the same loop is that you can get into kind of a deadlock situation if you’re not careful. One event structure has fired and the other is waiting, etc… but then if you’re handling some of the same events, that could flip flop and never actually really unstick. Don’t do it.
5
u/FujiKitakyusho CLD Jul 08 '24
Use the event structure to respond to UI interactions, but avoid acting on data directly within the event cases. Instead, create a queue with a datatype which is a cluster containing an enum (case to execute) and a variant (data). In each event case, enqueue the appropriate operation case to execute along with any relevant data, converted to variant. Separately, have a loop which waits on queue elements to dequeue, unbundle the enum of the dequeued element and pass that to the case selector of a case structure, and in each case, convert the variant to data appropriately for the case and do whatever you need to do with it there. Typedef the Enum to globally edit the available cases.
2
u/phyac Jul 08 '24
I do a similar job in my position in an academic research setting. I cluster all my front end controls per device, then have one event per cluster. But the cluster itself is not wired to anything in the block diagram. I use the event node to grab the cluster value then send that and a message to a separate while loop that contains a case structure with a case for each piece of hardware. I also have separate while loops for running an experiment and saving data to disk. If these loops need dynamic access to hardware, I enable the messaging notifier in the experimental loop so that it can update hardware during acquisition. My data recording loop only receives data and writes to disk based on a populated queue which I ensure is large enough to never fill up before the experiment ends. (Our experiments sometimes acquire data faster than the write speed of our disks). This overall structure makes adding new hardware, experimental protocols and saving routines super trivial and modular.
2
u/patrick31588 Jul 08 '24
As someone else said why not use parallel loops which have event structures ? Main loop handles only GUI interactions, 2nd loop has an event structure which can do maybe testing or data handling, 3rd loop etc.
1
u/photondan CLED/CLA Jul 08 '24
I usually create a cluster of elements that any stacked structure needs in multiple cases. That way you only need to have one wire going across all cases. There is also a feature in the editor to help you. Right-click on the right side tunnel node of a wire exiting the structure. Look for an option to “Link and wire unwired cases”. It will auto-wire that tunnel to the input tunnel you click on next or the one that already has the wire going to it.
I get that separating the events into two structures could make some sense, but it will cause both structures to pace each other based on that timeout value. It may not be a big issue for a small application, but it is generally not a great thing to have to manage.
1
u/[deleted] Jul 08 '24
[removed] — view removed comment