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.

1. Open the model.


2. Build the model.

### Starting build procedure for: rtwdemo_sum
### Successful completion of build procedure for: rtwdemo_sum

Build Summary

Top model targets built:

Model        Action                       Rebuild Reason                                    
rtwdemo_sum  Code generated and compiled  Code generation information file does not exist.  

1 of 1 models built (0 models already up to date)
Build duration: 0h 0m 20.845s

The generated code includes a structure representing the inports.

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

3. Get the code descriptor object.

codeDescObj = coder.getCodeDescriptor('rtwdemo_sum')
codeDescObj = 
  CodeDescriptor with properties:

    ModelName: 'rtwdemo_sum'
     BuildDir: '/tmp/Bdoc21b_1757077_75676/tpa197f9e0/simulinkcoder-ex78186698/rtwdemo_sum_ert_rtw'

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

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

5. Get the DataInterface object that represents the inports.

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


6. 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: ''

7. 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
    Signedness: 1

8. 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: 'rtwdemo_sum'
    StorageSpecifier: ''

9. 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]

Related Topics