07-08-2014 08:01 AM
Hello,
How efficient is this to use Global variable to echange data between different VI's. Is there any other better way to do this?
best regards,
Swap
07-08-2014 08:05 AM - edited 07-08-2014 08:20 AM
There are many alternatives. There are functional global variables, queues, notifiers, user-defined events, data value references...
"Better" is a funny word. What constitutes a "better" solution depends on what you want to do. To decide what is better for your application you need to understand (just to start) the kind of data, where and how the data will be accessed, and what will be done with the data.
Mike...
07-08-2014 08:36 AM
It's efficient as in "fast" and easily implemented, but depending on how often you set/read you'll run into race conditions, so it's not safe/secure. Depending on what the program do with the information that might be a problem, or not. I have much inherited code which uses a Running-global and sets it to false when the user wants to exit. The other loops will stop "this iteration or next", and that's ok since it's a 0.5 sec UI update loop and a background sampler.
If the safety/security of the information is important it's better to use events or queues, and in more advanced projects i use a "system event" (named user event) to signal shutdown.
/Y
07-08-2014 09:18 AM
As has been said, it really depends on exactly what you are trying to do.
Personally, I much prefer using queues to pass data back and forth. That way I know that I don't miss anything.
07-08-2014 09:30 AM
HI Crossruz,
here is my VI. I reading the CAN data using this VI. I want to use this vi as SubVI in my main VI to read the CAN data and to do some calculations.
I tried using Que method but elements are not being qued. I am not sure that I did it in a right way or not.Please have a look on my code and let me know the corrections.
thanks in advance.
regards,
swap
07-08-2014 09:34 AM - edited 07-08-2014 09:38 AM
Hi swap,
you need to THINK DATAFLOW!
Your data gets enqueued!
But: Before your subVI outputs the queue reference you already destroyed the queue inside of your subVI.
As I said before: THINK DATAFLOW!
You need to create (and destroy) the queue outside of your subVI…
07-08-2014
09:34 AM
- last edited on
05-09-2025
02:25 PM
by
Content Cleaner
You aren't passing the queue to anybody to use. Somebody needs to be able to read while you are enquing the data.
I recommend you look at the Producer/Consumer architecture to see how this is supposed to work.
07-08-2014 09:34 AM - edited 07-08-2014 09:35 AM
Additional information:
Global Variable: Simple, easy to create and easy to use but creates copy of memory on every instance. More chances of Race condition.
Functional Global: Chance of Race condition is comparitively low.
Queues: Used to transfer data but its mostly used in places where loss of data is not compromised. But using Queues similar to the other two above methods may give undesirable results.
Edit: Ignore this. I am way too slow. 🙂
07-09-2014 01:54 AM
Hello Guys,
Actually I am new to this. I tried to work it out but no success.........
Could anyone please tell me what changes I should make in Main VI and SubVI. A small example or modification in my above attached VI will be a great help.
thanks in advance.
regards,
swap
07-09-2014 07:04 AM
You need to create the queue and pass the queue reference into your subVIs. Close the queue your subVIs are done running.