LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why is my global variable not updating?

I am trying to use a global array variable so that my data can be updated within a while loop in a sub vi. Why does this not update in the main calling vi? Maybe there is a better way to do this?

Help is appreciated.

Thanks,

Rebecca
0 Kudos
Message 1 of 10
(6,704 Views)
Instead of using global variable you can make the sub vi to have input and/or output. This way you can route the data to the main vi. You may attach a portion of your vi for additional input.
0 Kudos
Message 2 of 10
(6,704 Views)
Yes, thank you, I did that, but I need the data to be updated soooner than the sub vi's while loop finishes. It updates several times within the loop.
0 Kudos
Message 3 of 10
(6,704 Views)
Do you want the update as the While loop runs or after it has finished?
0 Kudos
Message 5 of 10
(6,704 Views)
I need it as it runs which is why I am using a global rather than a shift register.
0 Kudos
Message 6 of 10
(6,704 Views)
In a model vi that I build to mimic your program logic, the global variable is actually updating but one can only have access to the latest data after the while loop ends. How to access it real-time when the while loop is running I don't know yet. I suggest you check "Global Variable Examples" in LabVIEW help.
0 Kudos
Message 7 of 10
(6,704 Views)
I tried the Global Variable update and found that if I update the global variable using a reference (Invoke Node, Set Control Value), then the value is available in other VIs immediately.

If I remember from other discussions here, subVIs in LabVIEW make local copies of global variables, work with the local copies and then put the value back when they are done. References change the original value in the global variable (or something like that). You might want to try references.

Rob
0 Kudos
Message 8 of 10
(6,704 Views)
I appreciate the detail and understand the concept since I have used property nodes. Yet somehow I am not quite finding the way to use a reference with the global. Could you please explain this in more detail? I would very much like to try it.

Thank you,

Rebecca
0 Kudos
Message 9 of 10
(6,704 Views)
I'll go 1 better. I've built a short demo. It works since you can open a reference to another VI that is in memory. A VI that uses a global, automatically has that in memory. You need to know the name of the global that was saved.

Run the "Update Test.vi" in the .LLB that I created. The .LLB should contain all of the subVIs that I used (most from a standard library that I created).

Rob
0 Kudos
Message 10 of 10
(6,704 Views)
For your kind of applications, I have used a seperate VI acting as a memory-vi. You can write new data to it and read data from it.
It has uninitialised shift registers inside that hold the data.
In the subvi you write the newest values to the memory-vi and in the main, you can read in the new values from this same memory-vi.
I hope this suits your application.
0 Kudos
Message 4 of 10
(6,704 Views)