Simulink.CodeImporter Class
Namespace: Simulink
Description
Use the Simulink.CodeImporter
class to import custom C/C++ code into
Simulink® for modeling, verification, and validation. Instances of this class are used to
specify custom code to import into Simulink.
The Simulink.CodeImporter
class is a handle
class.
Creation
Description
obj = Simulink.CodeImporter()
creates an instance of the
CodeImporter
with the LibraryFileName
property set
to "untitled"
.
obj = Simulink.CodeImporter(
, where
LibName
)LibName
is a file name chosen by the user and specified as a string
or character vector, creates an instance of the CodeImporter
with the
LibraryFileName
property set to LibName
.
Properties
LibraryFileName
— Name of Simulink library file and generated artifacts
"untitled"
(default) | string | character vector
Name of Simulink library file and generated artifacts created for the imported code, specified as a string or a character vector. Name must be a valid MATLAB® variable name. The same file name is used with different extensions for the data dictionary and other artifacts generated when code is imported.
Example: "pumpController"
Data Types: string
| character vector
OutputFolder
— Location of generated library file and generated artifacts
"" (default) | string | character vector
Location of generated library file and generated artifacts, specified as a string or a character vector. If left blank, the current MATLAB folder is used.
File locations that are part of the CustomCode
property can be
specified relative to this folder.
Example: "C:\HeatPump\Controller"
Data Types: string
| character vector
CustomCode
— Custom C or C++ code files and associated properties to import
CustomCode
object
C or C++ code files and associated properties to import, specified as an object of
class Simulink.CodeImporter.CustomCode
. Use this property to specify code
importing options, such as source and header files, folder paths, libraries, and
compiler and linker flags. For information, see Simulink.CodeImporter.CustomCode
.
obj = Simulink.CodeImporter; obj.CustomCode.InterfaceHeaders = ["pumpController.h"]; obj.CustomCode.IncludePaths = ["./include"]; obj.CustomCode.SourceFiles = ["src/pumpController.c" "src/utils.c"]; obj.CustomCode
ans = CustomCode with properties: SourceFiles: ["src/pumpController.c" "src/utils.c"] InterfaceHeaders: "pumpController.h" IncludePaths: "./include" Libraries: [1×0 string] Defines: [1×0 string] Language: "C" CompilerFlags: [1×0 string] LinkerFlags: [1×0 string] GlobalVariableInterface: 0 FunctionArrayLayout: NotSpecified
ParseInfo
— Information regarding parsed custom code
Simulink.CodeImporter.ParseInfo
object
Information regarding the parsed custom code, specified as an object of class
Simulink.CodeImporter.ParseInfo
. This property is read-only. Parsing
needs to be successful to obtain information regarding custom code. For information, see
Simulink.CodeImporter.ParseInfo
.
s = parse(obj); obj.ParseInfo
ans = ParseInfo with properties: Success: 1 AvailableFunctions: ["Controller" "setFanTempThreshold" "setPumpTempThreshold"] EntryFunctions: ["Controller" "setFanTempThreshold" "setPumpTempThreshold"] AvailableTypes: "pump_control_bus" Errors: []
Options
— Additional options used by Code Importer during import for library creation
Options
object
Additional options used by Code Importer during import for library creation,
specified as an object of class Simulink.CodeImporter.Options
. Use this
object to change the default values for the size of an argument passed by a pointer to a
function, and the Simulink library browser name. For information, see Simulink.CodeImporter.Options
.
obj.Options
ans = Options with properties: PassByPointerDefaultSize: "-1" CreateTestHarness: 0 LibraryBrowserName: "" SimulateInSeparateProcess: 0 UndefinedFunctionHandling: "FilterOut"
obj.Options.LibraryBrowserName = "Controller Library";
obj.Options
ans = Options with properties: PassByPointerDefaultSize: "-1" CreateTestHarness: 0 LibraryBrowserName: "Controller Library" SimulateInSeparateProcess: 0 UndefinedFunctionHandling: "FilterOut"
Methods
Public Methods
parse | Analyze custom code for functions, types, global variables, and their dependencies |
import | Import custom code, functions, and types into Simulink |
addToProject | Add custom code and imported artifacts to MATLAB project |
view | Launch Simulink Code Importer wizard |
save | Save import settings to JSON format text file |
load | Load import settings from saved import settings file |
computeInterfaceHeaders | Compute interface headers from specified source files |
Examples
Import Custom Code
Specify location and options for custom code.
Create a code importer object.
obj = Simulink.CodeImporter('PumpController');
Specify the custom code to import.
obj.CustomCode.InterfaceHeaders = ["pumpController.h"]; obj.CustomCode.IncludePaths = ["./include"]; obj.CustomCode.SourceFiles = ["src/pumpController.c" "src/utils.c"];
Specify the name to use in the Library Browser.
obj.Options.LibraryBrowserName = "Controller Library";
Parse the custom code.
s = parse(obj); obj.ParseInfo
ans = ParseInfo with properties: Success: 1 AvailableFunctions: ["Controller" "setFanTempThreshold" "setPumpTempThreshold"] EntryFunctions: ["Controller" "setFanTempThreshold" "setPumpTempThreshold"] AvailableTypes: "pump_control_bus" Errors: []
Import the parsed code.
s = import(obj);
Version History
Introduced in R2021a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)