Running a simulink model from python script using TCP/IP
4 次查看(过去 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 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call Python from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!