LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Shift registers in Enqueueing loops

Solved!
Go to solution

Hi all,

Recently, I was creating some producer/consumer subVIs using queues and stumbled upon a strange phenomenon: in the loops that enqueue an element, it is required to pass a queue reference through a shift register to enqueue an element, otherwise, it won't work. But, in loops that dequeue elements, it is enough to pass a reference to a queue through a tunnel. If someone could explain the reason behind using shift registers in enqueueing loops, I would very much appreciate it.

I've attached a file I'm working on, and the thing that concerns me is the need for the shift register in the consumer loop.

0 Kudos
Message 1 of 5
(2,998 Views)

This sounds like an incorrect diagnosis.  I'm on LV 2016 and can't open your code to inspect further, but I've never seen such an odd kind of behavior.

 

The main thing I can think to look for is the possibility of overlapped tunnels or something similar.  (2 tunnels can stack and look like 1.  It'd be possible to be wiring into one tunnel and out of a different one, but it wouldn't be obvious visually.)   Maybe try deleting all wires and loop nodes connecting the queue ref from outside the loop to inside, then rewire from scratch?

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 2 of 5
(2,973 Views)

Please attach the version of the file where you do not use shift registers that causes you problems.

 

What you are claiming simply isn't true.  However, there is one possibility that could be trip you up, but I can't see how that would be happening in your code.

 

It is a good idea to use shift registers on tunnels when you have For Loops.  When you have a For Loop that its number of iterations is determined by an auto-indexing tunnel, there is a chance that the array is empty and the For Loop will run zero times.  (While loops always have to run at least one time.)  If the For Loop doesn't run, then the value on the reference wire doesn't get passed through the loop.  Thus an ordinary tunnel would just output the default datatype which would be an empty referenced.  However, a shift register links the input and output tunnels and would allow the incoming reference value to be passed through the For Loop even though it happened to run 0 times.

0 Kudos
Message 3 of 5
(2,949 Views)

Thank you for your replies. My sincere apologies, it indeed does run without a problem if I use tunnels instead of shift registers. The problem was an incorrect checksum calculation. However, it is still not clear why templates for producer/consumer use shift registers for a producer since enqueue's queue reference out returns unchanged queue reference in, and there is no need for shift register in my opinion.  

0 Kudos
Message 4 of 5
(2,942 Views)
Solution
Accepted by topic author fedorc

Why not use shift registers?

 

In general, shift registers have an advantage over tunnels.  Besides the 0-iteration For Loop, shift registers allow you to change references if you need to.  Probably not needed for queues, but with something like a VISA reference, there will be times you may need to close and reopen a VISA resource perhaps to fix an error in operation.

Message 5 of 5
(2,917 Views)