02-05-2010 06:21 AM
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
02-05-2010 07:47 AM
02-05-2010 07:49 AM
02-05-2010 08:40 AM
02-05-2010 08:46 AM - edited 02-05-2010 08:46 AM
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?
02-05-2010 08:57 AM - edited 02-05-2010 09:01 AM
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.
02-05-2010 09:32 AM
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.