LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Local/global variables

Good morning everyone, I premise that I am new to Labview, however, I am working on a project and can't figure out how to use local/global variables. This project contains loops and for, and I need to update a variable in multiple places. For now, I have been using the local variables, calling them in the project, however, conflicts arise as this value is not being updated correctly. I guess this is not the right method, so I kindly ask for your help: I need to update a value multiple times within the same project. Thank you!!!

Translated with DeepL.com (free version)

0 Kudos
Message 1 of 4
(261 Views)

Hi giuli,

 


@giuli_ wrote:

I am working on a project and can't figure out how to use local/global variables.


You shouldn't need local/global variables at all (or not so often)!

Instead your program should rely on "THINK DATAFLOW", as the wire is the variable!!!

 


@giuli_ wrote:

This project contains loops and for, and I need to update a variable in multiple places.

For now, I have been using the local variables, calling them in the project, however, conflicts arise as this value is not being updated correctly.


So you try to access local/global variables in parallel from different places in your code and you wonder why you run into race conditions?

That's why I recommend to not use locals/globals at all (or not so often)…

 


@giuli_ wrote:

I guess this is not the right method, so I kindly ask for your help: I need to update a value multiple times within the same project.


You need to make sure you prevent parallel access to the same resource (aka prevent race conditions)!

  • You might start with an AE (action engine) aka FGV (functional global variable, LabVIEW2 style): the value is stored in a shift register of a subVI, and that subVI is set to non-reentrant (default).
  • You might redesign your program so there is no need for parallel access to your internal data…
  • You might learn to use LV-OOP as one step further then just AEs/FGVs for even more data encapsulation…

You might even show your current code to get more detailed and specific suggestions!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 4
(243 Views)

If you have multiple loops attempting to update the same local/global variable, you have a major design issue as it points to the loops being broken up too much. You might want to consider combining loops into a single loop.

 

At a very generic level, you should not be using local or global variables. I would need to know a lot more about your application to make any meaningful suggestions beyond that.


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 3 of 4
(198 Views)

@giuli_ wrote:

Good morning everyone, I premise that I am new to Labview, however, I am working on a project and can't figure out how to use local/global variables. This project contains loops and for, and I need to update a variable in multiple places. For now, I have been using the local variables, calling them in the project, however, conflicts arise as this value is not being updated correctly. I guess this is not the right method, so I kindly ask for your help: I need to update a value multiple times within the same project. Thank you!!!

Translated with DeepL.com (free version)


Once you show us your code, we can tell you what you are doing wrong.

 

Local variables are just secondary taps for front panel elements and the code determines when they get read or written and that is determined by dataflow. For example if the local is before or after the loop, it will only get read before the loop starts or after the loop has finished, respectively.

 

Local variables should not be confused with "variables" in text based code. Their use is typically limited to UI tasks. In LabVIEW, "the wire is the variable".

Message 4 of 4
(165 Views)