Effacer les filtres
Effacer les filtres

Running a simulink model from python script using TCP/IP

4 vues (au cours des 30 derniers jours)
Soumil Chugh
Soumil Chugh le 17 Juin 2019
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.

Réponses (0)

Catégories

En savoir plus sur Call MATLAB from Python dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by