Real-time communication between python and Simulink.

14 views (last 30 days)
Narayani
Narayani on 31 Jul 2014
Answered: Yongjian Feng on 20 Nov 2021
I have a script running in Python that reads data from a HID USB device ( logitech driving force gt ). I want to use this data as the input to the Simulink model. Currently, I save the read-data into a .mat file and access it in MATLAB. This is less intuitive and I would want to implement it in such a way that the data read in Python is available to the Simulink model real-time. Is there a way to do it?
  2 Comments
Zhanhao Liang
Zhanhao Liang on 18 Nov 2021
Hi Narayani and Afraz, have you guys already solved this problem and been willing to share?
I also want to get real-time data from/to Simulink to/from Python and just knew i can use the To Workspace block in simulink to send data from Simulink to Matlab then use matlab.engine in Python to get it, but it is just not real time.

Sign in to comment.

Answers (1)

Yongjian Feng
Yongjian Feng on 20 Nov 2021
Interesting. It is an old question but users are still interested in this.
How about this approach? Go through a server. On the python side, run a flask server. It has a thread to read the data. Matlab code pull data periodically from the flask server.

Tags

Community Treasure Hunt

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

Start Hunting!