2015-10-30 166 views
0

我想從一個Simulink模型(實時運行)發送數據到一個Python腳本(也是實時運行的,我使用的是Simulink內置的「UDP Send」模塊,它工作原理。如果SIMULINK發送一個常數 「10」,我得到的(10.0)。但我想10,因爲它是。通過udp從simulink塊接收數據

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 

回答

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] 
輸出