LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

event structures

Solved!
Go to solution

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?

0 Kudos
Message 1 of 11
(2,995 Views)
Solution
Accepted by labnoob

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!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 11
(2,986 Views)

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

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 3 of 11
(2,985 Views)

damn! how could i achive what i need to achive then? any ideas?

 

many thanks

0 Kudos
Message 4 of 11
(2,969 Views)

make a simple state machine not stacked.

use one event structure per vi.

0 Kudos
Message 5 of 11
(2,959 Views)

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

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 6 of 11
(2,954 Views)

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.

0 Kudos
Message 7 of 11
(2,950 Views)

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

0 Kudos
Message 8 of 11
(2,944 Views)

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

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 9 of 11
(2,935 Views)

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

0 Kudos
Message 10 of 11
(2,929 Views)