LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

local variable default value

Solved!
Go to solution

Hi

 

Just a quick question to get me out of a hole..... I am using local variable to control while loops, and based on a counter value, it turns it on or off. When i probe the value of the actual boolean, it comes up not exectuted, but the local indicator value is true???? is there any way to change this?? i need to to remain false, UNTIL it goes true!

 

Cheers

Peter

0 Kudos
Message 1 of 13
(5,554 Views)

What do you mean by the "local indicator"?

 

The local variable is a reference to the memory location of a front panel indicator or control.  That indicator is going to have a value even if no code has executed yet.

 

If this doesn't answer your question, please post your VI so we can see what you are trying to do.  With your description, I wonder if you are causing yourself some race condition problems.

0 Kudos
Message 2 of 13
(5,542 Views)

Hi,

I am attempting to stop the while loop containing the counter. The while loop should stay running until the counter value saifies the parameters of the position vI, which then should turn the two variables Xstop2 and Ystop2 true, (it does this ok) and that in turn turns the Boolean icon Ystop3 true (it does), but the local variable [YStop 3] in the counter while loop is true all the way alsong, regardless of whether the counter has satisified the contidtions of the position VI? (this is stopping the counter straight away, and the VI will never leave this situation then)

 

Local Variable.jpg

Message Edited by newbie09 on 03-04-2010 07:26 PM
0 Kudos
Message 3 of 13
(5,535 Views)

Hi,

 

Indeed of usually local variables, try using a queue instead.  You may have a race condition going in your program.  If not, for the boolean that you said is always true, check to see is it default value true or not.  If it is, you need a boolean with default value of false instead.

 

Yik

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
Message 4 of 13
(5,526 Views)

I asked you to post your VI, not a screen shot where half the code is cutoff.

 

You almost certainly have a race condition going on.  That means your logic is uncontrolled because it is dependent on what code is executing first which you have no control over.

   For instance, the local variable of Y-stop3 is getting read before a value gets written to it, which means it will have either the default value from when the VI was opened, or the value left in there from the last time it was run.

 

 

(PS.  Don't forget to wire your error wires on the DAQmx functions.)

Message 5 of 13
(5,521 Views)

I think that "Ravens" has hit the nail on the head. Using unprotected shared resources (like local variables) in parallel will open the door to race conditions... the bane of any programmers life!

 

Here are some useful resources which further explain this concept.

 

Using a Local, Global, or Shared Variable in Parallel Loops Can Cause Race Conditions

http://digital.ni.com/public.nsf/allkb/4F3CC921B4179F9F86256A3B0045CE2D

 

Tutorial: Local Variable, Global Variable, and Race Conditions

http://zone.ni.com/devzone/cda/tut/p/id/7585

 

The first link also mentions the producer/consumer articeture and the semaphore. Both great solutions. However, correctly sequencing your source code (using things like error clusters) will help prevent this issue.

 

Further more, I wonder if you are initialising your variables??

You should write a value of false to the variable before you enter the main body of your code. This ensure that the first time you read from the variable it will return a known value (false). If you dont do this, the variable will return what ever was the last value written to it.

 

Hope this has been useful.

Rich Roberts
Senior Marketing Engineer, National Instruments
Connect on LinkedIn: https://www.linkedin.com/in/richard-roberts-4176a27b/
Message 6 of 13
(5,503 Views)
I would also highly recommend you take a serious look at your program architecture and if nothing else consider using a state machine. From the screen shot you posted your application is using a 31 frame stacked sequence structure. This is a VERY bad way to implement your application. If you ever need to abort your application early you will not be able to do so. You will have to execute EVERY frame of the sequence structure. The only way to prevent code in following frames from being executed would be to have case states in every frame. This could get very ugly very fast. In addition wiring data between frames is extremely ugly as well.


Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 7 of 13
(5,483 Views)

Rich,

 

Any quick way to write code to initialise the variables, withour resetting the whole program?

 

Rgds

Peter

Message Edited by newbie09 on 03-05-2010 09:28 AM
0 Kudos
Message 8 of 13
(5,477 Views)

Mark Yedinak wrote:
I would also highly recommend you take a serious look at your program architecture and if nothing else consider using a state machine. From the screen shot you posted your application is using a 31 frame stacked sequence structure.

I didn't even notice that!  But I did see that the user needs to download and install some Windows updates.Smiley Very Happy

0 Kudos
Message 9 of 13
(5,476 Views)
Solution
Accepted by topic author newbie09

newbie09 wrote:

Rich,

 

Any quick way to write code to initialise the variables, withour resetting the whole program?

 

Rgds

Peter

Message Edited by newbie09 on 03-05-2010 09:28 AM

There is but I am hesitant to tell you only because by doing so it would only enable bad programming habits. You need to really look at your code and avoid the use of all the local variables as well as the overuse of the sequence structures.

 

Being nice though you can simply write a value to another copy of the local variable or you could use a method (Invoke node) for the control/indicator and use the method "Reinitialize to Default".



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 10 of 13
(5,467 Views)