LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

replacing global variable with queues or producer-consumer

I am trying to replace global variables with Queues and I am not sure of what is the most efficient way to do this.

 

Below is how I process some CAN messages and store into global variables (ProCanMsg - Global.vi):

 

ProCanMsg - Global.jpg

This is ok...but now i want to replace with queues or maybe producer/consumer?

Here is my attempt to do it using queues (ProcCanMsg - Queue.vi):

ProCanMsg - Queue.jpg

Is this the right way to do it? Should I be doing something differently? I have also tried the following but i am not sure which one is better...Something tells me that I am not utilising queues in the most efficient way...can you please help?

 

ProCanMsg - Queue2.jpgProCanMsg - Queue3.jpg

 

The idea is then to pass the variables in another vi and display them as shown below (VieGenCEU - Queue.vi):

 

ViewGenCEU - Queue.jpg

 

I have also attached all the code in a zip file....Any help would be much appreciated

 

Thanks

 

 

 

0 Kudos
Message 1 of 7
(2,789 Views)

Hi

You are almost there. The Initialise of the queue should go outside of the loop and then only the write whould go indie the loop. This way you are not try to get a ahandle to the queue every time. This will improve your time taken too.

The Can Data to Boolean and Can Data to Number should also be reentrant(under execution properties of the VI) so that they can run truly in parallel.

 

Mike

0 Kudos
Message 2 of 7
(2,785 Views)

Hi Mike...thank you for your prompt reply

 

Could you be a bit more specific on the 'Initialise of the queue should go outside of the loop and then only the write whould go inside the loop' bit?

 

Are you referring to the ViewGenCEU vi where I am displaying the values?

 

I will make sure that Can Data to Boolean and Can Data to Number are reentrant...thanks for the hint

 

 

0 Kudos
Message 3 of 7
(2,778 Views)

I am referring to the ViewGenCEU. 

Here is the snippet to show you how.

can.png

It would also be a good idea to use the error wire and have some error handling Smiley Wink

 

Mike

Message 4 of 7
(2,765 Views)

Thank you so much

 

I will try it now

 

One last question...in terms of enquing the data which of the three ways is the best?: Is 1 & 2 the same basically?

 

1. ProCanMsg - Queue1.jpg

 

2. ProCanMsg - Queue2.jpg

 

3. ProCanMsg - Queue3.jpg

 

Apologies but i want to understand the difference....

0 Kudos
Message 5 of 7
(2,758 Views)

It's all the same as ObtainQueue only defines the datatype...

And please: don't create queues again and again, once is enough!

And please: you have to close all those references (just in case you want to program in a 'clean' way...)!

 

Why don't you fill a single cluster with all data from that single CAN message? That way you only need one queue to store/transport all those values...

 

But well, some people prefer to create 12 queues for a single CAN message. Who am I to judge them? 😄

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 7
(2,749 Views)

GerdW

 

That would be the next step....I had to first get rid of the global variables and understand how to use queues...

 

I understand what you mean by using a cluster to store all data and use one queue instead of all these queues...which I will try to implement

 

Thank you for the help

 

Nick

0 Kudos
Message 7 of 7
(2,741 Views)