Share Structured Text Code by Using Simulink Cache Files
You can share the generated IEC 61131-3 Structured Text code between team members by using
Simulink® cache files. When you generate code from a Simulink model hierarchy, each referenced model has an associated Simulink cache file. These files have an .slxc
file extension. The
cache files contain artifacts that can reduce the time required for successive model
simulation and code generation. Simulink generates cache files when you simulate models in accelerator or rapid
accelerator mode or when you generate code for models. For more information, see Share Simulink Cache Files for Faster Simulation. Learn
about the contents of the cache files and, how to share the code generation artifacts to
enable incremental builds and reduce build model simulation times.
Contents of Simulink Cache Files
After you generate code, Simulink PLC Coder™ packages the artifacts and generated code for the model hierarchy in the Simulink cache files. The cached artifacts include:
Shared utilities.
All files under the
slprj\plc\release name\referenced model name
. For example, for a referenced model with the namesimple_sub1
, and code generated for the CODESYS 3.5 target IDE, the files are located inslprj\plc\R2025a\simple_sub1
.Any binaries generated for the top model.
You cannot modify the contents of Simulink cache files. If you update the code generation artifacts inside the
slprj
folder, you must generate code again to integrate the changes in
the Simulink cache files.
Share Code Generation Artifacts
If you are involved in team development of large models that reference other models, you can use Simulink cache files to synchronize builds and share generated code artifacts. You can use Simulink cache files to avoid unnecessary code generation.
For example, assume that you collaborate with your team members by using a source control system and your models are built every night in a continuous integration system.
Open your model. For example, open the
simple_top
model.mdl = "simple_top"; openExample("plccoder/GenerateSTCodeForModelreferenceHierarchyExample", ... "supportingFile", mdl);
Generate code for your model. For example, after you open the
simple_top
model, open the PLC Coder app. On the PLC Code tab, click Generate PLC Code.Simulink generates Simulink cache files for both referenced models. The
simple_sub1
andsimple_sub2
models are referenced models insimple_top
.Simulink stores cache files in the folder specified by the Simulation cache folder preference.
To see the supported configurations, double-click the cache file. The Simulink cache report contains information related to each release, platform, and list of packaged targets. For example, this image shows the content of the
simple_sub1.slxc
file.Alternatively, to display the contents of the Simulink cache file in a MATLAB® table, use the
slxcinfo
function.Submit your models to the source control system. The continuous integration system builds the models overnight and updates the existing Simulink cache files.
Note
Because Simulink cache files are derived files, do not submit them to source control. If you share Simulink cache files by storing them in a source control system, you cannot diff or merge different versions of these files.
Assume your team member makes changes to the model and submits the changes to the source control system. When you want to work with the model hierarchy, fetch these files:
The model and associated files from the source control system
The Simulink cache files from the continuous integration system
Make your changes to the model.
Build the model. Because the code generator can extract the code generation artifacts from the Simulink cache files from the overnight build, it can avoid unnecessary rebuilds and code regeneration.
The time to build the model and generate code is less than the first time that you built the model.
Note
To unpack the simulation and code generation targets from the Simulink cache files without updating, simulating, or generating code for the model hierarchy, use the
slxcunpack
function.Submit your updated model files to the source control system.
amazon.com
See Also
Topics
- Share Simulink Cache Files for Faster Simulation
- Generate Structured Text Code for Model Reference Hierarchy
- Import Structured Text Code Generated from Model Reference Hierarchy
- Collaborate Using Git in MATLAB
- Push to Git Remote
- Model Reference Code Generation Limitations