Main Content

Get Generated Type and Name of Inport Structures

To obtain the generated type and name of inport and outport structures, use the code descriptor API. The code generator stores this information within a DataImplementation object field on a DataInterface object when it generates the code.

To interface your generated code with other components of your application, use the code descriptor API.

Open and Build Model

Open the model.

myModel = "SumModel";
open_system(myModel);

2021-07-14_9-50-51.png

Build the model.

evalc("slbuild(myModel)");

The generated code includes a structure representing the inports.

/* External inputs (root inport signals with default storage) */
ExtU rtU;

Get Code Descriptor and Inport Structure Names and Types

Get the code descriptor object.

codeDescObj = coder.getCodeDescriptor(myModel)
codeDescObj = 
  CodeDescriptor with properties:

    ModelName: 'SumModel'
     BuildDir: '/tmp/Bdoc24a_2528353_1240342/tpc754ea74/simulinkcoder-ex78186698/SumModel_ert_rtw'

Get the list of data interface types in the generated code.

dataInterfaceTypes = codeDescObj.getDataInterfaceTypes()
dataInterfaceTypes = 2x1 cell
    {'Inports' }
    {'Outports'}

Get the DataInterface object that represents the inports.

inports = codeDescObj.getDataInterfaces('Inports')
inports = 
  1x2 DataInterface array with properties:

    Type
    SID
    GraphicalName
    VariantInfo
    Implementation
    Timing
    Unit
    Range

Get the Implementation object that represents the first inport. In this example, the inports are each represented as a StructExpression, which is a subclass of DataImplementation.

impl = inports(1).Implementation
impl = 
  StructExpression with properties:
                 Type: [1x1 coder.descriptor.types.Type]
           BaseRegion: [1x1 coder.descriptor.TypedRegion]
    ElementIdentifier: 'In1'
              Variant: ''

Get the Type of the first inport. The Type of the inport is real_T.

implType = impl.Type
implType = 
  Double with properties:
    Identifier: 'real_T'
          Name: 'double'
      ReadOnly: 0
      Volatile: 0
    WordLength: 64
        Signed: 1

Get the BaseRegion of the first inport. BaseRegion represents the structure that contains the inport. The BaseRegion is rtU.

baseRegion = impl.BaseRegion
baseRegion = 
  Variable with properties:
                Type: [1x1 coder.descriptor.types.Type]
          Identifier: 'rtU'
            VarOwner: 'SumModel'
    StorageSpecifier: 'extern'

Get the Type of the BaseRegion. The Type of the BaseRegion is ExtU.

baseRegionType = baseRegion.Type
baseRegionType = 
  Struct with properties:
    Identifier: 'ExtU'
          Name: 'ExtU'
      ReadOnly: 0
      Volatile: 0
      Elements: [1x2 coder.descriptor.types.AggregateElement Sequence]
      Checksum: [1x0 Integer Sequence]

Close Model

bdclose(myModel);

Related Topics