主要内容

Simulink.dictionary.ArchitecturalData

以编程方式编辑 Simulink 数据字典中的架构数据

自 R2023b 起

    说明

    Simulink.dictionary.ArchitecturalData 对象表示 Simulink® 数据字典的“架构数据”分区。通过架构数据对象,您可以以编程方式跨 Simulink 和端口接口、数据类型、系统级常量及其平台属性的架构模型访问共享定义。您也可以使用架构数据编辑器管理架构数据。

    创建对象

    您可以使用 Simulink.dictionary.archdata.create 函数创建一个新数据字典。此函数返回 Simulink.dictionary.ArchitecturalData 对象。

    dictName = "MyInterfaces.sldd";
    archDataObj = Simulink.dictionary.archdata.create(dictName);

    如果您已创建数据字典,您可以使用 Simulink.dictionary.archdata.open 函数创建架构数据对象。

    dictName = "MyInterfaces.sldd";
    archDataObj = Simulink.dictionary.archdata.open(dictName);

    属性

    全部展开

    数据字典的文件名,指定为字符向量或字符串标量。名称必须包含 .sldd 扩展名,并且必须为有效的 MATLAB® 标识符。

    在数据字典的“架构数据”分区中定义的接口,指定为 Simulink.dictionary.archdata.DataInterfaceSimulink.dictionary.archdata.ServiceInterfaceSimulink.dictionary.archdata.PhysicalInterface 对象数组,具有属性:DescriptionElementsNameOwner

    在数据字典的“架构数据”分区中定义的数据类型,指定为 Simulink.dictionary.archdata.DataType 对象数组,具有属性:NameOwner

    定义的常量,指定为 Simulink.dictionary.archdata.Constant 对象数组,具有属性:ValueDescriptionDataTypeNameOwner

    对象函数

    addAliasTypeAdd Simulink alias type to Architectural Data section of Simulink data dictionary
    addConstantAdd constant to Architectural Data section of Simulink data dictionary
    addDataInterfaceAdd data interface to Architectural Data section of Simulink data dictionary
    addEnumTypeAdd enumerated type to Architectural Data section of Simulink data dictionary
    addNumericTypeAdd Simulink numeric type to Architectural Data section of Simulink data dictionary
    addPhysicalInterfaceAdd physical interface to Architectural Data section of Simulink data dictionary
    addPlatformMappingAdd AUTOSAR Classic mapping to Architectural Data section of Simulink data dictionary
    addReferenceAdd data dictionary reference to Architectural Data section of Simulink data dictionary
    addServiceInterfaceAdd service interface to Architectural Data section of Simulink data dictionary
    addStructTypeAdd structure type to Architectural Data section of Simulink data dictionary
    addValueTypeAdd value type to Architectural Data section of Simulink data dictionary
    closeClose any open connections to Simulink data dictionary
    discardChangesDiscard changes to Simulink data dictionary
    findEntryByNameGet object by name in Architectural Data section of Simulink data dictionary
    getConstantGet Simulink.dictionary.archdata.Constant object in Architectural Data section of Simulink data dictionary
    getConstantNamesGet constant names in Architectural Data section of Simulink data dictionary
    getDataTypeGet data type in Architectural Data section of Simulink data dictionary
    getDataTypeNamesGet names of data types in Architectural Data section of Simulink data dictionary
    getInterfaceGet interface object for interface in Architectural Data section of Simulink data dictionary
    getInterfaceNamesGet interface names in Architectural Data section of Simulink data dictionary
    getPlatformMappingGet platform mapping object for platform of Simulink data dictionary
    getReferencesGet full paths of Simulink data dictionaries referenced by another Simulink data dictionary
    importFromBaseWorkspaceImport Simulink object definitions from base workspace to Architectural Data section of Simulink data dictionary
    importFromFileImport Simulink object definitions from file to Architectural Data section of data dictionary
    isDirtyCheck for unsaved changes in Simulink data dictionary
    moveToDesignDataMove interfaces, data types, and constants in Architectural Data section of Simulink data dictionary to design data
    moveToDictionaryMove architectural data of Simulink data dictionary to another data dictionary
    removeConstantRemove constant from Architectural Data section of Simulink data dictionary
    removeDataTypeRemove data type from Architectural Data section of Simulink data dictionary
    removeInterfaceRemove interface from Architectural Data section of Simulink data dictionary
    removeReferenceRemove Simulink data dictionary reference of another Simulink data dictionary
    removePlatformMappingRemove platform mapping of Architectural Data section of data dictionary
    saveSave changes to Architectural Data section of Simulink data dictionary
    showView architectural data of Simulink data dictionary in Architectural Data Editor
    showChangesView changes to architectural data of Simulink data dictionary in Comparison Tool

    示例

    全部折叠

    创建 Simulink 数据字典并返回关联的架构数据对象。

    dictName = "MyArchitecturalData.sldd";
    archDataObj = Simulink.dictionary.archdata.create(dictName);

    使用类型特定函数向数据字典添加别名类型和枚举。

    myAliasType1Obj = addAliasType(archDataObj,"aliasType",BaseType="single");
    myAliasType1Obj.Name = "myAliasType1";
    myAliasType1Obj.BaseType = "fixdt(1,32,16)";
    myAliasType2Obj = addAliasType(archDataObj,"myAliasType2");
    myAliasType2Obj.BaseType = myAliasType1Obj;
    
    myEnumType1Obj = addEnumType(archDataObj,"myColor");
    addEnumeral(myEnumType1Obj,"RED",'0',"Red Sunset");
    addEnumeral(myEnumType1Obj,"BLUE",'1',"Blue Skies");
    myEnumType1Obj.DefaultValue = "BLUE";
    myEnumType1Obj.Description = "I am a Simulink Enumeration";
    myEnumType1Obj.StorageType = 'int16'; 

    您可以将创建的别名类型的基类型设置为创建的枚举数据类型 myColor

    myAliasType3Obj = addAliasType(archDataObj,"myAliasType3");
    myAliasType3Obj.BaseType = myEnumType1Obj;
     

    使用 addNumericType 函数向数据字典添加数值类型。

    myNumericType1Obj = addNumericType(archDataObj,"myNumericType1");
    myNumericType1Obj.DataTypeMode = "Single";

    使用 addValueType 向数据字典添加值类型。您也可以将值类型的数据类型设置为预先存在数据类型或创建的枚举数据类型。

    myValueType1Obj = addValueType(archDataObj,"myValueType1");
    myValueType1Obj.DataType = "int32";
    myValueType1Obj.Dimensions = '[2 3]';
    myValueType1Obj.Description = "I am a Simulink ValueType";

    使用 addStructType 函数向数据字典添加结构体类型。

    myStructType1Obj = addStructType(archDataObj,"myStructType1");
    structElement1 = myStructType1Obj.addElement("Element1");
    structElement1.Type.DataType = "single";
    structElement1.Type.Dimensions = "3";
    structElement2 = addElement(myStructType1Obj,"Element2");
    structElement3 = addElement(myStructType1Obj,"Element3");

    您可以使用数据类型对象,或使用指定为字符串标量或字符向量的数据类型名称来设置结构体元素的数据类型。

    structElement2.Type = myValueType1Obj;
    % or
    structElement3.Type = "ValueType: myValueType1";

    您可以使用 addConstant 函数添加常量。

    myConstantObj = addConstant(archDataObj, "myConst", Value=4);

    您可以使用 Simulink.dictionary.archdata.DataInterface 对象的函数添加通信接口及其数据元素。

    dataInterface1Obj = addDataInterface(archDataObj,"DataInterface");
     
    dataElm1 = addElement(dataInterface1Obj,"DE1");
    dataElm1.Type = myValueType1Obj;
     
    dataElm2 = addElement(dataInterface1Obj,"DE2");
    dataElm2.Type = myStructType1Obj;
    dataElm2.Dimensions = "4";
    dataElm2.Description = "I am a data element with datatype = array of struct type";
     
    dataElm3 = addElement(dataInterface1Obj,"DE3");
    dataElm3.Type.DataType = "single";
    dataElm3.Type.Dimensions = "10";
    dataElm3.Type.Minimum = "-5";

    您可以向数据字典的“架构数据”分区添加所支持产品的平台映射。例如,在以下编程步骤中,使用 addPlatformMapping 函数添加 AUTOSAR Classic 映射。

    platformMapping = addPlatformMapping(archDataObj,"AUTOSARClassic");

    使用 getPlatformProperties (AUTOSAR Blockset)setPlatformProperty (AUTOSAR Blockset) 函数获取和设置 AUTOSAR 通信接口与包属性。

    setPlatformProperty(platformMapping, dataInterface1Obj,...
        "Package","/Interface2","InterfaceKind","NvDataInterface");
    [pNames, pValues] = getPlatformProperties(platformMapping,dataInterface1Obj);

    您现在可以为数据字典内容生成 ARXML 代码。

    exportedFolder = exportDictionary(platformMapping);
    Exporting dictionary, please wait...
    Exported dictionary ARXML files are located in: C:\work\MyArchitecturalData.

    管理 AUTOSAR Classic 平台相关元素、软件寻址方法和标定属性。这些元素没有到 Simulink 的映射。

    arProps = autosar.api.getAUTOSARProperties(dictName);
    addPackageableElement(arProps,"SwAddrMethod", ... 
        "/SwAddressMethods","VAR1","SectionType","Var");
    setPlatformProperty(platformMapping,dataElm1, ...
        SwAddrMethod="VAR1",SwCalibrationAccess="ReadWrite",... 
         DisplayFormat="%.3f");

    版本历史记录

    在 R2023b 中推出