MATLAB: How to parse XML data sent via UDP in a Simulink Desktop Real-Time application

sldrtudpxml

I would like to read UDP packets sent from a KUKA robot in a Simulink Desktop Real-Time application running at 1kHz.
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, C. How can I parse the XML data from the UDP packets using a Simulink Desktop Real-Time application?

Best Answer

Please 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>'
This is because we are reading 6 double values X, Y, Z, A, B, C, that are placed at the positions marked by %f placeholders.
Please also note the escaped double quotes (preceded by backslash).