CATIA-Systems / FMIKit-Simulink

Import and export Functional Mock-up Units with Simulink
Other
157 stars 51 forks source link

Model Exchange / rtwsfcnfmi.tlc based FMU unable to run #298

Closed OscarAguilarAguila closed 2 years ago

OscarAguilarAguila commented 3 years ago

Hello! I am currently unable to successfully use a Model Exchange FMU that I exported in Simulink, using the FMIKit. Parting from the below-referenced issue and answer as I encountered the same problem:

Does the problem still exist with https://github.com/CATIA-Systems/FMIKit-Simulink/releases/tag/v3.0-alpha.1 ? Originally posted by @t-sommer in https://github.com/CATIA-Systems/FMIKit-Simulink/issues/294#issuecomment-864833206

I started using the FMIKit V3.0-aplha.1 version instead. It has worked great, as I've been able to use Co-Simulation without a problem, and at least export the Model Exchange successfully. However, the model exchange-exported FMUs I've tried to use make matlab either close just as the simulation is about to finish under or not even start.

The FMU log either refers to this error:

fmi2NewDiscreteStates() Failed to calculate new discrete states. The FMU crashed (exception code: ACCESS_VIOLATION). mdlTerminate() called on MiL_FMUMEStr/FMU fmi2Terminate()

Or just calls fmi2Terminate() almost immediately after starting.

This always makes Matlab/Simulink crash, either reporting a crash report or just closing immediately and altogether.

This aforementioned Crash Reports state "Access Violation", proceeds to list the register states and ends with the following message:

"This error was detected while a MEX-file was running. If the MEX-file is not an official MathWorks function, please examine its source code for errors. Please consult the External Interfaces Guide for information on debugging MEX-files."

I have attempted to run 3 models: One with COSIM FMU, another with ME FMU and the last one being the unexported, original model, all with the same solver, under the same C-compiler version (MEX configured to use 'Microsoft Visual C++ 2019 (C)' for C language compilation), and all of them work except the ME FMU version.

I have not found anything in particular from my side, and would like to know if such a behavior is known from your side regarding Model Exchange/rtwsfcnfmi.tlc-based models, or if you have any idea how such an issue could be caused.

Additionally, whenever I have imported (with the FMIKit-Simulink) a Model-Exchange FMU generated in Dymola, I have been able to succesfully run it.

Software toolchain versions that might be relevant: MATLAB Version 9.8 (R2020a) Simulink Version 10.1 (R2020a) FMIKit-Simulink Version 3.0-alpha.1 Simulink Coder Version 9.3 (R2020a)

t-sommer commented 2 years ago

Please reopen if you can share an example model to reproduce the problem with the latest alpha release.