Matlab/Simulink Objects in C++ application

1 view (last 30 days)
Vijeesh
Vijeesh on 21 Feb 2012
Hi I'm developing a system where the model will get executed as RTWT kernel and user interaction is through a GUI which is developed using VC. I Could start the model execution through the GUI as specified in the tutorial. But I couldn't get any information on how to send the user inputs to the model and get the outputs from the model to the GUI. I tried with UDP sockets but It buffers the data which results a delay between GUI and model. Is there any other option to interact with the model from a C++ application?. I had done the same thing with GUI developed in MATLAB with event handler call backs. Similar thing can we implement here?
Expecting Reply
Vijeesh T NAL, Bangalore, India

Answers (3)

Kaustubha Govind
Kaustubha Govind on 21 Feb 2012
If you're using a PC-based GUI, you are essentially losing the "real-time" processing that the RTWT kernel provides - is there a reason that you have to use RTWT? Typically RTWT models are interfaced directly with hardware, so most of the driver blocks are associated with supported hardware.
Why not use a regular Embedded Coder (formerly, Real-Time Workshop Embedded Coder) generated shared library (DLL) and call into that from your GUI?
PS: I have no expertise in the RTWT area, but I know that attempting to interface custom drivers with RTWT is not easy, so I won't go so far as to suggest that you implement your own interface.

Vijeesh
Vijeesh on 21 Feb 2012
Hi Ms. Kaustubha
Thanks for your reply. The basic inputs to the model are accessed directly by the RTWT kernel. So I'm not loosing the Real time processing. The GUI provides options like gain tuning and starting and stoping the simulation etc. The second part (starting and stoping simulation) I could do with MatLab Engine APIs.I would like to know anything like event handlers callbacks can be used in C application(Either directly or through MEX file). Is it prossible to create Matlab function as a static(or dynamic) library and link to C++ application?I don't have experience on MEX file.
Thanks Vijeesh T
  1 Comment
Kaustubha Govind
Kaustubha Govind on 22 Feb 2012
Yes, I think you should be able to use the MATLAB Engine API so that MATLAB is started as a COM server - you can then write MATLAB functions that use the Simulink command-line API to control your model (http://www.mathworks.com/support/tech-notes/1900/1903.html). You simply need to execute the appropriate MATLAB function using engEvalString when an event occurs on your GUI.

Sign in to comment.


Vijeesh
Vijeesh on 22 Feb 2012
Hi I have one more doubt. If I call any function using angine API(engEvalString), the output doesn't show on the command window. I can capture the output to buffer but I want the outputs to be shown in the command window. Is it possible?
Thanks Vijeesh
  1 Comment
Kaustubha Govind
Kaustubha Govind on 22 Feb 2012
As far as I know, the output of statements like disp are displayed in the MATLAB COM Server. The server can be made visible by setting the 'Visible' property of the COM object to true. The COM object itself is not exposed through the Engine API, so might want to use the COM API directly to start and interface with the MATLAB COM Server.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!