MATLAB: How to output the Simulink Model Version in model_initialize c function

code generationinitializematlab codermodel versionsimulinksimulink coder

Hi,
I am trying to ouput the model version information in the generated c code. Preferable would be to have it generated in the model_initialze function.
But curretly I am facing the problem that both commands to retrieve the model version information are not usable with the ert code generator:
1) info = Simulink.MDLInfo('mymodel') % works only in releases after R2009b
2) modelVer = get_param(modelname, 'versionLoaded')
Whats the best way to get the version info into the code?
Thanks
Michael

Best Answer

You may follow these steps to include MATLAB version, Subversion revision number, and code generation settings in auto-generated code from Simulink models.
  • In that custom section, add a comment block with the information which you want to include in the auto-generated code.
  • For MATLAB version you can use the following code.
%openfile tmpBuf
/*
MATLAB Version : %<FEVAL("version", "-release")>
*/
%closefile tmpBuf
%<LibAddSourceFileCustomSection(modelC,"Includes","Myincludes")>
%<LibSetSourceFileCustomSection(modelC,"Myincludes",tmpBuf)>
Which resulted in this:
/*
MATLAB Version : 2015a
*/
  • The SVN revision is a little trickier. There is no direct way to access the revision from the command line, so the SVN command line needs to be used instead.
>> !svn info -r HEAD [[filename]]
Path: [[filename]]
Name: [[filename]]
URL:
Repository Root:
Repository UUID:
Revision: 1059 <----Revision number!
Node Kind: file
Last Changed Author:
Last Changed Rev:
Last Changed Date:
  • Note the presence of the revision number. You can use the FEVAL command in TLC to execute an m-function to call the SVN command and parse out the revision number.
  • Alternatively, you can also use the following command to return the data in an XML format which will be easier to parse through.
>> !svn info -r HEAD [[Filename]] --xml
  • To include code generation settings, you can use FEVEL command in TLC to execute an m-function which will have many "get_param" calls to obtain all the code generation parameters of your interest. To know the parameter name, simply right-click and click "What's this?" on the parameters in the "Code Generation" pane of "Model Configuration Parameters". A window will appear with all details of that parameter.