
Julie D. answered 04/04/25
Personalized Guidance from Experienced Cybersecurity Specialist
You're using Simulink's UDP Send block to send a constant (like 1 or 2), and in Python you're using struct.unpack('d', data) — but you're getting weird tiny numbers.
Simulink is likely not packing the data correctly as a double (64-bit float). You're decoding 8 bytes, but those 8 bytes are garbage without proper packing on the Simulink side.
Fix:
In Simulink:
1. Use Data Type Conversion to double
2. Use Byte Pack block:
*Set data type to double
*Set output to uint8
3. Send packed output to UDP Send
In Python:
Make sure you're unpacking exactly 8 bytes:
value = struct.unpack('<d', data[:8])[0] # '<d' = little-endian double