No BSD License  

4.88889

4.9 | 9 ratings Rate this file 81 Downloads (last 30 days) File Size: 67.8 KB File ID: #9709

From Simulink to DLL - A tutorial

by

 

20 Jan 2006 (Updated )

Describes how to build a DLL or shared library from a Simulink model.

| Watch this File

File Information
Description

This document attempts to give a hands-on description on how to make a DLL from a controller built in Simulink. This makes it possible to develop advanced controllers in Simulink, and then use them from an arbitrary application. Persons with knowledge in the C programming language should have no problems converting the steps in this tutorial to build Linux/Unix libraries, thus expanding the scope of this document to be applicable not only on Windows.

Required Products Simulink Coder
Simulink
MATLAB release MATLAB 7 (R14)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (19)
07 Jul 2014 G

need some help

18 Sep 2012 Xiongzhe

I have an applicatoin:

generate DLL from a simulink model, DLL is called in an external c program, when DLL initializes, it will load mat file and variables in m files.

can i change the m files without recompile the DLL?

26 Apr 2012 Lakshmi Narayanan

Need some help on this.

When I have generated the code and update the grt_shell.c file for inputs and outputs I tried to build the DLL as mentioned in the section 4.6. when I execute the command gmake –f ($NAMEOFMODEL).mk I am getting an error “:128: *** missing separator. Stop.”.
I understand that this is caused due to the use of space in place of tabs. But as you might know the .mk file is generated by the RTW. I checked the line 128 in the .mk file and it has no space at all.

Any suggestions would be much appreciated.

26 Apr 2012 Venkatakrishna Moorthy

We are getting the error ' NMAKE : fatal error U1073: don't know how to make 'cn_main.ofile'
Stop.
The make command returned an error of 2
'An_error_occurred_during_the_call_to_make' is not recognized as an internal or external command,
operable program or batch file.

This is appeared when we try to build the CANoe supported model. We are trying to interface Matlab into CANoe using the dll generated by the Matlab. But dll is not generated. Can anybody have a answer, please let us know.

23 Mar 2011 Imran

i can follow till 5th step of 4.6
than gmake gives me this out put
C:\123\add1_grt_rtw>gmake -f add1.mk
C:/PROGRA~1/MATLAB/R2008b\sys\lcc\bin\lcclnk -s -LC:/PROGRA~1/MATLAB/R2008b\sys\
lcc\lib -o ../add1.exe add1.obj add1_data.obj rtGetInf.obj rtGetNaN.obj rt_log
ging.obj rt_nonfinite.obj grt_main.obj rt_sim.obj @add1_ref.rsp
*** Created executable: add1.exe

this donot match with step 4.6 - 6 so what am i doing wrong?
please help i need it real bad and real fast
i am using make 3.81 compiler

19 Jan 2011 Siti khadijah ismail

hii.. i cannot create dll. the error shows that
""you must define MSDevDir"
does anyone know about this?

15 Dec 2010 Gianni  
15 Dec 2010 Gianni

hi everybody.
I have a problem. when I attemp to use gmake -f ($NAMEMODEL).mk I receive this error:
??? Undefined function or method 'gmake' for input arguments of type 'char'.
if I use the command :
!gmake -f ($NAMEMODEL).mk
it works but I can not see what gmake is dooing, the only output is :
>> !gmake -f controller.mk
gmake: `../controller.exe' is up to date.

can someone explain me hot to solve this problem? or please send me the code that I need to continue?
Many thanks,
Gian

27 Sep 2010 Nick Clark

Good stuff here. Thanks! I'd just like to add a little bit. For those who don't know pascal, please see the python script pasted below. This can be used to test your dll. This specific example is for 3xinput and 2xoutput:

from ctypes import *

# first make some hooks into the impported functions
initiateController = cdll.controller._initiateController
getControllerOutput = cdll.controller._getControllerOutput
performCleanup = cdll.controller._performCleanup

# This makes python realise that the function outputs are pointers to c_chars
initiateController.restype = c_char_p
getControllerOutput.restype = c_char_p
performCleanup.restype = c_char_p

print "\n\nInitiate"
errMsg = initiateController()
print "initiateController reports : ", errMsg

print "\n\nNow to do some stuff"
inputDoubles = 3*c_double
inputData = inputDoubles(2.5, 3.0, 1.0)
p_inputData = pointer(inputData)

outputDoubles = 2*c_double
outputData = outputDoubles(0.0, 0.0)
p_outputData = pointer(outputData)

#The following line shows two different methods for passing the pointers in
errMsg = getControllerOutput(c_int(3), p_inputData, c_int(2), byref(outputData) )
print "getControllerOutput reports : ", errMsg
print "output[0] = ", outputData[0], "\noutput[1] = ", outputData[1]

print "\n\nCleanup"
errMsg = performCleanup()
print "performCleanup reports : ", errMsg

25 Aug 2010 mohammed Hanneef

Nice information, thank you

15 Oct 2009 Patrick

I had a similar error to Dennis from a project I was compiling and linking into a project here at work. Turns out I hadn't set up the Configuration Parameters correctly (Tools -> Real Time Workshop -> Options). After I had set these up appropriately the error went away.

23 Aug 2008 Dennis Jimmy

Hello Roland Pfeiffer,
Thanks the document "from simulink model to dll",It is very helpful to me.

but there is some error.

when I construct a project in vc2005, the simulink model dll is call in a simple main function.

when I build it , the error is happen; the error is

simstruc.h(282) : fatal error C1189: #error : Unrecognized use.

15 Jun 2008 liu hz  
19 Mar 2008 Rajan R

Dennis Wouters,
I am new to matlab and RTWEC, I am not able to find the custom target example. can you please guide / share the information.

24 Apr 2007 Dennis Wouters

This document really kick-started my work. Thanks.
I ended up developing a more general approach that requires only a little more programming.

* Derive a custom TLC from the grt.tlc file using the "Custom Target" example in the RTW Embedded Coder documentation, which does NOT require RTWEC, only RTW. (This is easy.)
* Derive a custom TMF from the grt_lcc.tmf file. Make the changes proposed in the RTWEC example as well as the changes that Roland proposes to make to the 'lcc' and 'lcclnk' command line options. (Not too hard, you only need to change 2 or 3 lines.)
* Finally derive a C file as described by Roland. (This is the most work, but is outlined very well in the article.)

This will give you the opportunity to configure the model to build directly to a DLL without any manual intervention!

Happy DLL'ing!

19 Mar 2007 Diego Barragán

Good!

10 Oct 2006 Jaspreet kaur

I want to use matlab program in VB

20 Jul 2006 Scott Reeder

Very good tutorial. I would recommend adding RTW to the keywords for this tutorial.

17 Mar 2006 Stefan Lindhuber

Excellent step-by-step tutorial. It helped me to save a lot of time.

Contact us