Main Content

coder.mapping.api.get

モデルのコード マッピングの取得

R2020b 以降

    説明

    coderMapObj = coder.mapping.api.get(simulinkModel) は指定されたモデルに対してアクティブなコード マッピングを coderMapObj オブジェクトとして返します。コード マッピングはモデル データ要素を C または C++ コード生成の構成に関連付けます。モデルに複数のコード マッピングがある場合、アクティブなコード マッピングはアクティブなシステム ターゲット ファイルに関連付けられたマッピングです。

    コード マッピングが存在しない場合、エラーが生成されます。モデルの Coder アプリを開くと、Simulink® はコード マッピング オブジェクトを作成します。モデルの Coder アプリを開いていない場合は、関数 coder.mapping.utils.create を呼び出してコード マッピング オブジェクトを作成できます。

    すべて折りたたむ

    プログラム インターフェイスを使用して、Simulink モデルのコード マッピング オブジェクトを作成および使用します。

    モデル NoCoderMapping を読み込みます。

    simulinkModel = "NoCoderMapping";
    load_system(simulinkModel);

    try-catch ブロックを使用して、モデル用にコード マッピング オブジェクトが存在するかどうかを判別します。try ブロック内で、関数 coder.mapping.api.get を使用して既存のオブジェクトの取得を試みます。catch ブロック内で、関数 coder.mapping.utils.create を使用して新しいコード マッピング オブジェクトを作成します。コード マッピング オブジェクトを変数 codeMapObj に保存します。

    モデルに既存のコード マッピング オブジェクトがあったかどうかを示す出力メッセージを追加します。

    try
      codeMapObj = coder.mapping.api.get(simulinkModel);
              fprintf("" + ...
                " ========================================================\n" + ...
                " The model already had code mappings.\n" + ...
                " ========================================================\n");
    catch
              fprintf("" + ...
                " ==========================================\n" + ...
                " The model does not have code mappings.\n" + ...
                " Creating new code mappings for the model.\n" + ...
                " ==========================================\n");
      codeMapObj = coder.mapping.utils.create(simulinkModel);
    end
     ==========================================
     The model does not have code mappings.
     Creating new code mappings for the model.
     ==========================================
    

    モデルの入力端子 inport_1 のストレージ クラスを取得します。

    getInport(codeMapObj,"inport_1","StorageClass")
    ans = 
    'Auto'
    

    入力端子 inport_1 のストレージ クラスを ExportedGlobal に設定します。

    setInport(codeMapObj,"inport_1",StorageClass="ExportedGlobal")

    同じ try-catch ブロックを使用して、関数 coder.mapping.api.get でモデルの既存のコード マッピングをどのように取得できるようになったかを確認します。

    try
      codeMapObj = coder.mapping.api.get(simulinkModel);
              fprintf("" + ...
                " ========================================================\n" + ...
                " The model already had code mappings.\n" + ...
                " ========================================================\n");
    catch
              fprintf("" + ...
                " ==========================================\n" + ...
                " The model does not have code mappings.\n" + ... 
                " Creating new code mappings for the model.\n" + ...
                " ==========================================\n");
      codeMapObj = coder.mapping.utils.create(simulinkModel);
    end
     ========================================================
     The model already had code mappings.
     ========================================================
    

    モデルの入力端子 inport_1 のストレージ クラスを取得します。これは、以前に設定したストレージ クラスであることに注意してください。

    getInport(codeMapObj,"inport_1","StorageClass")
    ans = 
    'ExportedGlobal'
    

    モデルを保存せずに閉じます。

    close_system(simulinkModel,false)

    入力引数

    すべて折りたたむ

    コード マッピング オブジェクトを返す対象の Simulink モデル。ハンドル、またはモデル名 (.slx ファイル拡張子なし) あるいはモデル ファイルの相対パスまたは絶対パス (.slx ファイル拡張子を含む) を含む文字ベクトルまたは string スカラーとして指定します。

    メモ

    モデルが (たとえば、load_system を使用して) 読み込まれていなければなりません。

    例: "configModel"

    データ型: char | string | handle

    コード マッピング オブジェクトを返す対象のデータ インターフェイス ディクショナリ。Simulink.data.Dictionary オブジェクト、またはディクショナリ ファイルの相対パスまたは絶対パス (.sldd ファイル拡張子を含む) を含む文字ベクトルまたは string スカラーとして指定します。

    例: "exCodeDefs.sldd"

    データ型: char | string | Simulink.data.Dictionary

    出力引数

    すべて折りたたむ

    モデルのコード マッピング オブジェクト。CodeMapping オブジェクトまたは CodeMappingCPP として返されます。

    出力入力オブジェクトコード マッピング タイプ
    coder.mapping.api.CodeMappingSimulink モデル"SimulinkCoderC" または "EmbeddedCoderC"
    coder.mapping.api.CodeMappingCPP (Embedded Coder)Simulink モデル"EmbeddedCoderCPP"

    Embedded Coder データ ディクショナリ。coder.mapping.api.CoderDictionary オブジェクトとして返されます。

    バージョン履歴

    R2020b で導入