S-function and Custom C Code support with Simulink Desktop Real-Time (SLDRT) in Kernel Mode
28 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 26 de Mayo de 2020
Editada: MathWorks Support Team
el 24 de Jun. de 2025
I have written a C-MEX S-function, or other custom C code that uses Windows API functions. When I try to compile this model using sldrt.tlc to run the real-time simulation with Simulink Desktop Real-Time (SLDRT) in Kernel Mode (previously called External Mode), I receive the following build error using MATLAB R2020a:
In file included from ...\someSource.c:134:
C:/PROGRA~1/MATLAB/R2020a/toolbox/sldrt/lib/include\Windows.h:16:2: error:
Attempt to include "windows.h"
C:/PROGRA~1/MATLAB/R2020a/toolbox/sldrt/lib/include\Windows.h:17:2: error:
The model being compiled contains a block that can run on host only and
cannot be compiled for External Mode. Please either switch to Normal Mode
or remove the block.
In newer versions of MATLAB:
In file included from someSourcec:21:
In file included from ./someSource.h:25:
C:/PROGRA~1/MATLAB/R2024b/toolbox/sldrt/lib/include\windows.h:16:2: error:
The model contains a block that requires to include the "windows.h" header
in its generated code. Such blocks cannot be compiled for Run in Kernel Mode.
Please either switch to Connected IO Mode or remove the block.
When I include an S-Function or other custom external C code in my model, is there a limitation regarding the C library functions it can use with Simulink Desktop Real-Time simulation in External Mode?
Respuesta aceptada
MathWorks Support Team
el 24 de Jun. de 2025
Editada: MathWorks Support Team
el 24 de Jun. de 2025
You can use S-functions and custom C code with SLDRT Kernel Mode, as long as the code is self-contained. This means the S-functions and C code should only rely on a limited subset of the standard C library, such as math and string functions.
S-functions or custom C code that use file input/output, console input/output, or any Windows API calls, such as those from the windows.h header, are not supported in SLDRT Kernel Mode.
For a detailed list of supported and unsupported C functions, refer to the official documentation:
Note that the above limitations apply only to SLDRT Kernel Mode. They do not affect Connected IO or Accelerator Mode simulations. So, if your S-function or custom C code requires unsupported features such as the windows.h header, you can still simulate your model using Connected IO or Accelerator Mode. For more information about the different SLDRT simulation modes, see this MATLAB Answers article:
Also note that the ability to simulate an S-function or custom C code with other code generation targets—such as grt.tlc, ert.tlc—does not guarantee compatibility with sldrt.tlc. For example, S-functions that depend on dynamically linked libraries (DLLs) typically do not work with SLDRT, as the real-time kernel cannot access these DLLs.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!