Simulink UDP does not work, but Matlab code does
2 views (last 30 days)
Show older comments
Hi! I can get a piece of code to run in my Matlab script, but not when I use the corresponding Simulink block.
I am using UDP as a way of piping live streams from Simulink to python (Blender, 3D software) In matlab I am simply using
u = udp(host,port);
fopen(u);
fwrite(u, data, 'double');
fclose(u)
and I am sending a simple array of numbers. This comes through nicely. However, using Simulink 'UDP Send', I get the wrong numbers (instead of 3.14 i get something to the power of negative 300, etc.). My first thought is that this is owing to a different data type being used, but there is no way to set 'double' in the Simulink block, and it is my understanding that Simulink uses 'double' as its standard data type anyway.
Is there a way to change the data type, or could my problem lie somewhere else?
The Python end of the solution looks like
data = self.request[0]
socket = self.request[1]
numOfValues = int(len(data) / 8)
info=struct.unpack('>' + 'd' * numOfValues, data)
0 Comments
Answers (2)
Gao Yang
on 5 Feb 2020
Hello,sir! I met the same problem. I code the UDP server code in python. But do you know how to output the data UDP server received to simulink? And how to parse this data in real time in Python's UDP code? Very thanks, I am looking forward to your reply.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!