How do I troubleshoot issues with imported or exported Tool-Coupling FMUs in Simulink?

35 views (last 30 days)
I have exported a Tool-Coupling FMU from Simulink as shown below:
Why do I have issues with an imported/exported FMU in Simulink and how to resolve them?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 13 Oct 2021
Edited: MathWorks Support Team on 13 Oct 2021

How do I debug issues with imported FMUs and get the actual error message?

In order to debug an FMU imported in your model, enable the "FMU debug logging". You can find this in an FMU block in the "FMU Settings (Co-Simulation)" pane:
Click "Enable FMU debug logging" and set "Redirect debug logs to:" to "Display".
You will see the error messages in the Diagnostic Viewer which can look similar to the following:
# Debug Logging enabled for block FMU_test_bus/FMU
Component:Simulink | Category:Model
Log from FMU: [category:logStatusError, status:fmi2Error] No available MATLAB session can be found.
Component:Simulink | Category:Model
Log from FMU: [category:logStatusError, status:fmi2Error] fmi2Instantiate: Cannot find or connect to existing MATLAB session.

Troubleshooting common issues with FMU import/export:

1. Check if the FMU was exported in the same Simulink release you want to use the FMU with. This means that a Simulink FMU exported from R2018b can only be used in R2018b. If you upgrade MATLAB, re-export the FMU to use it in the newer release.
2. Check if you have started a MATLAB slave session. Starting in R2019a you have to run the following command:
>> shareMATLABForFMUCoSim
3. Before exporting the FMU using the "Share" option in Simulink, check if there are .slxc files in the folder with the name of your model. If yes, add these .slxc files to your project. They are caching the usage of variables in the model and this speeds up the simulation (but this step is not mandatory). See the note below on how to automate adding these .slxc files to your project.
4. If you are using data from the workspace or data dictionaries, also add them to your project.
5. If this data is not loaded during the runtime of your FMU simulation and has to be there for the model initialization, you have to load the data during project startup. This can be done using a project startup function, or you can use the "Run at Startup" functionality. See:
Right-click on the .mat file that has to be loaded and click "Run at Startup"
If you did it correctly, you see a small icon under "Status" and you have the right-click option to "Remove from Startup".
6. Check if the "Communication step size" of your FMU is set to a value that is not working with your original Simulink model. You can find this in the "FMU Settings (Co-Simulation)" pane. 
7. If the steps above are not resolving the issue for you, contact MathWorks Technical Support:
How can I automate adding .slxc files to the project?
There is a way for you to automate this file addition process, with some initial setup work.
1. Create a startup script (.M file) that runs every time the project is opened. See:
2. In this script, you will want to scan your project folders for the filetypes you want to add to your project. See:
3. Add either of these functions to your script, using the information from the file search above, and using "addFile" and  "addFolderIncludingChildFiles":

More Answers (0)

Community Treasure Hunt

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

Start Hunting!