Asked • 07/20/19

Reading data from Simulink into Python over UDP?

I want to send data from a Simulink model (running in real time) to a Python script (also running in real time. I am using Simulink's built-in "UDP Send" block, which works, but I don't know how to decode the data I'm getting. This is what my python script looks like: import sys, struct from socket import * SIZE = 1024 # packet size hostName = gethostbyname('0.0.0.0') mySocket = socket( AF_INET, SOCK_DGRAM ) mySocket.bind((hostName,5002)) repeat = True while repeat: (data,addr) = mySocket.recvfrom(SIZE) data = struct.unpack('d',data) print data I've suspected that the data stream should be something like a double, but while it's giving me numbers they aren't meaningful: - If simulink sends a constant "1", I get an output of "3.16e-322" - If Simulink sends a constant "2", I get an output of "3.038e-319" Any ideas?

1 Expert Answer

By:

Julie D. answered • 04/04/25

Tutor
New to Wyzant

Personalized Guidance from Experienced Cybersecurity Specialist

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.