Running a simulink model from python script using TCP/IP

5 次查看(过去 30 天)
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.

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Call MATLAB from Python 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by