I am trying to control my Simulink model through an S7 1200 PLC. The idea is to send the process value from the model to the PLC and send a corresposding control variable from PLC to the simulink model.
The TIA Portal only has TCP/IP client block, and the instrument Control Toolbox of Matlab also has TCP client send/receive blocks. So I decided to write my own function to make a TCPIP server on Matlab. The code is quite simple but the problem is that the connection gets destroyed once the fucntion block is executed. This makes my simulation run very slow (1 second is simulated in 8 seconds).
t = tcpip('0.0.0.0', 2000, 'NetworkRole', 'server');fopen(t);
Is there a way to make the connection to the PLC once and then reuse that connection throughout the simulation?
I have spent a lot of time trying to find a solution but no success yet. The Modbus object won't even run inside the custom function. UDP also needs to connect every time so I am out of options here. Is there anyone that can help me please.