I am creating a basic simulation with a line of 4 Processors connected with queues. I use javascript code in GUI listening to a WebSocket. Using the incoming message from that socket, I change the parameters of a Processor.
socket.onmessage = function(e) { var data = JSON.parse(e.data); for (var object in data) { for (var type in data[object]) { var val = data[object][type]; fireFlexsimEvent("receiveInput", object, type, String(val)); } } };
Above is a cleaner and simpler version of the function used for handling incoming messages to the socket. Below is an example form of an incoming message.
{ "Processor1": { cycletime: 6 }, "Processor2": { cycletime: 7 } }
Basically, I am iterating all the elements in the JSON object to get the corresponding Processor name and its property to change and update the value of the property of that Processor.
Below is the cleaner and simpler version of the receiveInput Flexscript.
string objName = param(1); string type = param(2); string _value = param(3); double value = _value.toNum(); print("Setting", objName + "." + type, "to", value Model.find(objName + ">variables/" + type).value = value;
I also have an external dashboard to trigger a socket message. Updating property values works generally fine. However, sometimes with no apparent reason, the Processor whose property I want to change stops processing. When this happens, the connection coming into the Processor has a red triangle instead of green on the processor end. All Processors work fine after I reset the simulation. I assumed that it might be because in the for loop in the socket.onmessage function, receiveInput script might be fired a second time before it finishes running for the first time and this might have messed things up but I am not sure and I do not know how to fix it. Please help, any help will be greatly appreciated. Thank you.