LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW 2010 local variable behavior

Solved!
Go to solution

Hi -

 

I upgraded to LabVIEW 2010 from 2009SP1 and the attached sub VI no longer works correctly.  This is a state machine case structure that gets called inside a loop.  I'm setting a Boolean local variable true, then on the next call when the case changes the variable has been reset to false. It did not do this in LV2009.

 

Someone will immediately tell me I have a race condition, but these local variables are not being written anyplace else, just within these separate cases.

 

See the attached code, specifically, the local variable "Enable" is getting reset when going from case "Enable" to case "Turn on".

 

Anyone else seen this issue, or can shed any light?

 

I fixed the VI by writing the value in each case, but this different behavior makes me wonder what other issues are lurking in LV2010?

 

Thanks

0 Kudos
Message 1 of 14
(3,867 Views)

First this is a very strange way to do a state machine. Iterating through the fore loop only one time is very strange indeed. All of the local variables seem to work as far as I cam tell.

Tim
GHSP
0 Kudos
Message 2 of 14
(3,846 Views)

>>First this is a very strange way to do a state machine. Iterating through the fore loop only one time is very strange indeed.

 

This is a sub-VI that gets called repeatedly from a while loop, that's why there is no outside loop.

0 Kudos
Message 3 of 14
(3,836 Views)

Have you tried to highlight the execution, the turn on state execute fast and if you go back to idle "enable" is set back to false.

0 Kudos
Message 4 of 14
(3,835 Views)

I guess you do have a race condition, there's no guarantee in which order the locals are set to the indicator.

Check this small modification, if it works you did have a race condition.

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 5 of 14
(3,820 Views)

OK, thanks, I'll try it.

 

And thanks for showing me "Use default if unwired" on the output tunnels, I didn't know you could leave some cases unwired like that.

0 Kudos
Message 6 of 14
(3,806 Views)

Here is a version where I got rid of most of the Local variables. I use the one I have and take advantage of the way the locals update to my advantage here.

Tim
GHSP
0 Kudos
Message 7 of 14
(3,785 Views)

Here is a 2009 version

Tim
GHSP
0 Kudos
Message 8 of 14
(3,781 Views)

I would never want to do a state machine like this. I hope you the best of luck with this.

Tim
GHSP
0 Kudos
Message 9 of 14
(3,779 Views)
Solution
Accepted by topic author RandomBob

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

Inventor of the WORM Global
Message 10 of 14
(3,750 Views)