Perhaps you have a DLL that you want to access from a Simulink model. Maybe a colleague has developed an algorithm in another language that can be compiled as a shared library, and you want to take advantage of it.
How can you access it from Simulink?
If you're familiar with Simulink, you're probably groaning as the words "S-Function" cross your mind, but there are other options, which can be easier.
Mikhail's entry that describes a variety of methods you can apply to access the functions and variables that are exposed in the shared library from Simulink.
This explanation of shared libraries covers the basics. Shared libraries make for a relatively portable means of sharing functionality between executables. I say relatively because shared libraries are specific to an operating system. On Windows they are DLL-files and Linux they are SO-files.
Your colleague has written some set of functions in C-code used for some other application. If your colleague compiles these functions to be exposed via a DLL, each of you can leverage the functions from your own applications, without needing to share the source code. (Although you generally need to know the interface definitions of the exposed functions)
Mikhail has a very nice document that describes several methods for accessing a shared library from Simulink.
As part of the examples, it also demonstrates how to load a shared library into MATLAB using the LOADLIBRARY function.
And (my favorite) demonstrates how to load a library that was generated from Simulink using Embedded Coder.
Yes, search "loadlibrary" on the MATLAB File Exchange to give you an idea of how people might use this type of capability.
To start, this entry is well formed and well documented.
Also for me, coming across this entry is very timely. I have been working on some projects that involve deploying Simulink models as MEX-files. Notice that you can generate a DLL from Simulink, and then load that DLL into MATLAB. I have used that very method, but instead of using LOADLIBRARY, I call the DLL from a MEX-file that has been compiled for MATLAB.
- Do you need to access shared libraries from your Simulink model?
- Do you want access to simulations exported from other tools?
- Should C-code generation support calling a function in a DLL?
- Is it useful to call Simulink models as a MEX-function?
Let us know here.
要发表评论，请点击 此处 登录到您的 MathWorks 帐户或创建一个新帐户。