Main Content

Simulink.CodeImporter.SimulinkPortSpecification Class

Namespace: Simulink.CodeImporter

Configure port specification for imported custom code

Since R2021a


Configure port specification for custom code function arguments imported as C Caller blocks via Simulink.CodeImporter or sltest.CodeImporter class instances, that is, configure how C/C++ interfaces map to Simulink® interfaces for custom code functions.

This class is analogous to the FunctionPortSpecification class that is used to configure C Caller block properties outside the context of the Simulink Code Importer. The properties and methods of this class behave similarly to the like-named properties and methods of the FunctionPortSpecification class.

The SimulinkPortSpecification class is a handle class.


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


expand all

Port specification for input arguments, specified as FunctionArgument objects.

Port specification for function return argument, specified as a FunctionArgument object.

Port specification for custom code global variables used as function arguments, specified as a FunctionArgument object.


expand all


collapse all

Specify and parse custom code, then customize port specification before importing into Simulink.

%% Create code importer object
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 custom code and configure function
fcn = obj.ParseInfo.getFunctions("Controller");
fcn.PortSpecification.ReturnArgument.Label = "control_out";

ans = 

  FunctionArgument with properties:

          Name: 'out'
    PortNumber: 1
          Size: '1'
          Type: 'Bus: pump_control_bus'
         Label: 'control_out'
         Scope: 'Output'

Version History

Introduced in R2021a