LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to dequeue an enqueued array

Hey guys,

 

in the attached VI I want to enqueue various events in the producer. Therefor I chose an array. In the consumer I dequeue and get the array. The Problem is, that the consumer does not execute all of the orders in the Array. I tried to index with the counter of the while Loop, that does not work properly however. What's the Problem and how can I fix it?

 

Regards

0 Kudos
Message 1 of 8
(4,187 Views)

Two solutions come to my mind:

 

1) Don't use an array as the queue element. Instead enqueue several elements in your producer loop (ie put the Enqueue inside a For-Loop)

2) Use a For-Loop with Auto-Indexing in your consumer-loop after the dequeue vi.

 

Regards, Jens

Kudos are welcome...
Message 2 of 8
(4,184 Views)

@jg69 wrote:

1) Don't use an array as the queue element. Instead enqueue several elements in your producer loop (ie put the Enqueue inside a For-Loop)

2) Use a For-Loop with Auto-Indexing in your consumer-loop after the dequeue vi.


And based on what I quickly saw in the VI, I would go with Option 1.


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 3 of 8
(4,166 Views)

Enqueueing an array should work just fine, there's something else going on. I can't check your example right now, but did a simple test and it works as it should. One possibility is to set the Queue as Variant and do a Variant to data in the consumer.

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 8
(4,163 Views)

The problem is that you enqueue the array, then dequeue the array.  You index out the first element and act on it.  You increment your shift register and the consumer loop iterates again.  But now you are waiting on another array to come through the queue.  Your original array is discarded having only worked on the 0th element.  Elements 1 and 2 were never used.

 

Now if you change the tab control again, you send another 3 element array, but index 1 will be used (since you had incremented the shift register).  Elements 0 and 2 will be discarded.

 

Run your code with highlight executing turned on to see how the dataflow is happening.

Message 5 of 8
(4,149 Views)

@Yamaeda wrote:

Enqueueing an array should work just fine, there's something else going on.

/Y


See for yourself, it's not working in his VI, as dataflow has been mistreated...grafik.png

@volfi: Debug your code with highlighting activated and try to understand what you did wrong... THINK dataflow!

EDIT: Or read RavenFan's reply

Regards, Jens

Kudos are welcome...
0 Kudos
Message 6 of 8
(4,147 Views)

As jg69 wrote, you need a for loop to execute all the commands in the array. Right now, you are only deferring panel updates and then waiting for the next message to arrive in the queue. 

 

Speaking of defer panel updates, what's the purpose of that? 

Why do you have a tab indicator on top of a tab control?  Rube Goldberg.

Why do you load two different VI's into the same sub panel at the same time?

 

I can appreciate that you are trying to learn to use a design pattern but there are a lot of mistakes in your code.  I would suggest that you look into a state machine, since you obviously want to execute different states in a predetermined order. 

 

aputman
0 Kudos
Message 7 of 8
(4,133 Views)

Ah, i couldn't open the VI, but your image shows the problem and the solution is easy enough. You send an array of clusters, but you don't act on the full array. Just place a For loop around the case and remove the index array and all full queued array should be handled.

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 8 of 8
(4,112 Views)