Main Content

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

生成コードに関するコード説明の取得

コード記述子 API を使用して、生成コードに関するメタデータを取得できます。既定では、コード ジェネレーターはモデルの各ビルドに対して codedescriptor.dmr ファイルをビルド フォルダー内に作成します。アクセラレータ モードおよびラピッド アクセラレータ モードでモデルのシミュレーションを実行すると、codedescriptor.dmr は生成されません。

コードが生成されたら、コード記述子 API を使用できます。コード記述子 API を使用して、生成コード内の次の項目について記述します。

  • データ インターフェイス: 入力端子、出力端子、パラメーター、データ ストアおよび内部データ。

  • 関数インターフェイス: 初期化、出力、更新および終了。

  • データや関数インターフェイスの実行時の情報 (各インターフェイス エンティティのタイミング要件など)。

  • モデルの階層構造情報と参照モデルのコードの説明。

データ インターフェイス情報の取得

coder.descriptor.DataInterfaceオブジェクトは、生成されたコードの指定されたデータ インターフェイスのさまざまなプロパティを示します。モデル CustomCodeComments には、4 つの入力端子、1 つの出力端子および調整可能な外部パラメーターがあります。モデル内のデータ インターフェイスの詳細については、coder.codedescriptor.CodeDescriptorオブジェクトとそのメソッドを使用してください。

1. モデルを開いて作成します。

open_system('CustomCodeComments');
evalc('slbuild(''CustomCodeComments'')');

2. 関数getCodeDescriptorを使用して、必要なモデルの coder.codedescriptor.CodeDescriptor オブジェクトを作成します。

codeDescriptor = coder.getCodeDescriptor('CustomCodeComments');

3. 生成コード内のすべてのデータ インターフェイス タイプのリストを取得するには、getDataInterfaceTypesメソッドを使用します。

dataInterfaceTypes = codeDescriptor.getDataInterfaceTypes()
dataInterfaceTypes =

  5x1 cell array

    {'Inports'                 }
    {'Outports'                }
    {'Parameters'              }
    {'ExternalParameterObjects'}
    {'InternalData'            }

サポートされているすべてのデータ インターフェイスのリストを取得するには、getAllDataInterfaceTypesメソッドを使用します。

4. 特定のデータ インターフェイス タイプに関する詳細を取得するには、getDataInterfacesメソッドを使用します。

dataInterface = codeDescriptor.getDataInterfaces('Inports');

このメソッドによって、生成コード内の Inport ブロックのプロパティが返されます。

5. このモデルには 4 つの入力端子があるため、dataInterfacecoder.descriptor.DataInterface オブジェクトの配列です。配列の最初の位置にアクセスして、モデルの最初の入力端子の詳細を取得します。

dataInterface(1)
ans = 

  DataInterface with properties:
              Type: [1x1 coder.descriptor.types.Type]
               SID: 'CustomCodeComments:99'
     GraphicalName: 'In1'
       VariantInfo: [1x0 coder.descriptor.VariantInfo]
    Implementation: [1x1 coder.descriptor.DataImplementation]
            Timing: [1x1 coder.descriptor.TimingInterface]
              Unit: ''
             Range: [1x0 coder.descriptor.Range]

関数インターフェイス情報の取得

関数インターフェイスは、生成されたコードのエントリポイント関数です。モデル RollAxisAutopilot のエントリポイント関数は model_initializemodel_step および model_terminate です。モデル内の関数インターフェイスの詳細については、coder.descriptor.FunctionInterfaceオブジェクトを使用してください。

1. ビルド エラーを回避するために、前のビルドから slprj ディレクトリを削除します。RollAxisAutopilot モデルを開いてビルドします。

rmdir ('slprj','s')
open_system('RollAxisAutopilot')
slbuild('RollAxisAutopilot')
### Starting build procedure for: RollAxisAutopilot
### Successful completion of build procedure for: RollAxisAutopilot

Build Summary

Top model targets built:

Model              Action                        Rebuild Reason                                    
===================================================================================================
RollAxisAutopilot  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.946s

2. 関数getCodeDescriptorを使用して、必要なモデルの coder.codedescriptor.CodeDescriptor オブジェクトを作成します。

codeDescriptor = coder.getCodeDescriptor('RollAxisAutopilot');

3. 生成コード内のすべての関数インターフェイス タイプのリストを取得するには、getFunctionInterfaceTypesメソッドを使用します。

functionInterfaceTypes = codeDescriptor.getFunctionInterfaceTypes()
functionInterfaceTypes =

  2x1 cell array

    {'Initialize'}
    {'Output'    }

サポートされているすべての関数インターフェイスのリストを取得するには、getAllFunctionInterfaceTypesメソッドを使用します。

4. 特定の関数インターフェイス タイプに関する詳細を取得するには、getFunctionInterfacesメソッドを使用します。

functionInterface = codeDescriptor.getFunctionInterfaces('Initialize')
functionInterface = 

  FunctionInterface with properties:
        Prototype: [1x1 coder.descriptor.types.Prototype]
     ActualReturn: [1x0 coder.descriptor.DataInterface]
      VariantInfo: [1x0 coder.descriptor.VariantInfo]
    FunctionOwner: [1x0 coder.descriptor.TypedRegion]
           Timing: [1x1 coder.descriptor.TimingInterface]
       ActualArgs: [1x0 coder.descriptor.DataInterface Sequence]

5. プロパティをさらに展開すると、詳細情報を取得できます。関数の戻り値、名前および引数を取得するには、以下を実行します。

functionInterface.Prototype
% 6.
ans = 

  Prototype with properties:
          Name: 'RollAxisAutopilot_initialize'
        Return: [1x0 coder.descriptor.types.Argument]
    HeaderFile: 'RollAxisAutopilot.h'
    SourceFile: 'RollAxisAutopilot.c'
     Arguments: [1x0 coder.descriptor.types.Argument Sequence]

モデルの階層構造情報の取得

coder.codedescriptor.CodeDescriptor オブジェクトを使用して、モデルの階層構造全体の情報を取得します。モデル AsynchronousEventsTop には参照モデルとしてモデル AsynchronousEventsRef があります。

1. モデルを開いて作成します。

open_system('AsynchronousEventsTop');
evalc('slbuild(''AsynchronousEventsTop'')');

2. 関数getCodeDescriptorを使用して、必要なモデルの coder.codedescriptor.CodeDescriptor オブジェクトを作成します。

codeDescriptor = coder.getCodeDescriptor('AsynchronousEventsTop');

3. getReferencedModelNamesメソッドを使用して、すべての参照モデルのリストを取得します。

refModels = codeDescriptor.getReferencedModelNames()
refModels =

  1x1 cell array

    {'AsynchronousEventsRef'}

4. 参照モデルの coder.codedescriptor.CodeDescriptor オブジェクトを取得するには、getReferencedModelCodeDescriptorメソッドを使用します。

refCodeDescriptor = codeDescriptor.getReferencedModelCodeDescriptor('AsynchronousEventsRef');

これで、コード記述子 API で利用可能なすべてのメソッドを使用することで、refCodeDescriptor オブジェクトを使用して参照モデルに関する詳細を取得できます。

関連するトピック