question

Stephane R avatar image
0 Likes"
Stephane R asked Mischa Spelt edited

How to synchronize FlexSim simulation clock with an external service?

I'm looking for pointers, or a previous body of work.

I'm evaluating whether or not I can use FlexSim for parts of a large simulation, while other parts are controlled by a different/legacy simulator. Both simulators are Discrete Event based.

I envision using network calls, to transfer information between the two, but I need some way to synchronize the clocks, or at least limit the amount of drift between the 2.

I don't want to solely rely on speed factor, as I can not guarantee that either simulation can consistently process event at any given rate.

What would be the best way to periodically communicate to an outside process the current FlexSim simulation time; and block/delay FlexSim own event processing until the outside process has confirmed it's own time ?

FlexSim 19.0.2
custom codedllsimulation time
· 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.

Mischa Spelt avatar image
2 Likes"
Mischa Spelt answered Mischa Spelt edited

Hi Stephane,

Mid 2017 we created a multi-threaded Networking module in C++ that is able to handle TCP/IP communication asynchronously - i.e. even when the model is stopped, incoming messages will trigger a response in FlexSim such as a user command getting executed.

We haven't updated the code in a while and FlexSim can only act as a server, not as a client. So getting it up and running would probably require a little bit of effort from our side. If you'd like to discuss the options feel free to contact me through the email address in my profile.

5 |100000

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

Jordan Johnson avatar image
2 Likes"
Jordan Johnson answered Jordan Johnson commented

I don't know of any previous work, but maybe the following would be helpful:

  • You can use commands in FlexSim to communicate over a network:
    • clientconnect(), clientsend(), clientreceive()
  • You can also control the model run using commands:
    • runspeed(), stop(), go()
  • You can a token with executesubflow()

So using these tools, you could probably come up with some way for FlexSim to be driven by another DES package. The way I see it, the other package would be the driving process. When you run that model, you would have it listen for a network connection, and wait till it gets one. You could then run the FlexSim model, which would connect to the other server as its first event.

Once they are connected, you could have the other DES package send a "tick" message with the current simulation time. You could configure the FlexSim model to check for that tick message at the expected time. For example, you could send a tick every 5 model time units from the one package, and have FlexSim try to get that tick every 5 model time units. If FlexSim is ahead, you could set the run speed to very, very slow (making sure to schedule an extra tick check for when to go back to normal). If FlexSim is behind, you could set the run speed higher.

As for transferring other data, FlexSim could check for that during the tick messages, or at other times. It would be completely up to you.

For sending data back, you would probably need to block the other DES package until FlexSim sends the message you are looking for.

If you use the Module SDK, you could write a C++ dll that communicates via websocket, which might simplify communication.

Those are my ideas. I've never done it, and it seems difficult, but possible. As far as I know, you are in new territory. If you come up with a solution, feel free to share it. Good luck!

· 3
5 |100000

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