通过udp从simulink块接收数据

时间:2015-10-30 14:02:35

标签: udp raspberry-pi simulink

我想将数据从Simulink模型(实时运行)发送到Python脚本(也是实时运行。我使用的是Simulink内置的" UDP Send"阻止如果simulink发送一个常量" 10",我得到(10.0,)的输出。但我想要10个。

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,18726))

repeat = True
if repeat:
    (data,addr) = mySocket.recvfrom(SIZE)
    data = struct.unpack('d',data)
    print data

1 个答案:

答案 0 :(得分:0)

 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,18726))

 repeat = True
 if repeat:
    (data,addr) = mySocket.recvfrom(SIZE)
    data = struct.unpack('d',data)
    print (int)data[0]