MATLAB Answers

0

Can I call a Simulink generated DLL file in a Simulink model (Matlab 2018b)?

Asked by Panagiotis Bountouris on 14 Apr 2019
Latest activity Commented on by Panagiotis Bountouris on 23 Apr 2019
I have created a .dll file (see fig: PID_win64.dll) and associated headers (see fig: in PID_ert_shrlib_rtw) with the aid of Simulink (see fig: PID.slx). I now want to call it in a simulink model (see fig: test_dll.slx) where I am going to test it. I have read in older posts that I have to use S-Function block. Please let me know if this is the proper route I should follow and if so could you please share with me the exact steps (where should I allocate the name of dll and headers - which headers) ?
The final aim is to import the created .dll file in DIgSILENT POWERFACTORY. If anyone can share any further information regarding this would be highly appreciated.

  0 Comments

Sign in to comment.

1 Answer

Answer by Mark McBroom on 15 Apr 2019

Yes, creating an S-Function one possible approach. I presonally prefer the legacy_code tool, but S-Function builder will also work.
Note that you can also call C code in a DLL from a MATLAB Function block using the coder.ceval() function.

  3 Comments

Thank you for your answer Mark. Are there any specific guidelines when using the above to import a dll?
No particular guidelines. There are a number of examples for each approach. Tricky part for either is specifying the layout of input/output buses to the Simulink model.
An altnerate appraoch is to put your entire model into a sub-system. Then, select the subsystem and pick the following from the Simulink menu:
Code => C/C++ code => Generate S-Function
This will generate an S-Function from the subsystem. You can now use this s-function in another Simulink model.
Finally, if your goal of creating an s-function is to hide the implementation details of the model before providing to someone else, you can use the Protected Model feature.
Thank you Mark. The ultimate goal is to import the already generated dll to digsilent (another simulations program). Before that I wanted to import the dll in simulink, so I compare the dll with the actual model. I don't think creating an S-Function out of the initial model will help me at this stage. Correct me if I am wrong. Thank you for your help anyway!

Sign in to comment.