04-12-2013 06:12 AM
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):
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):
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?
The idea is then to pass the variables in another vi and display them as shown below (VieGenCEU - Queue.vi):
I have also attached all the code in a zip file....Any help would be much appreciated
Thanks
04-12-2013 06:24 AM
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
04-12-2013 06:31 AM
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
04-12-2013 07:11 AM
I am referring to the ViewGenCEU.
Here is the snippet to show you how.
It would also be a good idea to use the error wire and have some error handling
Mike
04-12-2013 07:36 AM
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.
2.
3.
Apologies but i want to understand the difference....
04-12-2013 07:59 AM - edited 04-12-2013 08:16 AM
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? 😄
04-12-2013 08:15 AM
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