question

Roger W avatar image
0 Likes"
Roger W asked Roger W commented

will repeat User event make my simulation lag?

I want to control my flexsim model through a custom webpage.
My idea is to have a node respond depending on a SQL database. For example, if the value is 1 in this table, the color of a fixed resource will change color. I do not want this to base off a trigger.

My plan is to set model to check the database through repeating a user-event command. Is this the best way to do it? or are there some method that can allow me to send a flex script from a webpage to the flexsim webserver (read something on job query but that seems very complicated).

FlexSim 17.2.2
user-event
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
2 Likes"
Phil BoBo answered Roger W commented

    Yes, a repeating user event will slow down your model, especially if it is polling a database during each execution.

    It is almost always better and faster to set up a push mechanism rather than a pull mechanism when changes happen.

    Yes, there is a method that can allow you to send a message from a webpage to the FlexSim WebServer to execute a FlexScript function in the running model. It is not that complicated to add custom queries to the server and custom query handlers to a model.

    The attached model (customwebserverexample.fsm), has a customized serverinterface in MODEL:/Tools/serverinterface. It is customized in the following ways:

    The defaultpagetemplate has been modified in two ways:

    Extra Javascript functions have been added on lines 41-55 as an example of how to send custom queries to the server.

    Lines 122-127 have added buttons and inputs for changing the arrival time and cycle time and executing the extra Javascript functions.

    The sendreply handles executing the queryhandlers.

    The queryhandlers have code that set global table values. The cycle and arrival times in the model are set to read those global table values. I did this as an example; you could use whatever Flexscript code you want to modify your model in whatever way you want, such as changing an object's color.

    This model shows how you can (1) customize the model’s default page and (2) write your own custom query handlers.

    (FlexSim 7.5 had a bug where custom model queryhandlers didn’t work unless you had a custom sendreply. This is fixed in FlexSim 7.7 and later, but I created the attached example model so that it works correctly with 7.5.4 and with 7.7 or later. Typically you wouldn’t need a custom sendreply.)

    You may also be interested in the web server technologies discussed in: Is it possible to use the Server Sent Events with the Http interface in FlexSim?


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

    Roger W avatar image Roger W commented ·

    thanks phil for constantly answering my questions, apologies for my lack of knowledge in coding (just started this year). I have looked at the server interface script and I understand there are some JS, buttons and I can customize my flex script there (eg change color of a node). However (sorry if this sounds like a dumb question), how do I access this script from the web? do I run the flexsim webserver and it will pick up this script once I start this instance? Or is this works like a webkit/GUI?

    Thank you for your time, much appreciated

    Roger

    0 Likes 0 ·
    Phil BoBo avatar image Phil BoBo ♦♦ Roger W commented ·

    Sorry. The model I attached was built in a previous version, and the latest updates to the Web Server that enable you to see your dashboards and other views do not play nicely with how it was built. I didn't verify that it still worked with the latest version when I posted it.

    When you connected to the model through the older web server,

    the default page for that model had custom input fields and buttons

    that executed custom query handlers to execute FlexScript that modified the model:

    Attached is a newer version of that model (customwebserverexample-v17.fsm), but with the default interface stripped out so that you can see exactly what is happening and how it works.

    This new example works the same way, but with an even simpler interface that just has the custom input buttons:

    In the model, the node MODEL:/Tools/serverinterface/defaultpagetemplate shows the custom interface HTML and JavaScript code that sends the custom query handlers.

    MODEL:/Tools/serverinterface/queryhandlers has the FlexScript code that is executed when it receives those custom queries.

    The purpose of this model is to show how you can create your own custom query handlers and how you can send those using HTML/JavaScript. The queries are sent through JavaScript input buttons, but you could do the same thing using whatever mechanism you want. If all you wanted was to execute FlexScript code through a button, you could just add a button to a dashboard in the model and then the button would show up on the new interface and you could push it. The point of this example model is how you can have custom queries that are executed however you want, not necessary from the default webserver model view interface.

    1 Like 1 ·
    1.png (86.7 KiB)
    2.png (228.2 KiB)
    3.png (125.6 KiB)
    4.png (118.7 KiB)
    5.png (19.1 KiB)
    6.png (116.8 KiB)
    Roger W avatar image Roger W Phil BoBo ♦♦ commented ·

    @phil.bobo Thanks you for further explanation, I am going to explore your option and see what I can do with the custom interface. Many thanks again

    0 Likes 0 ·