question

Bo.W avatar image
0 Likes"
Bo.W asked Jason Lightfoot edited

Listen for a trigger and override the return value with code

HI,@Phil BoBo

Is there a method to use Code-monitoring-mechanism to listen for a trigger with a return value (such as sendtoport), and use a value to override the return value of the trigger. The current development environment is not suitable for PF. I know that PF can be realized by using the return value of FINISH activity of subflow.

For example, I want to override the return value of the Queue1's sendtoport trigger with the variable q1s2pCode's execution result in the Plane1.

Listen for a trigger and override the return value with code.fsm

FlexSim 21.0.2
flexsim 21.0.2event listeningoverride return value
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
4 Likes"
Phil BoBo answered Bo.W edited

You can use the listenerinfo() command to override the return value. (This isn't documented anywhere, but it works.)

See the attached example model. listen-for-a-trigger-and-override-the-return-value_autosave_1.fsm

Setting up the listening with eventlisten():

Object queue1 = Model.find("Queue1");
treenode q1send2port = getvarnode( queue1, "sendtoport");
Object Plane1 = Model.find("Plane1");
treenode q1s2pCode = getvarnode( Plane1, "q1s2pCode");
eventlisten(queue1, "SendToPort", q1s2pCode, EVENT_LISTEN|EVENT_PERSIST|EVENT_PASS_THROUGH_PARAMS);

In your listener relayNode, using listenerinfo() to override the return value:

Object item = param(1);
double returnVal = item.Type?;
#define LISTENER_INFO_OVERRIDE_RETURN_VALUE 4
listenerinfo(LISTENER_INFO_OVERRIDE_RETURN_VALUE, up(i), returnVal);

Also, as documented in the eventlisten() command, you can use function_s(obj, "enumerateEvents", node) to list the events that an object has in order to know what string to pass for a certain event and to know what parameters you have access to:


· 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.

Bo.W avatar image Bo.W commented ·

Thank you very much. This is really helpful to me.Your reply is very accurate and clear.

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.