LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Very simple questions about Queue and De-queue. Vi attached.

Solved!
Go to solution

Dear friend, 

 

Please check the attached vi. The function is very simple, just queue the array from lower while loop to upper while loop.  That's it!

The style A is working, but B is NOT working.  

My questions:

1. why B is not working ? I didn't get any error.  

2. If I want to queue an array from one while loop to another while loop (outside and parallel ), the way I do is correct or not?  I am new with queue, please advise me.  Thank you

A.pngB.png

0 Kudos
Message 1 of 18
(4,149 Views)
Solution
Accepted by sunson29

@sunson29 wrote:

Dear friend, 

 

Please check the attached vi. The function is very simple, just queue the array from lower while loop to upper while loop.  That's it!

The style A is working, but B is NOT working.  

My questions:

1. why B is not working ? I didn't get any error.  

2. If I want to queue an array from one while loop to another while loop (outside and parallel ), the way I do is correct or not?  I am new with queue, please advise me.  Thank you

 


1.   Dataflow.  In A the loops run in parallel.  In B, the top loop can't begin until the bottom loop ends because of the wire that LEAVES the bottom loop and ENTERS the top loop.  Execute both pieces of code with Highlight Execution (the light bulb) turned on and watch how data flows.

2.  It's correct as long as you do it like in A.   But you proved that yourself when you said A is working for you.

0 Kudos
Message 2 of 18
(4,120 Views)
Solution
Accepted by sunson29

1. why B is not working ? I didn't get any error.  

Because the upper loop cannot execute until the queue wire has data. The wire is coming from the OUTPUT tunnel in the lower loop meaning it doesn't have data until that loop stops. What error would you expect? It's perfectly valid to code that, you just need to know how data flow works. Once the lower loop stops, the wire connected to the output tunnel has data and can continue. Spoiler, the release queue and dequeue element will have a race condition.

 

2. If I want to queue an array from one while loop to another while loop (outside and parallel ), the way I do is correct or not?  I am new with queue, please advise me.

 

The basic design will work, but there is a timing issue. You are enqueing elements every 100 ms and dequeueing every 200 ms so your queue will constantly be growing the number of elements to dequeue and be out of sync. I would remove the wait function in the upper loop and let the dequeue element function determine the timing, and wire the error output to the stop terminal.

 

 

0 Kudos
Message 3 of 18
(4,119 Views)

StevenD wrote:

2. If I want to queue an array from one while loop to another while loop (outside and parallel ), the way I do is correct or not?  I am new with queue, please advise me.

 

The basic design will work, but there is a timing issue. You are enqueing elements every 100 ms and dequeueing every 200 ms so your queue will constantly be growing the number of elements to dequeue and be out of sync. I would remove the wait function in the upper loop and let the dequeue element function determine the timing, and wire the error output to the stop terminal.


Just to add to this.  The general idea behind a queue is to offload some processing to another loop.  That loop should be able to run as fast as possible in order to keep up with the producer.  If the producer is slow, the consumer will sit there idle until more data enters the queue (waits at the Dequeue Element).  So let the rate of data determine your consumer's loop rate and don't try to slow it down.


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 4 of 18
(4,091 Views)

Thank you!!!   

0 Kudos
Message 5 of 18
(4,062 Views)

Thank you!. 

0 Kudos
Message 6 of 18
(4,059 Views)

Allow me to have a quick follow up question.  Thank you:)

I did the highlight execution, and I do see what you said!  If in B, there will be no data unless bottom loop stopped. 

 BBBBUUUUTTT,  why the A will work?  I mean, the wire of A is still outside of bottom loop, right? Why if i make the wire on the left (outside of bottom loop) will work, and the data will transfer to upper loop?  My thought is : any data from bottom (to outside) will be available only  bottom loop stopped.   Please current my understanding.  Thank you again.  

 

oh, btw, the first time I do the queue, I use C style, because I thought dequeue should be after queue, so, the wire should be out after queue.  but, this is wrong. I think the answer will be the same as the question above. Thank you.

C.png

0 Kudos
Message 7 of 18
(4,031 Views)

Yes, it does not matter whether your wire is exiting to the left or to the right, it is still seen as an output of the loop either way.

 

For the future, you may also want to think about using the queue to stop the loop as well, this way you only have to push one stop button instead of 2 🙂

0 Kudos
Message 8 of 18
(4,025 Views)

Another way to think about the Queue "wire" is that it is a "pointer to a storage area".  Once you tell the Enquer where to put the data, the function "knows" (or remembers) and doesn't need "new" information, hence can "use the old data" on subsequent loops.  The Dequeuer also needs to know where the data are stored -- if you don't tell it, it can't get it.

 

Bob Schor

0 Kudos
Message 9 of 18
(4,020 Views)
0 Kudos
Message 10 of 18
(3,992 Views)