From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Frequently update global variable

Solved!
Go to solution

Hello,

 

I made this counter, that counts from value x to value y.

This value I need in an other VI, so I made from this VI a subVI.

The counter value is needed in an other For loop to count with.

But the counter doesn't update his self every time, in that main VI.

How can I make the value frequently updated in that main VI without using a while loop.

If I put the global variable in a while loop it will update, but than the while loop will be executed constantly,

and the For loop won't be executed until the while loop is stopped.

Counter.JPG

 

0 Kudos
Message 1 of 10
(4,095 Views)

Its tough to answer the question without seeing the while loop and the for loop without seeing the main vi you are talking about. Try to post that snapshots also.

-----

The best solution is the one you find it by yourself
0 Kudos
Message 2 of 10
(4,092 Views)

If this is the main VI, than the value of x+1 doesn't update himself.

Inside the subVI the counter is counting, but the global variable and the "x+1" indicator don't show the counting,

only if I put them in a while loop. But I can't use a while loop it blocks other loops to run.

 

Counter main VI.JPG

0 Kudos
Message 3 of 10
(4,087 Views)

If the problem is to use the counter in several vi's, it might be easiest to simply use the global as a counter and read from that.

/Y 

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

Qestit Systems
Certified-LabVIEW-Developer
Message 4 of 10
(4,086 Views)

Hi Stef,

 

"Inside the subVI the counter is counting, but the global variable and the "x+1" indicator don't show the counting, only if I put them in a while loop."

If that's your problem: you have to obey the DATAFLOW paradigm. When you check the global only once, you will see no further updates. When you check the global frequently (in a loop) you will see updates.

 

"But I can't use a while loop it blocks other loops to run."

Why can't you? You should be able to use parallel running loops...

 

Hint:

- Go through the basics course offered by NI.

- Learn to think in DATAFLOW terms!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 5 of 10
(4,079 Views)

Reading/Writing with a global requires a loop in your top level VI. Using a reference and passing it to she subVI where you write to it's Value property does not.

0 Kudos
Message 6 of 10
(4,054 Views)

So, what are you really triing to do with this?


"Should be" isn't "Is" -Jay
0 Kudos
Message 7 of 10
(4,042 Views)

@Stef_vl wrote:

If this is the main VI, than the value of x+1 doesn't update himself.

Inside the subVI the counter is counting, but the global variable and the "x+1" indicator don't show the counting,

only if I put them in a while loop. But I can't use a while loop it blocks other loops to run.

 

Counter main VI.JPG


 

Have you tried turning on execution highlighting (the lightbulb on the BD menu bar). It will show when values are moving and give you an idea of how data flow is really working.

 

Ben

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 8 of 10
(4,026 Views)
Solution
Accepted by topic author Stef_vl

Here is how I would do it using an AE (action Engine)

 

Example Main.png

Tim
GHSP
Download All
Message 9 of 10
(4,015 Views)

Ofcourse they dont show anything. You have a loop in a sub vi, and the result you get out is the end result once it stops executing. That's basic dataflow.

Your counter2 reads the global variable once and shows the result, it doesn't automagically follow and update from the global variable. That's basic dataflow.

Your program does exactly what you told it to do. That it makes little sense is not basic dataflow. 🙂

 

Run the program in highlight mode and it should be quite obvious. But main and sub-vi. 

 

/Y 

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

Qestit Systems
Certified-LabVIEW-Developer
Message 10 of 10
(3,998 Views)