From Thursday, May 23rd (05:00 PM CDT) through Friday, April 24th (1:30 AM CDT), 2024, 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: 

Global not read within while loop -- but Local is

Solved!
Go to solution

I have a front panel switch writing to a variable so it will be read within a while loop.   If the variable is Local, it is read and my code works, but I need to make a subvi of the inner loop so it appears I have to use a Global variable--but then it is not read, and the code does not work.  I am very new to Labview and I don't recall this difference being pointed out any where.  I have posted a very simple example.

 

Instructions: Click on SW-LV, the inner loop starts; turn the switch off, inner loop stops.  Clicking on SW-GV starts the inner loop, but the inner loop does not stop by turning off the switch.  If I go to the front panel of SW-GV I can stop the inner loop. 

 

Any help woud be appreciated.

 

I am using Labview 2011 Evaluation and Windows 7.

Download All
0 Kudos
Message 1 of 4
(2,030 Views)
Solution
Accepted by topic author labujones

You are a little off in your reasoning.  I'll explain whats going on.

 

In the Lower loop the outer loop runs and the inner loop runs once per iteration of the outer loop until the value of SW-LV goes True. Then the inner loop starts running reading the value of SW-LV each iteration until you press thw SW-LV button at witch point the value of SW-LV changes (Trust me, Rip the Write Local out and it works the same)

 

The upper loop: outer loop runs and the inner loop runs once per iteration of the outer loop until the value of SW-GV goes True AND The Global is written.  The Global cannot be written to again from this loop since the outer loop is waiting for the inner loop to finish (You have a classic deadlock!)  Writing to the global elsewhere (like from the global itself, breaks the deadlock)


"Should be" isn't "Is" -Jay
Message 2 of 4
(2,023 Views)

Yes Just now saw that code. Literally you got locked into that logic since it appears to be logically correct but need to take a closer look. Clear explanation Jeff.

-----

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

Thanks for the prompt reply Jeff, I was very confused and understand it better now.

 

You seem to imply that in the LV loop, the button labeled SW-LV -is- the Local variable SW-LV so the inner loop doesn't need to yield.  That seems to be so, if I rename the button, all the variables get renamed, and if I click on the button or variable in the block diagram, Labview highlights the same button SW-LV on the front panel, so they must be all "the same."

 

But in the GV case, it appears that the button in the Global front panel is what -is- the global variable SW-GV, and it doesn't matter what I name the button on the block diagram even SW-GV, there is no such association.  That's fair enough, the real SW-GV is not on the diagram.

 

So it may not be possible to make a subvi out of the inner loop (in the real code) if I keep the current structure.  Will return, thanks again.

 

0 Kudos
Message 4 of 4
(2,004 Views)