Simulink: is there something like a “pre-build” callback function?

23 visualizzazioni (ultimi 30 giorni)
I have a Simulink model, the purpose of which is automated code generation.
My model uses S-functions (developed by another party), some of which have hard-coded assumptions about the path. For instance, several external data files are needed, which are referenced in one of the S-functions via a relative path like so:
..\Bin\data\datafile.bin.
This makes it necessary to set MATLAB's current working directory to a specific path before the model can be run.
I can automatically check and set the correct path via model callback functions. However, all model callback functions only seem to be related to the simulation process, not the build process. That means that I can run the model irrespective of what directory I'm in, but when I try to build the model, it always fails unless I manually navigate MATLAB back to the correct build directory.
Needless to say, that's quite annoying. So I was wondering if there is something like a "preBuildFcn" callback function, a function that is run before starting the build process? Any other solution (that does not involve modifying the S-function) is also very welcome.
My MATLAB/Simulink version is R2010a/7.5. I've already tried using RTW hook files, but when changing the path in the "entry" hook, I get the error:
"Warning: During the 'entry' hook call to 'grt_make_rtw_hook', pwd was changed to <new dir>. Changing directories is not allowed. The pwd will be reset to <previous dir>"
Note also that
FileGenControl
is not available in R2010a.
I've been on a wild goose chase for the past 2 days now, without satisfying results. Is this at all possible in R2010a?

Risposte (2)

Jim Riggs
Jim Riggs il 11 Giu 2018
In the Simulink model configuration parameters, there is a tab for "Simulation Target\Custom Code". Here you can specify "Include Directories" for the model. Have you tried this?

TAB
TAB il 12 Giu 2018
Make a function to build your model.
In the function check the required paths before starting the build.
You can add the path of function file in Matlab to call it from anywhere (any directory).
function genMyCode()
% Check and correct directories
% pwd, cd, addpath etc
% Any other preprocess if required
%load data from m-file.. etc
% Start model build
rtwbuild('myModel')
end

Categorie

Scopri di più su Simulink Environment Customization in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by