LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to get the element data type of a Queue from itself?

Solved!
Go to solution

One should be able to use a case structure around a dequeue, with a constant case selector set to the empty case, and the tunnel out of the queue element set to "use default if unwired".  I would expect the compiler to constant-fold that into just the element default type, and so this method should have no overhead.

0 Kudos
Message 11 of 30
(1,493 Views)

@drjdpowell wrote:

One should be able to use a case structure around a dequeue, with a constant case selector set to the empty case, and the tunnel out of the queue element set to "use default if unwired".  I would expect the compiler to constant-fold that into just the element default type, and so this method should have no overhead.


... and, as the Snippet shows, this does, indeed, work!   Even simpler ...  Note that the Queue is actually empty!

 

BS

 

Get Queue Element Type.png

0 Kudos
Message 12 of 30
(1,460 Views)

Yes, all of these work.  But they are way more complicated than just using a simple Type Def constant.  You have to know your data type anyways.  So you might as well just bind it to a type def.


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
Message 13 of 30
(1,421 Views)

A very good point.  Even in my snippets illustrating some of the "other" ways, there's the TypeDef prominently displayed in creating the Queue ...

 

BS

0 Kudos
Message 14 of 30
(1,410 Views)

Yes, a type def....but because it wasn't mentioned and because they're so...much...fun... don't forget the variant functions, specifically vi.lib\Utility\VariantDataType\GetRefnumInfo.vi.

From that you can get the type of your data and manually reconstruct it.

 

Or...use a type def 😞

0 Kudos
Message 15 of 30
(1,388 Views)

omg so many answers .. i had a long weekend so i didnt see all the replies yet.

 

thank you all for posting .. ill have a look at all the suggestions now.

 

regards j


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 16 of 30
(1,362 Views)

@tst & @Bob_Shor thx for the tip .. i thought this was only possible if elemnts were in the Q, ill try it.

@everyoneelse thx for the tips and discussion.

 

i understand that best practice would be the type def,

but i have some code with too many cables and was trying for a way with less long cables.

will decide how to go about this in production code,

but now at least i have more options 😉

 

cheers to you all

 


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 17 of 30
(1,354 Views)

If that's the case then I would definitely suggest typedefs. All the things we were talking about here were ways to achieve what you were asking for, but there are only a few cases where something like this might be useful and I don't think that yours is one of those. Here's how a typedef could remove the wires:

 

TypedefQ.png

 

Once you have a typedef you can also pass the queue reference into subVIs and do some of the work in there, so that each piece of code becomes simpler.

 

There are many other options for improving code, but this thread isn't the place for discussing them. You might want to try reading up on software engineering.

 

 


___________________
Try to take over the world!
0 Kudos
Message 18 of 30
(1,345 Views)

this question just came up in my mind.

i do know a little about software engineering (am cs)

but applying all my code-based principles with the labview tools is quite troublesome.

for example i have not yet mastered (really tried) the object-oriented approach.

 

using type defs as best practice is what i took away,

but i was happy to find that my intuition of getting the element data type somehow from the queue itself was not false 😉

 

j

 

edit: formatting


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 19 of 30
(1,334 Views)

For me, a (minor) downside of using Queues is all those wires everywhere!  So I tend to use what I call Wireless Queues, which have been discussed fairly recently in the Forum (talking about speed/efficiency).  Basically, you build an Action Engine for a Queue with all of the Queue functions (Obtain, Enqueue, Enqueue Lossy, ... Release) except Dequeue as the "Action" (I use an Enum that I call Queue Action to hold these choices).  Since in most cases none of the Queue actions (except Dequeue) will take appreciable time and prevent other Actions from being called. there should be no problem having them in the same VI and being called from multiple places in your code.

 

Dequeue, however, typically "waits forever" for something to appear in the Queue.  If Dequeue was present in this Action Engine, and you called for a Dequeue Action before you put something on the Queue, you'd be stuck -- the first call to this VI, Dequeue, would "wait forever" for something to appear, blocking the second call that was trying to fill the Queue!  [True story -- I made this stupid mistake at least twice before I "learned my lesson" ...].

 

I've attached a Snippet of one such Queue, whose input is a Cluster.  I'm illustrating the Status Action, which I use for three things -- in this particular example, I'm using it to give me a copy of the entire Queue by setting "Return Elements?" to True (normally I don't use this), am returning the number of elements on the Queue (useful to tell when the Queue is empty or getting full), and also to return the Queue, itself.  I use this as a "trick" when I want to Dequeue something (typically inside a While Loop) -- I put Status outside the loop, bring the Queue into the loop, and connect it to the Dequeue.  Very quick (and you only need to do it once) and otherwise doesn't affect the Queue.

 

Queue Example.png

 

Bob Schor

Message 20 of 30
(1,297 Views)