08-16-2010 01:25 PM
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
Solved! Go to Solution.
08-16-2010 01:48 PM
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.
08-16-2010 01:56 PM
>>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.
08-16-2010 01:57 PM
08-16-2010 02:02 PM
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
08-16-2010 02:12 PM
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.
08-16-2010 02:49 PM
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.
08-16-2010 02:50 PM
Here is a 2009 version
08-16-2010 02:51 PM
I would never want to do a state machine like this. I hope you the best of luck with this.
08-16-2010 05:04 PM
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.