Running a simulink model from python script using TCP/IP

5 views (last 30 days)
import socket, struct
import matlab.engine
import os
eng = matlab.engine.start_matlab()
TCP_IP = 'localhost'
TCP_PORT = 30001
BUFFER_SIZE = 1024
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((TCP_IP, TCP_PORT))
print('Waiting for Simulink to start')
s.listen()
print("Waiting for connection")
-------------------------Stops at this point--------------------------------------------------------------
eng.sim('TCP')
conn, addr = s.accept()
print("Connection Accpeted")
print('Connection address: ', addr)
for i in range(51):
msg1 = struct.pack('>d', i)
conn.send(msg1)
print('sent data:', i)
data = conn.recv(BUFFER_SIZE)
print(data)
conn.close()
I am trying to run a simulink model which sends and receives data from python. The connection fails when I run the model through python scipt. Can anyone help me with the same.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!