How can I output the Simulink Model Version in model_initialize c function?

12 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Chidvi Modala
Chidvi Modala el 29 de Oct. de 2020
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.
  2 comentarios
Michael Frena
Michael Frena el 3 de Nov. de 2020
In fact to output the model version I added the following function call to the tlc file:
%openfile tmpBuf
modelVersion = 0b%<FEVAL("getVersionInfo")>;
%closefile tmpBuf
%<LibSetSourceFileSection(modelC,"Declarations",tmpBuf)>
I defined the getVersionInfo m-function like this:
function verOut = getVersionInfo()
verIn = get_param(gcs, 'ModelVersion');
VersionInfo = strsplit(verIn, '.');
major = bitshift(str2num(VersionInfo{1}),12,'uint16');
minor = uint16(str2num(VersionInfo{2}));
verOut = dec2bin(major + minor);
end

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Event Functions en Help Center y File Exchange.

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by