Export a Simulink model with an FMU interface

I have to create an FMU interface to export a Simulink model. I've downloaded the software from the website https://www.fmi-standard.org/downloads. It requires the xml file and the C-source of the simulink model. When I run the software to create the FMU the error message is
"simstruc.h<285> : fatal error C1189: #error : Unrecognized use"
I've created the xml file using the command "savesystem" in MATLAB. For the C file I've used the target rsim because I used a variable integration step.
MATLAB version used R2011b.
Thanks a lot. Alessandro.

Réponses (1)

Kaustubha Govind
Kaustubha Govind le 16 Oct 2012

0 votes

It looks like you may have non-inlined S-functions in your model that the build is unable to handle. What is the System Target File selected in the Configuration Parameters>Code Generation pane?

14 commentaires

Alessandro
Alessandro le 16 Oct 2012
Modifié(e) : Alessandro le 16 Oct 2012
Hi! Thank you so much. I selected first the "rsim.tlc" because I used a variable integration step, then I selected "grt.tlc" (description: create visual C/C++ Solution file for "grt" target) because I obtained the same results with a fixed integration step during the simulation; the error message is the same..I don't know if could be helpful, but I use windows 7 and I have installed visual studio 2010.
Could you enable verbose build and see if you can get a more detailed error message with grt.tlc?
Alessandro
Alessandro le 26 Oct 2012
Hi again. This option was already enabled before generating the C code..The model is a simple mass-spring-damper system, I created all just using simulink blocks (a pulse generator for the input, some blocks to save the output data as variables in the workspace, some blocks to create graphics and load data input, some integrators and a subsystem to create the acceleration), so I do not realize to figure out why it does not work..
What is the C/C++ compiler command being use?
Following the instruction given with the FMU package, I open the cmd window, then I use the syntax "build_fmu me sistMCK", where build fmu open a .bat file, me is a blank file given with the package, and sistMCK is the name of my folder I've created with the xml file, the C code and the other Matlab files. The syntax of the .bat file is this one:
@echo off
rem ------------------------------------------------------------
rem This batch builds an FMU of the FMU SDK
rem Usage: build_fmu (me|cs) < fmu_dir_name >
rem (c) 2011 QTronic GmbH
rem ------------------------------------------------------------
echo -----------------------------------------------------------
if %1==cs (^
echo building FMU %2 - FMI for Co-Simulation 1.0) else ^
echo building FMU %2 - FMI for Model Exchange 1.0
rem save env variable settings
set PREV_PATH=%PATH%
if defined INCLUDE set PREV_INCLUDE=%INLUDE%
if defined LIB set PREV_LIB=%LIB%
if defined LIBPATH set PREV_LIBPATH=%LIBPATH%
rem setup the compiler
if defined VS100COMNTOOLS (call "%VS100COMNTOOLS%\vsvars32.bat") else ^
if defined VS90COMNTOOLS (call "%VS90COMNTOOLS%\vsvars32.bat") else ^
if defined VS80COMNTOOLS (call "%VS80COMNTOOLS%\vsvars32.bat") else ^
goto noCompiler
rem create the %2.dll in the temp dir
if not exist temp mkdir temp
pushd temp
if exist *.dll del /Q *.dll
rem /wd4090 disables warnings about different 'const' qualifiers
if %1==cs (set FMI_DIR=co_simulation) else set FMI_DIR=model_exchange
if %1==cs (set DEF=/DFMI_COSIMULATION) else set DEF=
cl /LD /wd4090 /nologo %DEF% ..\%2\%2.c /I ..\. /I ..\..\%FMI_DIR%\include
if not exist %2.dll goto compileError
rem create FMU dir structure with root 'fmu'
set BIN_DIR=fmu\binaries\win32
set SRC_DIR=fmu\sources
set DOC_DIR=fmu\documentation
if not exist %BIN_DIR% mkdir %BIN_DIR%
if not exist %SRC_DIR% mkdir %SRC_DIR%
if not exist %DOC_DIR% mkdir %DOC_DIR%
move /Y %2.dll %BIN_DIR%
if exist ..\%2\*~ del /Q ..\%2\*~
copy ..\%2\%2.c %SRC_DIR%
type ..\%2\modelDescription.xml ..\%1.xml > fmu\modelDescription.xml
copy ..\%2\model.png fmu
copy ..\fmuTemplate.c %SRC_DIR%
copy ..\fmuTemplate.h %SRC_DIR%
copy ..\%2\*.html %DOC_DIR%
copy ..\%2\*.png %DOC_DIR%
del %DOC_DIR%\model.png
rem zip the directory tree and move to fmu directory
cd fmu
set FMU_FILE=..\..\..\..\fmu\%1\%2.fmu
if exist %ZIP_FILE% del %FMU_FILE%
..\..\..\..\bin\7z.exe a -tzip -xr!.svn %FMU_FILE% ^
modelDescription.xml model.png binaries sources documentation
goto cleanup
:noCompiler
echo No Microsoft Visual C compiler found
exit
:compileError
echo build of %2 failed
:cleanup
popd
if exist temp rmdir /S /Q temp
rem undo variable settings performed by vsvars32.bat
set PATH=%PREV_PATH%
if defined PREV_INCLUDE set INCLUDE=%PREV_INLUDE%
if defined PREV_LIB set LIB=%PREV_LIB%
if defined PREV_LIBPATH set LIBPATH=%PREV_LIBPATH%
echo done.
Alessandro: Can we stick to debugging with grt.tlc+MSVC?
Alessandro
Alessandro le 5 Nov 2012
Do you mean using the grt.tlc target and Microsoft Visual C++ instead of Microsoft Visual Studio?
I meant to ask you to try the build without using the "build_fmu me sistMCK" command. Just use the default Simulink Coder build process.
Alessandro
Alessandro le 5 Nov 2012
Ok, I'll try and I'll let you know. Thanks a lot. :)
Alessandro
Alessandro le 15 Nov 2012
Hi again. I've still not found a solution for my problem. Do you have any good idea? The problem is always the simstruc. At the line 220 there is the first of seven "if":
#if defined (RTW_GENERATED_S_FUNCTION)
#elif S_FUNCTION_LEVEL == 1
#elif defined(S_FUNCTION_NAME)
#elif defined(SL_INTERNAL) | | defined(RSIM_WITH_SL_SOLVER)
#elif defined(RT) | | defined(NRT)
#elif defined(FIPXT_SHARED_MODULE)
#elif defined(MATLAB_MEX_FILE)
#else
#endif
it seems that no one of the if condition is read, so it goes directly to the else and to the error...
Alessandro: Are you saying that you are seeing the exact same error using the default Simulink Coder build process (ie. without using a custom command like "build_fmu me sistMCK")?
Alessandro
Alessandro le 15 Nov 2012
No, I used the Simulink Coder build process, but I don't need the "exe" file so I tried to use the custom command again. Can I create the "fmu" file using the simulink coder? Do you suggest this to me?
You probably need to fix the Makefile used with the fmu build process to define the right symbol. I would recommend looking at the default Makefile generated by Simulink Coder. In particular look for the symbols used in the seven #ifs that you posted to find which of those you need to define at compilation.
Is there already a solution available for this issue ? Thanks Sathish

Connectez-vous pour commenter.

Catégories

En savoir plus sur Simulink Coder dans Centre d'aide et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by