LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW 2010 local variable behavior

Solved!
Go to solution

Thanks to all for your suggestions.  I see that the right approach is to get rid of the local variables. 

This is what happens when a C programmer turns to LabVIEW Smiley Wink

0 Kudos
Message 11 of 14
(408 Views)

 


@tbob wrote:

This code looks more like some sort of an Action Engine than a state machine, but not quite.  It gets called repeatedly from a state machine, and it decides what the next state will be depending upon the inputs.  Instead of using all those local variables, I would use uninitialized shift registers (nothing wired to the left side).  They hold their value from one call to the next.  One more case needs to be added in this case.  An unnamed, default case that would set the initial values of all the shift registers.  Make it the default case and don't even name it.  It will be called first automatically because the shift register is uninitialized so the default will be called.  Inside the default case, set all the shift registers to desired values.  Next time this subvi is called, those values will still be there.  That is as long as nothing is wired on the left side,  Whatever is wired to the state shift register will be the next case called.

See attached vi.  It is broken because I did not wire anything to the indicators.


 

tbob

 

The reason I used the locals instead of the loop was that I thought he was calling this vi over and over again. The way you have it the loop would never stop. My code exicutes once and then moves on but still remembers what it did the last time through. I do not have to have a loop and will not get caught in this loop. The way the orgianl code was written it looked like that was the way it was being used.

Tim
GHSP
0 Kudos
Message 12 of 14
(396 Views)

Yes aeastet, you are right, I am calling this repeatedly from a while loop.

I revised it much like tbob's version, with uninitialized shift registers (in a single-iteration for loop), and everything seems to be OK.

 

0 Kudos
Message 13 of 14
(387 Views)

@aeastet wrote:

 

 

tbob

 

The reason I used the locals instead of the loop was that I thought he was calling this vi over and over again. The way you have it the loop would never stop.

 


 

Never stop???  There is a true constant wired to the stop sign.  The loop will execute only once.  The only reason for the loop is to have uninitialized shift registers which hold the value of the previous call.

 

 

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 14 of 14
(351 Views)