Problem with Flexsimpy controller.send() function

Problem with Flexsimpy controller.send() function

thomas_q2
Not applicable
97 Views
3 Replies
Message 1 of 4

Problem with Flexsimpy controller.send() function

thomas_q2
Not applicable

[ FlexSim 22.1.2 ]

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

0 Likes
Accepted solutions (1)
98 Views
3 Replies
Replies (3)
Message 2 of 4

joerg_vogel_HsH
Mentor
Mentor
0 Likes
Message 3 of 4

kavika_faleumu
Autodesk
Autodesk
Accepted solution

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

0 Likes
Message 4 of 4

kavika_faleumu
Autodesk
Autodesk

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