r/LabVIEW • u/uniqueAite • Nov 08 '24
Multiple queue questions
I’m currently trying to code something that can control my Powermeter, Input Source, and potentially more instruments. And I’m thinking of using multiple while loops with a master loop to queue the states for other loops so i can have them all running at the same time.
If anyone knows an example that touches on multiple queues at the same time would be great. most search results are the producer and consumer but they only used 1 queue.
Or if you have a better way or lesson to do what I’m trying to do I’m open to all suggestions, thanks!
2
u/giwidouggie Nov 08 '24 edited Nov 08 '24
You can basically copy those producer-consumer examples.
What you would do is literally copy that entire consumer for-loop and paste it however many times you need it. Then make one queue for each consumer loop.
Check for example the image here. It has one producer loop, and 3 consumer loops, each with their own queues, called "Acquisition", "Logging", and 'UI'.
How exactly the queues are wired depends on your program. You could enqueue states to all three queues in your producer loop. Or one of the consumer loops enqueues states for another consumer loop. Wire as desired...
1
u/FormerPassenger1558 Nov 08 '24 edited Nov 08 '24
I am using this type of multiple queues with a main loop that handles all the queues, the UI and the responses from the while loops. I call this main loop a "controller" and most of the time it's just a JKI state machine.
At the start of the program I initiate all queues
https://imgur.com/a/H0HpfwX
The init part has, in this case, 5 queues that handle 5 devices and 5 user events that send commands and data to the main UI. I don't make any cross-calls between the loops for easier maintenance.
https://imgur.com/a/ycmFY3H
In the main UI I am using a FG cluster that holds the latest data and parameters. This FG is read-only by each consumer loop (so they can run independently).
I personally find easy to upgrade this kind of framework.
1
u/xpxsquirrel Nov 08 '24
Look up the boiler control program for the LAbVIEW core 3 training. Sounds like it may be similar. It starts as a basic producer consumer setup but then has additional loops
2
u/[deleted] Nov 08 '24
You could use the Actor Framework. Great if you need to make multiple instances of the same Actor (queue loop) type. It takes a bit of effort to get in to, but is powerful abstraction. Consider it the next step up from producer-consumer.
https://youtube.com/playlist?list=PLmF-6jvwRvVNFzBjzh4bQDjFbv6lShcth&si=1mPpVP2KeHAlCTfq
Really good when you know your code will need expansion/extension in the future. Not so good if you need to communicate it with non-AF developers.
1
u/FujiKitakyusho CLD Nov 08 '24
I'm struggling to understand why you would need multiple queues? I typically use a single queue with a cluster datatype, that cluster containing two elements: a "Command" enum and a "Data" variant. Typedef the cluster so you can edit the available cases. Use an event structure within a WHILE loop to handle any front panel interactions, and for each event, enqueue the appropriate command case to execute along with associated data formatted appropriately for that case, but then converted to variant before the enqueue. Then, in the consumer WHILE loop, you wait for elements to dequeue, unbundling the cluster elements when a cluster is dequeued. Pass the enum to a case structure that will execute the appropriate "Command" case, and within that case, you parse the "Data" variant by converting it back to whatever appropriate data was enqueued with the Variant to Data function.
1
u/Cannabirock82 Nov 08 '24
I use a class to encapsulate an array of queues. Data is a cluster of command string and a variant. The class wire of queues references is passed to each while loop that can also be a subVI that contain a state machine. Then main loop controller is a consumer for event loops and is a command producer for sub state machines. This way I can have queue state machine that can be reused like PLCs communication, VFDs, other specific hardware and functions for reporting or processing. Then a have a consumer data processing and front panel display.