question

Thomas Q2 avatar image
0 Likes"
Thomas Q2 asked Kavika F commented

Problem with Flexsimpy controller.send() function

Hello,

I tried to replace the line "value = controller.receive();" of the TestFlexSimPy.py file (part TestSendReceive) to send to Flexsim a number, but Flexsim seems to not receive it. When I try to read the value it always appears as 0 (TestFlexSimPy.py).

I tried to send a value to Flexsim and put it into the performance measure (since controller.receive() doesn’t work but getPerformanceMeasure() work well) and read the performance measure but whatever number I sent it always return 0. I have attached the Flexsim file of this experiment (test1.fsm).

What is the proper method to send data to Flexsim via the controller.send() function, to be able to send int, float, string or even array? cmd-testflexsimpymodified.pngpythoncode-testflexsimpymodified.png

FlexSim 22.1.2
flexsimpy
· 2
5 |100000

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

Kavika F avatar image Kavika F ♦ commented ·

Hi @Thomas Q2, was my answer helpful? If so, please click the "Accept" button at the bottom of their answer. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always unaccept and comment back to reopen your question.

0 Likes 0 ·

1 Answer

Kavika F avatar image
0 Likes"
Kavika F answered

Hey @Thomas Q2, I've found the root of your problem in this question and the other one you posted.

There are some conflicts going on between Python and FlexSim when certain triggers happen. First, in the code you would call, you would call "controller.reset()", which would trigger the "OnModelReset" event in FlexSim. You had custom code for that trigger that would send FlexSim into a receiving state, waiting for python to send a response; however, python was waiting for the "OK" from FlexSim that it had finished resetting, so you get this loop of both processes waiting for each other.

The same thing happens when you call "controller.stop()" in python and in the model you have custom code for "OnRunStop" that calls receive, sending both processes into an infinite loop. If you remove your custom code, you're able to run the code smoothly and change the sending value to whatever you want and you'll receive that value (like you have set up).

(Don't worry about the asterisks; they have no bearing on the code and will be fixed within a future version of FlexSim)

1655330248660.png

When making your model and python code, be careful not to make them wait for each other or to write custom code on reset and stop that sends it into a waiting state.


TestFlexSimPy.py

test1.fsm


1655330248660.png (11.6 KiB)
testflexsimpy.py (1.7 KiB)
test1.fsm (60.0 KiB)
5 |100000

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