LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple Queues

Solved!
Go to solution

I am new to labview and a problem running two queues as producers/consumers, see sample VI. I am inserting data first into the first queue, later into the second queue and want to process the data later in the consumer loop (comparing data 1 with data 2). What am I missing??

Thanks

Thomas

0 Kudos
Message 1 of 12
(9,438 Views)

Thomas,

 

if producer and consumer are the same loop each (like in your screenshot), there is absolutely no sense to create two queues. Just use a single one.

The problem is that you have to feed both queues and dequeue both queues in order to keep both loops running.

 

hope this helps,

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 2 of 12
(9,422 Views)

Sorry, I forgot to mention, that the data sets for the two queues are not the same. The data for queue 1 is from one source and the data for queue 2 is from another source. Once I have both sets of data, i want to compare the data in the consumer loop.

 

Thomas

0 Kudos
Message 3 of 12
(9,417 Views)

Ok, but still, if you have two queues in a single loop without timeouts, you have to have the same amount of elements in both queues, otherwise the "bigger" one will run full (leading to out of memory errors).

So if the consumer reads from two different queues, use a timeout for each read. Make sure that you do not compare if one of the reader ran into timeout.

 

All in all, i am not sure if you are trying the best setup here. As stated above, queues are not the best thing to use multiple times in a single loop.....

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 4 of 12
(9,413 Views)

The consumer loop will not iterate until both queues receive data. Each consumer needs it's own loop. To compare data in the two consumers you have to send the results of both back to some other process (a fourth queue or even back in your producer)

 

[Edit: Saw Norbert's reply only after I hit post]

 

 

=====================
LabVIEW 2012


0 Kudos
Message 5 of 12
(9,405 Views)
Solution
Accepted by topic author Thomasocholt

Another idea would be something like this. Please note that you should insert some timing, otherwise you will produce 100% CPU load for a core.

 

consumer.PNG

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 6 of 12
(9,386 Views)

You should also set the queue sizes to 1. Otherwise you have to take into account what would happen if one queue has three elements and the other has two. You might end up out of sync and compare the wrong elements.

=====================
LabVIEW 2012


0 Kudos
Message 7 of 12
(9,377 Views)

Good idea, Steve. This will simplify the consumer since you can leave both queues to a simple dequeue. You can stop execution of the consumer by simply close the queues which will create an error in the appropriate dequeue function (so error handling to stop the consumer is important!).

 

Nevertheless, it arises a new question: What are you going to do if you try to enqueue something into a full queue?

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 8 of 12
(9,372 Views)

If your are simply doing basic messaging with two different types of data you can define your queue element to be a cluster which includes a message type/ID and a variant. That will allow you to use a single queue for the consumer but handle differetn types of data. This assumes teh messages are independent. If your system requires both messages/data sets to arrive before you can process anything then some of the earlier suggestions will work.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 9 of 12
(9,365 Views)

Here is a way to dequeue from two loops.  The timeouts are set on each Dequeue function and are monitored by the case structures connected to the "timed out?" booleans. Use of Bulid Array in a loop is not the best practice because of memory allocation issues, but it is the easiest way to show the concept of handling two queues.  The timeouts do not need to be the same, but each dequeue will only operate once per iteration of the while loop, so different timeouts may not be very meaningful.  Both case structures are identical.

 

Lynn

 

Multiple dequeue.png

Message 10 of 12
(9,360 Views)