How do I use Stream Input block to parse ASCII encoded data received via UDP, TCP or Serial with Simulink Desktop Real-Time?

5 views (last 30 days)
I would like to read UDP packets sent from a KUKA robot in a Simulink Desktop Real-Time (SLDRT) application.
The UDP packets include 120 Byte ASCII encoded data in XML format containing position information of the robot, e.g.:
<Rob Type="KUKA"><RIst X="-18.3" Y="260.3" Z="25.0" A="18.6" B="1.4" C="-1.1"/><Delay D="0"/><IPOC>9420422</IPOC></Rob>
My aim is to process the values for X, Y, Z, A, B, and C. How can I parse the XML data from the UDP packets in a Simulink Desktop Real-Time application?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 13 Nov 2025 at 0:00
Edited: MathWorks Support Team on 13 Nov 2025 at 10:20
Use a Stream Input block from the Simulink Desktop Real-Time library with the following settings:
  • Block output data types: 
    '6*double'
  • Format string:
    '<Rob Type=\"KUKA\"><RIst X=\"%f\" Y=\"%f\" Z=\"%f\" A=\"%f\" B=\"%f\" C=\"%f\"/>'
  • Message termination:
    '</Rob>'
In this way, we can read 6 double values X, Y, Z, A, B, and C, that are placed at the positions marked by %f placeholders. Note the escaped double quotes (preceded by a backslash).

More Answers (0)

Community Treasure Hunt

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

Start Hunting!