Thursday, November 5, 2015

Receive data from a Simulink's built-in "UDP Send" block in python

 import sys, struct  
import time
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
while repeat:
(data,addr) = mySocket.recvfrom(SIZE)
data = struct.unpack('d',data)
print int(data[0])

3 comments: