LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

static reference with global variable

Solved!
Go to solution

Hi, I've used a static reference to a subvi where I am changing a global varible before (3-4 years ago) and can't remember how I did that.

It was something like these attachment but now I am using LabView 2013 instead of LV 8.6.

The change in the global os not seen in the main vi (it seems like the invoke node run vi is not working with globals).

 

Furthermore the vi does close with the invoke node Close vi but not if I set the custom properties in the subvi to automatically close.

 

 

 

 

Download All
0 Kudos
Message 1 of 8
(3,100 Views)

You have a very classic race condition.  You have no clue when that global variable will be read.  It is very likely is is being read before your subVI is even called.  Maybe we should really be asking "what are you trying to do?"


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 2 of 8
(3,088 Views)

I don't see it being a race condition. The subvi stays open until the operator clicks OK or cancel button. I want the mainvi to read the status of the OK button.

0 Kudos
Message 3 of 8
(3,077 Views)

So when does the main vi read the Global variable:

When the user click Ok in the sub vi ?

When the main vi start ?

Before the sub vi start ?

After the sub vi start ?

 

 

0 Kudos
Message 4 of 8
(3,067 Views)

It could be read before the subvi is called. The idea is that it will be read when the subvi exits and if the user had pressed the OK button this True value will be read in the main vi.

The reason I wanted to do it this way is that there is a timer running in the main vi and if you are using a normal pop up message you will halt this timer.

0 Kudos
Message 5 of 8
(3,059 Views)

It could be, yes. It could also be read while the sub vi is runing.

This sounds to me as a race condition, you don't know for sure when the global variable is read and written to.

 

If you want the global variable to be read after the sub vi has finished, you need to forces it the execute in your order.

You could use a sequnce structure for that.

But then you are still waiting for the sub vi to complete.
Don't know how this relate to your timer description.

 

Why not call the sub vi as normal, just with the setting to show front panel when called?

Use the connector pane to transfer the Ok button's value from the sub vi when it completes.

Message 6 of 8
(3,046 Views)
Solution
Accepted by topic author hasse

dkfire wrote:

Why not call the sub vi as normal, just with the setting to show front panel when called?

Use the connector pane to transfer the Ok button's value from the sub vi when it completes.


That is what I recommend.  If that isn't possible for whatever reason, then you need to use a Flat Sequence Structure to force the reading of the global variable until after the subVI is complete.


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
Message 7 of 8
(3,032 Views)

Yes, your solution worked perfect. I just put a while loop in the main vi and waiting until the response from the subvi is coming. Then it will still run both vi:s at the same time.

I don't know why I was using static references and global variables before. This is simplier and works good.

Thanks!

0 Kudos
Message 8 of 8
(3,028 Views)