MATLAB Answers

0

Can be imported a .dll file to Simulink?

Asked by Alexandru on 20 Sep 2012
Hello,
I'm having some questions and hope to find some answears/tips here. Any advice is appreciated.
I have a model in Simulink that contains a Library, I've generated C Code out of the model and now I'm trying to complile the generated C Code with headers and other files into a .dll file with a gcc compiler.
My problem is how to include/import the .dll file back in Simulink, and is it possible to import the .dll inside a block (an S-Function for example) having all the inputs and outputs of the original library?
Thanks, Alex

  0 Comments

Sign in to comment.

1 Answer

Answer by Kaustubha Govind on 20 Sep 2012

Technically you should be able to bring any generic DLL into Simulink via an S-function block, but I'm not completely confident that you won't have any issues doing so with a Simulink Coder generated DLL. You will mostly likely be able to get this done for normal mode simulation, but I'm afraid that there might be multiple definitions of types that will clash when you generate code from the model and use the S-function in non-inlined mode. Essentially, you might see a file called rtwtypes.h created with the DLL - a header will the same name is produced when generating code from any model. The trouble is that rtwtypes.h contains generic platform-independent types, but may also include user-defined types, fixed-point types, etc. So you might need to combine the 2 rtwtypes.h files. (Please take my advice with a grain of salt because I haven't tried this myself - this is mostly speculation)
Is there a reason why you can't simply generate an S-function from the first model and use the generated S-function in the second model?

  2 Comments

The reason is that when I'm creating the .dll file I'm adding some headers to be compiled also with the generated code from matlab. And I don't know if it is possible to include the headers before compiling the model and generate C Code.
If you have an example of adding a .DLL into Simulink via a S-Function, I would appreciate.
Alexandru: You will need to specify build rules in the Simulation Target>Custom Code pane for model compilation or simulation, and check the Use the same custom code settings as Simulation Target in the Code Generation>Custom Code pane for the same settings to be applied for code generation.

Sign in to comment.