How do I receive UDP data in Simulink from programs which can only send strings?

2 vues (au cours des 30 derniers jours)
David H
David H le 17 Nov 2015
Hi all,
I am trying to send numerical data (a double every 0.2 seconds or so) to Simulink from Processing (Java). Processing can only send UDP data as a string and obviously Simulink only deals with numerical data. I have successfully sent/received data between Processing and LabVIEW (which can deal with strings) but have not been able to receive anything in Simulink. I have tried a number of ways to solve this problem including sending data as ASCII strings and as binary strings, but nothing has worked.
Any suggestions would be gratefully accepted!
Thanks!

Réponses (1)

Swastik Sarkar
Swastik Sarkar le 16 Sep 2024
The key issue may be related to how the string is formatted in Java before being sent as a UDP packet to Simulink. Often, the mistake involves sending data like "123.456" instead of "123.456\n" or "123.456\r". The escape sequences at the end of the string signal the end of the message, which helps the receiving block recognize when to stop reading.
When using the Stream Input block in Simulink, the Message Terminator field plays a crucial role. More information about configuring this can be found here:
Alternatively, the Packet Input block in Simulink can be used to handle unformatted binary data and output a formatted string. This method requires specifying the packet size, which corresponds to a fixed number of decimal points. Additional details are available here:
Hope this helps.

Community Treasure Hunt

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

Start Hunting!

Translated by