I am new to Matlab and trying to code a winform based GUI for a simulink model in C#. But i had issue about how to communicate them efficiently.
2 different ways i tried:
1) I tried is COM communication between C# to matlab but after loading model, it was frozen.
C# script for communicating matlab over COM:
MLApp.MLApp matlab = new MLApp.MLApp();matlab.Visible = 0;matlab.Execute(@"cd('path to model')");matlab.Execute("model");matlab.Execute("set_param('model','SimulationCommand','start')");
It looks like a buffer overflow to me but I couldn't find any resources on the subject.
How can i prevent freezing?
2) I tried to communicate c# and matlab to control simulink model using udp protocol. I coded a matlab script to be bridge. However, i realized that i need to create more than one thread that will communicate with each other. Eventhough i used parellel computing toolbox in matlab, i can not accomplish it.
matlab script :
u = udp('', 'LocalHost', '127.0.0.1', 'LocalPort', 49013);fopen(u);while(true) command = fread(u); if(command == 1) %start model
set_param('model','SimulationCommand','start') elseif(command == 3) %pause model
set_param('model','SimulationCommand','pause') . . . else(command == 4) %stop model
set_param('model','SimulationCommand','pause') endend
Is there a way to communicate threads each other in matlab?
Any suggestion would be nice.
Best Answer