Main Content

Simulink.CodeImporter.Options Class

Namespace: Simulink.CodeImporter

Specify additional import options for Simulink.CodeImporter and sltest.CodeImporter classes

Since R2021a

Description

Use the Simulink.CodeImporter class to specify options for importing custom code beyond what is specified in the CustomCode property of the relevant Simulink.CodeImporter object.

The Simulink.CodeImporter.Options class is a handle class.

Creation

When you create an object of class Simulink.CodeImporter, an object of class Simulink.CodeImporter.Options is automatically created as the Options property of that object. Do not create an object of class Simulink.CodeImporter.Options directly.

Properties

expand all

Default size of C argument passed by pointer to function in the generated C Caller block port specifications, specified as a character vector or string scalar. By default, the value is set to "-1", meaning that the size is inherited. A value of "1" indicates that arguments passed by address to functions are scalars, unless you override this setting in the Simulink.CodeImporter.SimulinkPortSpecification corresponding to a particular function.

Data Types: char | string

Automatic creation of test harness during import, specified as a logical 1 (true) or 0 (false). Specify whether the Simulink® Code Importer should automatically create a test harness for each block in the generated Simulink library (Simulink Test™ license required).

Data Types: logical

Name by which generated Simulink library appears in Simulink Library Browser, specified as a character vector or string scalar. By default, the value is an empty string, meaning that the generated library does not appear in the Simulink Library Browser. If you specify a name, the Simulink Code Importer generates the file slblocks.m as part of the artifacts the Code Importer creates.

Example: "Controller Library"

Data Types: char | string

Run custom code in a separate process outside of MATLAB® during model simulation, specified as logical 1 (true) or 0 (false). If this property is false, the custom code runs in the same process as the rest of the model during simulation. Simulations usually run faster, but run-time exceptions in the custom code can cause MATLAB to crash. If the property is true, custom code runs in a separate process during model simulation, which can prevent MATLAB from crashing due to run-time exceptions in the custom code or errors in the interface between Simulink and the custom code.

Data Types: logical

How to manage undefined functions and variables, specified as:

ValuePurpose
"FilterOut"

Filter out undefined functions and variables. Simulink Code Importer does not bring undefined functions and variables into the generated Simulink library.

"ThrowError"

Return an error if Simulink Code Importer detects an undefined function or variable.

"DoNotDetect"

Simulink Code Importer brings undefined functions and variables into the generated Simulink library, but does not automatically generate stub functions and variables equal to zero.

"UseInterfaceOnly"

Simulink Code Importer brings undefined functions and variables into the generated Simulink library, and generates stub functions and variables equal to zero.

Data Types: enum

Examples

collapse all

Create a Simulink.CodeImporter object and set options.

obj = Simulink.CodeImporter;
obj.CustomCode.InterfaceHeaders = ["pumpController.h"];
obj.CustomCode.IncludePaths = ["./include"];
obj.CustomCode.SourceFiles = ["src/pumpController.c" "src/utils.c"];
obj.Options.LibraryBrowserName="Controller Library";

obj.Options
ans = 

  Options with properties:

     PassByPointerDefaultSize: "-1"
            CreateTestHarness: 1
           LibraryBrowserName: "Controller Library"
    SimulateInSeparateProcess: 0
    UndefinedFunctionHandling: "FilterOut"

Version History

Introduced in R2021a