Main Content

Simulink.CodeImporter.Function class

Package: Simulink.CodeImporter

Access and configure detailed information about parsed custom code functions

Description

Access detailed information about parsed custom code functions obtained from Simulink.CodeImporter or sltest.CodeImporter class instance. Configure information about custom code functions for importing into Simulink®.

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

Creation

One or more objects of this class are automatically created when you invoke the getFunctions method of an object of class Simuink.CodeImporter.ParseInfo. A Simulink.CodeImporter.Function object is created for each function in the parsed custom code for which getFunctions is invoked. Do not create an object of class Simulink.CodeImporter.Function directly.

Properties

expand all

Function name, returned as a string scalar.

Example: "Controller"

Data Types: string scalar

C prototype for function, returned as a string scalar.

Example: "pump_control_bus Controller(real_T Tset, real_T Troom_in);"

Data Types: string scalar

Port specification of function, specified as an object of class Simulink.CodeImporter.SimulinkPortSpecification.

Whether function is an entry-point function, returned as a logical scalar. An entry-point function is not called by other functions in the custom code.

Whether function is defined, returned as a logical scalar. This scalar indicates whether custom code contains a function body defining the function in addition to a function prototype defined in a header.

Whether function is deterministic, specified as a logical scalar. A deterministic function always produces the same outputs for the same input values. Specifying a function as deterministic enables the corresponding C Caller block to be used in a For Each subsystem and with continuous sample time, and optimizes the use of the block in conditional input branch execution. See Deterministic functions.

Whether function is stubbed, returned as a logical scalar. This scalar indicates whether, for a unit test, a stub for undefined symbols was generated for the function (Simulink Test™ license required).

Array layout for function, returned as NotSpecified, ColumnMajor, RowMajor, or Any. If NotSpecified, then the default setting for the custom code as specified in the FunctionArrayLayout property of the relevant SimulinkCode.CustomCode object is used. Otherwise, the value specified for the function overrides the default.

Data Types: enum

Methods

expand all

Examples

collapse all

Specify and parse custom code, then query information regarding custom code functions.

obj = Simulink.CodeImporter;

%% Set library file name and output folder
obj.LibraryFileName = "pumpController";
obj.OutputFolder = ".";

%% Set the custom code to import
obj.CustomCode.InterfaceHeaders = ["pumpController.h"];
obj.CustomCode.IncludePaths = ["./include"];
obj.CustomCode.SourceFiles = ["src/pumpController.c" "src/utils.c"];

%% Parse code
obj.parse;
parseobj = obj.ParseInfo
ans = 

  ParseInfo with properties:

               Success: 1
    AvailableFunctions: ["Controller"    "setFanTempThreshold"    "setPumpTempThreshold"]
        EntryFunctions: ["Controller"    "setFanTempThreshold"    "setPumpTempThreshold"]
        AvailableTypes: "pump_control_bus"
                Errors: []
fcnobj = parseobj.getFunctions(["Controller"])
fcnobj = 

  Function with properties:

                 Name: "Controller"
           CPrototype: "pump_control_bus Controller(real_T Tset, real_T Troom_in);"
    PortSpecification: [1×1 Simulink.CodeImporter.SimulinkPortSpecification]
              IsEntry: 1
            IsDefined: 1
               IsStub: 0
          ArrayLayout: NotSpecified
      IsDeterministic: 0

Introduced in R2021a