09-04-2014 09:24 AM
I have a nested state machine which mechanises some manual pump commands within my main autonomous program. To enter the state in the main state machine where this nested state machine resides, the user clicks on a switch which latches. This causes the top level state machine to enter the correct state as expected; however my nested state machine exits straight away. The second state within the nested one is as per the pic shown. I have an event structure which has two events. If the latching switch that got us in here in the first place changes state, i.e. unlatches then this event runs; “changes of value” and wil take me out of this nested state machine. My trouble is its counting the initial latching mechanism as a change of value. I don’t understand why it would do this since this happened upstream in time of the event structure executing.
Any ideas?
Solved! Go to Solution.
09-04-2014 09:28 AM
Hi noob,
event structures catch all events they are registered to. Even when the event structure can't execute (because it is hidden in nested case structures) it will catch the event.
After catching the event the DATAFLOW rulez: the event will get executed when the event structure has a chance to execute. And as it stores all events in its internal event queue it may have a lot of events to execute…
Lesson learned: Never hide event structures in case structures!
09-04-2014 09:28 AM - edited 09-04-2014 09:30 AM
Never stack event structures. Never ever.
Unless you are a real expert and KNOW what happens internally. Until that time, above rule is fixed.
EDIT: Same holds true for "sharing" event sources in different event structures. Gerd's hint is also valuable: Never hide event structures in "sub-systems".
Norbert
09-04-2014 09:41 AM
damn! how could i achive what i need to achive then? any ideas?
many thanks
09-04-2014 09:45 AM
make a simple state machine not stacked.
use one event structure per vi.
09-04-2014 09:47 AM
In the first place: Why do you stack state machines at all? Do you use the "sub-system" anywhere else in your project? If yes: Why isn't it placed in a subVI?
If no: Please integrate it in your top-level state machine.
Norbert
09-04-2014 09:50 AM - edited 09-04-2014 09:50 AM
Sorry Norbert , when you said, "Never stack event structures." did you actually mean Never stack statemachines? Yes, i suppose i could just add the sub states to the mains states. In my head just thought it made better sense like that. So if I do that, are you saying the event structure will work as expcted, or will i still have issues with that too? sounds like I might as per what Gerd said.
09-04-2014 09:53 AM
it just made sense to me to sepearte this from teh main code but take on board what you are all saying so will move this to the main states. and no this is not called anywhere else, otherwise i would have made this a subvi.
thanks
09-04-2014 09:56 AM
Without seeing the code, i cannot tell you if you really stacked event structures. Stacking event structures means that you are creating/placing an event structure in an event case of another event structure. This issue can be obfuscated if the event case includes loops and case structures....
Point is that having multiple event structures in one VI requires the developer to take special care. Experience shows that most developers don't (either by lack of knowledge or simply "lazyness"). Nevertheless, that's why i stated that 'rule of thumb'.
Norbert
09-04-2014 09:58 AM
no, it wasnt an event structure i stacked, it was a statemchanine i stacked. like a nested statemchaines as per my first post. is that ok then? i dont have any nested event structures