Use a DLL in Simulink

13 views (last 30 days)
rents85
rents85 on 5 Sep 2012
Hi to all,
i've created a DLL in C# language and i want to use it in simulink.
I'm able to use in Matlab command line:
dllPath = fullfile('c:','OwnProtocol2.dll');
NET.addAssembly(dllPath);
OwnProtocol2.sendsMeasures.writeInt()
How can i do this in Simulink?
The version of Matlab is 2010b

Accepted Answer

Ryan G
Ryan G on 5 Sep 2012
Edited: Ryan G on 5 Sep 2012
You can use a s-function to call the DLL. To do this you would need a header file describing the functions inside the DLL so the s-function knows how to call the functions inside the code. I'm not overly familiar with C# so I'm not sure how easy this will be but I am sure it is doable.
After you write the code just make sure to include the DLL in the mex line.
For example
mex mysfun.c myDLL.dll
  2 Comments
rents85
rents85 on 5 Sep 2012
Edited: rents85 on 5 Sep 2012
Doesn't exist header file in C#...
Kaustubha Govind
Kaustubha Govind on 5 Sep 2012
Not sure if you can link .NET assemblies directly against C-MEX S-functions (or any generic DLLs for that matter), but if you know how to invoke .NET assemblies from generic C/C++ DLLs, you can follow the same technique for C S-functions. Alternately, it might be easier to continue using your MATLAB code to call into the assembly. You can call MATLAB code from Simulink using the Interpreted MATLAB Function block or MATLAB S-Functions.

Sign in to comment.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!