LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

global variable

Hello

 

I have a global variable that is a int.

 

I`m using a VI to write on it a value and another VI to read this value.

Now, every works well untill I keep both the VI running (write and read), but as soon I close the write one the vaule into the global variable is reinitialized to the default value.

How can I avoid this?

 

thanks

 

Vincenzo

0 Kudos
Message 1 of 7
(3,514 Views)
First avoid using a global variable. Use a property node. Which should solve your problem.
0 Kudos
Message 2 of 7
(3,491 Views)
Message 3 of 7
(3,490 Views)
As mentioned try to change your system to avoid using the global variable. Which approach would be best depends on how you want to use it. You could use a functional global (action engine if you require more than simply a read/write), a LVOOP object, a shift register or a message based architecture using queues or notifiers. In general global variables, as well as local variables, should be avoided since they can lead to race conditions, make debugging your code more difficult, break the data flow paradigm as well make the code harder to read and understand.


Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 4 of 7
(3,472 Views)

Hi Vincenzo,

 

as muks tried to express: globals can easily lead to race conditions and you can avoid them by using FGV aka AE aka LV2style Globals.

That being said:

Usually a global keeps it's value as long as it is in memory (and there it stays as long as the Read.VI is running). So I can't believe the global is reset to default value when the Write.VI is stopped...

Can you attach an example, where this behaviour is shown?

Message Edited by GerdW on 02-05-2010 03:46 PM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 5 of 7
(3,464 Views)

enzo78 wrote:

....as soon I close the write one the vaule into the global variable is reinitialized to the default value.


Regardless of globals being evil, etc, this should not occur unless your global VI is being closed and re-opened. Your global should have the last data written to it. Maybe somewhere else you are writing to the global, which is exactly why we tend to stay away from globals, because it breaks the dataflow paradigm which makes LabVIEW easy to troubleshoot - or at lest easy to see where all the data are.

Right-mouse-click on the global and Find > Global References to see where other copies reside.

 

 

Message Edited by Broken Arrow on 02-05-2010 09:01 AM
Richard






0 Kudos
Message 6 of 7
(3,459 Views)

muks wrote:
First avoid using a global variable. Use a property node. Which should solve your problem.

A property node is not a substitute for a global variable. It's not even a good substitute for a local variable.

0 Kudos
Message 7 of 7
(3,440 Views)