MATLAB: Simulink to a DLL to execute from an Desktop .Net Application

code generationdllreal time workshopsimulinksimulink coderSimulink Desktop Real-Time

Hello Matlabers,
Situation: in the Moment I'm working on an project, with code written in C# and an Simulink model. The C# code can controll a crane. The Simulink model measures the position of the crane. I want to join them to a Control Loop, with a PID controller in the Simulink model. I now working on the Simulink model and want to avoid the investing time in the wrong direction (If this interaction is not possible). Also I need to know which products I need so I can start the process ( 😉 ) of getting them upfront.
My Question is: How can I greate a Dll which I can call from an .Net application. And how to call it from .Net (NOT: How to call an dll in general?). Which are the limitations to the simulink model.
My Results so far: It is posible to generate c and c++ Code form an Simulink Model. The Real-Time Workshop now Simulink Coder makes this possible. But I didn't find something about the interaction between a Simulink model and normal Desktop Application.
Thanks Timo

Best Answer

You can certainly do this with your Simulink model.
Simulink Coder (formerly Real-Time Workshop) allows you to generate C/C++ code from your Simulink model, as you know. Your options from there are
1. Integrate that code directly with your C# application and build them together. This is a common approach. It is fairly easy to get all of the Simulink dependencies using a feature called packngo:
The code generated from the Simulink model provides interface functions such as
<modelName>_initialize()
<modelName>_step()
which allow you to initialize and step through your model. It is then the C# application's responsibility to call them at the correct time.
2. Build the Simulink generated code into a shared library and then have your C# application use the shared library. There seems to be a way to do this but I must confess that I've never done it myself.
Here's a doc link for ya though. It seems to require the Embedded Coder product as well.
Hope this helps!