Reading data from Simulink into Python over UDP -


i want send data simulink model (running in real time) python script (also running in real time. using simulink's built-in "udp send" block, works, don't know how decode data i'm getting. python script looks like:

import sys, struct 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 data stream should double, while it's giving me numbers aren't meaningful:

  • if simulink sends constant "1", output of "3.16e-322"

  • if simulink sends constant "2", output of "3.038e-319"

any ideas?

turns out network reversing packet bits. solution read in bit-reversed:

data = struct.unpack('!d',data) 

i have no clue why happens on networks , not others. can comment on way tell if need use bit-reversal?


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -