主要内容

本页采用了机器翻译。点击此处可查看最新英文版本。

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

    数据字典的建筑数据部分中定义的数据类型,指定为具有属性 NameOwnerSimulink.dictionary.archdata.DataType 对象数组。

    定义的常量,指定为具有属性的 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 中推出