LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

accessing data between VI's using global variable

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

0 Kudos
Message 1 of 14
(3,368 Views)

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...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 14
(3,365 Views)

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

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 14
(3,344 Views)

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.


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
0 Kudos
Message 4 of 14
(3,328 Views)

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

0 Kudos
Message 5 of 14
(3,315 Views)

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…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 14
(3,310 Views)

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.


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 7 of 14
(3,308 Views)

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. 🙂

-----

The best solution is the one you find it by yourself
0 Kudos
Message 8 of 14
(3,307 Views)

Hello Guys,

 

Actually I am new to this. I tried to work it out but no success.Smiley Sad........

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

0 Kudos
Message 9 of 14
(3,271 Views)

You need to create the queue and pass the queue reference into your subVIs.  Close the queue your subVIs are done running.


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
0 Kudos
Message 10 of 14
(3,253 Views)