question

Alessio Merlo avatar image
0 Likes"
Alessio Merlo asked Alessio Merlo commented

OnStateChange: issue with multiple set and multiple wait for

Hi,

today I bumped into a problem with OnStateChange trigger and event.

I don't know if it is a bug, but conceptually it would works well without workaround. The model is attached (statechange_issue.fsm).

I set the state twice in the same moment and I would like to detect the state transition three times (two for the first set, one for the second one). But my process detects only two state transition (one for the former, one for the latter). Why?

Could someone help me? How does the notification occur? @anthony.johnson or @phil.bobo probably you have to reveal some "DLL secret".

Thanks for support!

FlexSim 20.0.8
wait for eventflexsim 20.0.8onstatechangemonitor
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

·
Phil BoBo avatar image
2 Likes"
Phil BoBo answered Alessio Merlo commented

This isn't a bug, and using a Breathe isn't a work-around; it is the solution.

https://docs.flexsim.com/en/20.2/ModelLogic/AdditionalConcepts/TroubleshootingProcessFlows/#delays

Wait for Event fires immediately. It synchronously interrupts the event to execute additional logic.

The first setState() hasn't even finished when you are trying to set the state again. Of course you need a breathe. Let the original event finish before changing the state again.

The OnStateChange event fires before the state value is even set. If you return -1 from OnStateChange, then it doesn't set the state value. You are calling the setState() function recursively from within the setState() function before it has even set the state value from the first function call.

So the second setState() is finishing before the first setState() finishes, which leaves the object in the state of the first setState() because you interrupted it before it finished. Let it finish with a breathe if you want the functions to happen in series instead of in recursion.

Here is a diagram showing how Wait For Event works and what using a Breathe Delay activity does. (This example is in the setstate function, but the same principle applies to listening to any event.)


1599229926178.png (31.7 KiB)
1599230380232.png (41.5 KiB)
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Alessio Merlo avatar image Alessio Merlo commented ·

Thanks Phil!

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.