Skip to content
This repository was archived by the owner on Apr 16, 2025. It is now read-only.
This repository was archived by the owner on Apr 16, 2025. It is now read-only.

rtwsfcnfmi FMU containing an S-Function packed in MATLAB 2022b crashes MATLAB #475

@benplay2

Description

@benplay2

Problem

FMUs packaged with rtwsfcnfmi.tlc from FMIKit 3.1 in MATLAB 2022b crash MATLAB when they are executed.

image

After a little debugging, I discovered that the error occurs in fmi2functions.c fmi2SetReal():
image

Replication

I created a test function to demonstrate the error state. Please see the zip file. Here's a snippet of the code:

% Perform a simple test to demonstrate an error state of FMIKit which
% causes MATLAB to crash.
% 
% From my testing with FMIKit v3.1, usage of the FMU created with 2021b
% works properly, but the one created using 2022b crashes MATLAB.

load_system(model)

cs = getActiveConfigSet(gcs);
switchTarget(cs, 'rtwsfcnfmi.tlc', []);

set_param(model, 'GenerateReport', 'off');
set_param(model, 'FMIType', 'CoSimulation');

set_param(model, 'SolverType', 'Fixed-step');

set_param(model, 'LoadBinaryMEX', loadSfunctionBinary); %Even if no s-Function in "model", this causes a crash when simulated (2022b)


slbuild(model);

close_system(model, 0);

%Now, open a new simulink model and create an FMU block of this and try to
%simulate. I used the built-in Simulink FMU block

fmikitErrorExamples.zip

Workaround

Using MATLAB 2021b to create the FMU seems to resolve the problem. Was there an S-Function API change between the versions?

System details:

  • Windows 10
  • MATLAB Version: 9.13.0.2399474 (R2022b) Update 7
  • Compiler: Visual Studio 2017
  • FMIKit version 3.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    RTWSFCNThis issue is related to the S-Function based FMU export

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions