LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Global Variable

Hi.

Let me explain the program:

- Main.vi is the main vi. Inside is a loop with sub vi's in it. After
doing the necessery the settings, it calls a sub vi ->> Problem.vi

- Problem.vi is where the actual temperature measurement is done in a
loop. There is a digital display with the current temperature
measurement, so that it displays the temperature on the front panel
each loop cycle.

My question is:

- How do I display the current temperature measurement in Main.vi ?

If I use a global variable, it only dislays the last temperature
value. Meaning, only after finishing Problem.vi, would the temperature
value in Main.vi change

Thanks in advance!!!!!

0 Kudos
Message 1 of 11
(4,114 Views)
You would have to place the sub VI outside the main loop.

It will execute in parallel to the main loop.

OR

Use VI server to dispatch the subVI dynamiccally and allow the main VI to continue.

André
Regards,
André (CLA, CLED)
0 Kudos
Message 2 of 11
(4,104 Views)
Hi DaVinci,

if you write to the global in your measurement loop, you can read from the global in your UI loop and you will get the latest results. Maybe change your iteration times to avoid reading 100 times before a new value is written to the global... Don't forget: you need a second (independent from subvi) loop in your main vi to read the global!

There are other options too:
- using a queue (aka FIFO buffer) to move values from subvi to main vi
- using a functional global (aka LV2-style global) to encapsulate and maintain read/write operations
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 11
(4,102 Views)
User events also work well for this type of variable update. I would get in the habit of avoiding globals. While they can be useful in some circumstances, unless you really know what you are doing, you will produce difficult-to-debug race conditions.
Message 4 of 11
(4,063 Views)

The best way I’ve found to do what you want to do is by using references.  Rather than passing in the Temperature variable to the subvi, pass in a reference to it.  That way when you update the variable in the subvi, the indicator in the main vi gets updated at the same time. No need for globals.

Doug Asselbergs
Certified LabVIEW Developer
Message 5 of 11
(4,030 Views)
Hi
 
i'm back to the global variable problem again.
 
Uploaded are shots of the Sub VI and Main VI
 
In the SubVI, I read pressure measurments 100 times (FOR loop) and the value is given to a global variable. Apart from that. I count the average.
 
In the MainVI , I call the SubVI to run parallel. This means that my other subVIs can be executed eventhough SubVI isnt finished. How do I display the Global Variable in MainVI ? or How do I display each pressure reading in MainVI and not just the last one?
 
Thanks 🙂
Download All
0 Kudos
Message 6 of 11
(3,892 Views)
Hi DaVinci,

put the part reading the global in the main-vi in it's own loop. Main point is: make the sub-vi call independent from global-display!

Btw: Why don't you just put the subvi into the main-vi instead of using vi-server functions?

Btw 2: It would be much easier to demonstrate the points above when you would include vis instead of pictures...



Message Edited by GerdW on 01-09-2008 04:03 PM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 11
(3,883 Views)
Hi, thank you for the reply.
 
I have attached a simplified MainVI and some VIs needed to run Main.
 
I now put the reading the global part in the main-vi in it's own loop. How to make the sub-vi call independent from global-display?
 
To answer the question: Why not just put the subvi into the main-vi instead of using vi-server functions? --> I want SubVI to run and Daten VI to run as well without waiting for SubVI to finish executing.

André mentioned: Use VI server to dispatch the subVI dynamiccally and allow the main VI to continue. This is what I think I was doing. Is this correct?
 
GerdW also mentioned other options:
- using a queue (aka FIFO buffer) to move values from subvi to main vi
- using a functional global (aka LV2-style global) to encapsulate and maintain read/write operations
Could you elaborate ?
 
DFGray mentioned: avoid using globals and use User events.
Doug Asselbergs mentioned: use references. This will update the indicator in main vi.
 
I have failed to discover the last two options 😞
 
Thanks ! 🙂
 
Best regards,
Affa
0 Kudos
Message 8 of 11
(3,847 Views)
Hi DaVinci,

attached you will find changed vis to demonstrate parallel execution of code parts Smiley Wink
Attention: I simplified the "subvi" a lot, don't overwrite your original vis!


Message Edited by GerdW on 01-10-2008 11:40 AM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 11
(3,837 Views)

Thank you!!

As expected --> parallel loop should execute at same time, provided they are not connected. Smiley Very Happy

Regards,

Azfar

 

0 Kudos
Message 10 of 11
(3,786 Views)