Simulink: is there something like a “pre-build” callback function?
20 views (last 30 days)
Show older comments
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?
1 Comment
David Rodríguez
on 11 Jun 2018
I am in a similar situation and would like to know if there's any workaround.
Answers (2)
Jim Riggs
on 11 Jun 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?
0 Comments
TAB
on 12 Jun 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
0 Comments
See Also
Categories
Find more on Naming Conventions in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!