Real Time Simulation Simulink with other engine (TCP connection)

Hello,
since Matlab R2020b there is the possibility to configure a TCP server in Simulink.
-> It is possible to send with a TCPServer (implemented in SimuLink) XML-messages (strings) to a other engine (Unity) ?
I have seen, that there are additional blocks like the "Send TCP packets". I have tried different approaches but nothing worked. The TCP Server recognize the connection to the TCP client (the unity engine). The matlab documentation is not very detailed. Furthermore there is written, that the client must be a matlab client....
Kind regards,
Miri
(I want to implement a stateflow controller for a elevator simulation, Transmission protocol is TCP, the exchange of data between engine(unity) and controller(Simulink) should be handled via xml.)

Answers (1)

Hi Miriam,
I see you are trying to send an xml-formatted string with a TPCSend block in Simulink. The TCP/IP Send blocks do not support strings inputs directly. This MATLAB Answer might help you to implement what you need.
Assuming that you are working with Simulink Real-Time, I modified the example in MATLAB Answer to run on a Speedgoat target for R2020b. I attached models 'TCPTargetSendString.slx' and 'TCPHostClientRcv.slx'. The first model is meant to run on a target and sent a basic xml-formatted string, the second model can run on the host similarly to your Unity. You just need to change the IP addresses accordingly to your network configuration.
Some useful references to the documentation: Simulink Strings, TCP Send block.
Regards,
Roberto

Asked:

on 27 Apr 2021

Answered:

on 25 Jun 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!