question

Asif A avatar image
0 Likes"
Asif A asked Joshua S commented

writing a code for interaction with model

i m trying to interact with the simulation model. if i m using the method of sending a request to http address. how can i get one http server that i can use in codes

FlexSim 19.1.0
interactionwriting code
· 5
5 |100000

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

Benjamin W2 avatar image Benjamin W2 commented ·

Hi @Asif A, I am having difficulties understanding what you are asking.

  1. Could you clarify what you mean by "sending a request to http address" and "get one http server that i can use in codes"?
  2. I also think it would be helpful if you can describe what you are trying to accomplish.
  3. Additionally, it would be helpful if you attached a copy of your model.

Until then, here is the documentation on the FlexSim webserver that might be helpful:

https://docs.flexsim.com/en/19.1/Reference/DeveloperAdvancedUser/Webserver/

0 Likes 0 ·
Asif A avatar image Asif A commented ·

hi @Benjamin W2, i m trying to create a model that can get the live feeds from the external signal. by which the model can be updated in the real time. for example in simple model having a breakdown every 100 minutes, using the live feed the when the breakdown takes place the operator can be called to fix it or the model can be told to resume the processing, like wise similar operations can be done by updating the model using the live feed interaction with the help of sockets.

i was able to get the live feed from the external signal. Basically the flexsim works as the server and will accept the connections. then using the external script that works as the client and arguments or text are sent to the flexsim. the flexsim model will then update in the real time and will display the text on the model screen in the real time.

though we were enable to develop the codes for operations related to breakdown or more complex changes. but we were successful to develop a simple live feed interaction using the node.ja and visual studio for the flexsim.

is it possible to use this method or any other method to do so for more complex updates such as resuming the breakdowns in the model? if it is possible then how can it be done. i need some help for codes for operations like breakdown. i have attached the flexsim model and the screen shot of the external node.js code written in visual studio.

tahir-sockets-server.fsm

capture.png

capturekk.png

0 Likes 0 ·
capture.png (149.5 KiB)
capturekk.png (14.5 KiB)
Benjamin W2 avatar image Benjamin W2 Asif A commented ·

@Asif A If I understand you correctly, you have successfully established a live feed between your process and FlexSim. Your question is how to use the input received from your process to change the state of your processors in Flexsim to reflect the actual process. Is that correct?

If so, I would assign the input text to a global variable in your model. Then on some model trigger, I would have your processors evaluate the state of that global variable and change their state accordingly.

Where are you currently storing your input from the socket connection?

0 Likes 0 ·
Asif A avatar image Asif A commented ·

thank u so much @Benjamin W2 .yes its correct, i have established a live feed connection..and my question is how to change the state of the processors for example breakdowns. can u please give little brief explanations. it will b really helpfull for me. may b with en example model..if possible

0 Likes 0 ·
Show more comments

1 Answer

·
Benjamin W2 avatar image
1 Like"
Benjamin W2 answered Joshua S commented

Hi @Asif A,

I think that this code should work, however you will have to test it on your end since I don't have access to your client.

On your Tools tab, click into your recieveOnSocket User command.

I added this code underneath line 18:

	// Add Logic for processor
	if (input == "Down")
	{
		Model.find("Processor1").as(Object).stop(STATE_STOPPED);
	}
	else if (input == "Resume")
	{
		Model.find("Processor1").as(Object).resume(STATE_IDLE);
	}

Note that you will need to change "Down" and "Resume" in the if statements to whatever you are reading from your client.

I hope this helps!

flexsimasserver.fsm


flexsimasserver.fsm (18.3 KiB)
· 6
5 |100000

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

Asif A avatar image Asif A commented ·

Thanks @Benjamin W2, this was really helpful. i had to made few changes, but at last it was working. what i did was added a simple processing line with one source, queue, processor, and a sink. when i ran the script the processor successfully stooped and resumed.

but i had another problem. when i clicked on reset and then on run button for running the model, and then when i clicked on the play button on the script for starting the socket the processing line stopped and the flexsim crashed. so if i want to start and stop the running processing line what changes i can to make or can i use the same code?. similarly if i set the breakdown and the processor stops due to breakdown, can i use the run the same code to resume the processor?

i have attached the working flexsim model. tahir-sockets-server.fsm

0 Likes 0 ·
Joshua S avatar image Joshua S Asif A commented ·

@Asif A

Your current code is built to listen to a single command from another socket, then closes the connection. You even close the connections twice both in the recieveSockets and in endSockets. It is crashing because it is waiting for an input from your client. Do you want the server continuously running and receiving inputs? Also I wouldn't use a global variable for the connectionID. If you hit reset then it will default back to 0 and you don't have anything built in to close any sockets you might have open and this will prevent you from reestablishing a connection. I would do what the original code was doing and use a node to hold that information if a connection was made.

0 Likes 0 ·
Asif A avatar image Asif A commented ·
@Joshua S

yes i wish the server to be continuously running and receive the inputs. what i want to do is run the model and then use the input from the client to start and stop the processor.

so what changes i can make here. can u help me with the replacement code to do so.

0 Likes 0 ·
Joshua S avatar image Joshua S Asif A commented ·

@Asif A

I used the original template and the process flow controls the connections. See if this works for you.

sockets-server-10.fsm

0 Likes 0 ·
Asif A avatar image Asif A commented ·

@Joshua S, @Benjamin W2. i had made this model with that was able to interact with the external signal as mentioned in the above question. it was working fine. it still works but i m facing one problem now. i have tried running it and its working fine but i cant find the custom code written to startSocket, endSocket, recieveOnSocket. to be exact i have forget how to open the custom code window that i had written previously.how to open the custom code for startSocket, endSocket, recieveOnSocket so if i want to edit the codes. can you please help me with this. i have also attached the model. it is the same model mentioned in the above comments.tahir-sockets-server-copy.fsm

0 Likes 0 ·
Joshua S avatar image Joshua S Asif A commented ·

@Asif A

double click the User Commands you created in your toolbox, then hit the script icon to edit the code.

0 Likes 0 ·
pic1.png (42.2 KiB)

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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