Event OnMessage

All topics specific to modeling questions in Enterprise Dynamics
Post Reply
Thor
Posts: 12
Joined: Thursday 16 January, 2014 - 15:16

Event OnMessage

Post by Thor »

Dear ED Community,

there is a funny thing going on in my model with regard to an event on message. It shall be triggered from different locations, however one works and the other one does not. I now have tried for hours but cannot figure out why this is the case.

The model is attached for better reference. For a quick overview I suggest to open the tracer and the table "Startup Permissives".

The atoms represent a machine that is shut down after certain events via ExecOnUser on the atom "TurbineOnOff". This works.

Turning it on again is the problem. This is supposed to happen on message to the atom "Startup Initiation". The Atom "Startup Initiation" then checks in the table "Startup Permissives" whether the startup conditions are met (see table). The entries in this table are increased/decreased while "products" (representing failures that need maintenance) run through the model.

There are two streams of "products". The blue one and the red one. For the blue one the model works just fine and when it enters "Processed Workorders" a message is sent to the atom "Startup Initiation" which (after a check of the startup permissives) triggers "TurbineOnOff".

The processing of the red product is slightly different but after running through the model and entering "PickUp Point" the "machine" should be restarted. However this does not happen. "Startup Initiation" receives the message and executes the OnMessage code but deems the startup conditions (from the table) as not met and therefore does not startup the machine again (see trace message which is given out when startup request was denied).

Is it possible, that the OnMessage Event is executed before the values in the table "StartupPermissives" are updated?
But then, why does it work for the blue products?

I have spend quite some time on this problem today and would be greatful for help.
Best regards
Thorsten
Attachments
20140122 Startup Permissives.mod
(95.3 KiB) Downloaded 222 times
marlies
Posts: 301
Joined: Monday 17 January, 2011 - 09:28

Re: Event OnMessage

Post by marlies »

Hi Thorsten,

Did you already try to step through your code using the debugger?

When you add Enterdebugger(1) to your code, the debugger will pop up, once the code is executed. This will enable you to step through the code in the sequence of execution and see the results step by step. I did this for example in the beginning of the trigger on entry of the pickup point.

What I see is that the value in the 3rd row is updated (which is done in this trigger) but in the 1st row of this table there are 2 different values (column 1=0, column 2=1). So, which atom should update the row nr 1? As this has apparently not been executed at the moment of evaluation.

Regards, Marlies
Thor
Posts: 12
Joined: Thursday 16 January, 2014 - 15:16

Re: Event OnMessage

Post by Thor »

Hi Marlies,

many thanks for your quick reply! I believe I need to get acustomed to the debugger. Going through step by step I saw what you pointed out. If I see it correctly, the problem is the order of code execution after Unpack39. The product leaving channel 2 triggers the decrease of the value in row one. But this happens only after the code is executed in the "Pick Up Point" Atom which is triggered by the atom leaving channel 1 of Unpack39. So channel 1 beats channel 2 - learned something new...

Thanks for the tip with the debugger!

Is there any advantage/disadvantage of using either "OnEvent" or "OnMessage" to trigger something in a remote atom? I was not sure which way is best to execute code in the atom "Startup Initiation".

Regards
Thorsten
marlies
Posts: 301
Joined: Monday 17 January, 2011 - 09:28

Re: Event OnMessage

Post by marlies »

Hi Thorsten,

For the unpack atom it is true indeed that atoms leaving via channel 1 (the content of the atom to be unpacked) will leave the atom first and therefore the events for that atomsmay get triggered before the package is leaving.

The difference between OnEvent and OnMessage is that the OnMessage is executed as soon as the message is send/received. For example: in the trigger on entry of the pickup point you could have had some more code after the message command. In that case, sequence of execution would be: send message - execute message code - execute rest of trigger on entry.

When you use CreateEvent an event will be scheduled, but not executed immediately. When you replace the message by an createevent after 0 seconds in the example. Sequence of execution would be: createevent (event will be scheduled) - execute rest of trigger on entry - event will be executed if it is the next on the list. Note that there is a tab Events in the debugger which will show you a list of all the scheduled events.

So, it depends if your code needs to be executed immediately or better after other events have been finished. Immediate execution of code can be achieved using functions as well (see atom function editor).

By the way, if you select the option "create alias" on a table atom the table will create a global reference starting with ref and than the name of your alias (alias Startup will generate the reference refStartup). You can use this global reference instead of all the connections to the atom. So instead of out(2,c) you can use the reference. Just in case you would like to have less channels :-).

Success!

Marlies
Thor
Posts: 12
Joined: Thursday 16 January, 2014 - 15:16

Re: Event OnMessage

Post by Thor »

Hi Marlies,

thanks for the detailed explanation! I now understand a bit more about the different implications of OnEvent and OnMessage.

The reason for the connections via channels and not with global functions is that I will duplicate (or better centuple) the complete setup within the model. Control of the individual packages must remain independent though and I believe that this allows an easier duplication. To achieve this I plan to use the composition container.

Best regards
Thorsten
Post Reply