主要内容

addStructType

在 Simulink 接口字典中添加由 Simulink.Bus 表示的结构体类型

自 R2022b 起

在 R2023b 中,引入了数据字典的“架构数据”部分。当管理接口、数据类型、常量和软件寻址方法时,请考虑改用 Simulink.dictionary.ArchitecturalData 编程接口。有关详细信息,请参阅Programmatically Manage AUTOSAR Architectural Data

说明

dataType = addStructType(dictObj,dtName) 将具有指定名称的 Simulink.Bus 类型添加到字典。

示例

dataType = addStructType(dictObj,dtName, SimulinkBus=busObj) 将具有指定名称 dtName 的结构体类型添加到字典,该结构体类型镜像指定的 Simulink.Bus 对象 busObj

示例

示例

全部折叠

要将具有指定名称的 Simulink.Bus 类型添加到字典,请使用 addStructType 函数。有关显示相关函数工作流的更多信息的示例,请参阅创建和配置接口字典

% open interface dictionary
dictName = 'MyInterfaces.sldd';
dictAPI = Simulink.interface.dictionary.open(dictName);

% add an enumerated type
myEnumType1 = addEnumType(dictAPI,'myColor');
myEnumType1.addEnumeral('RED', '0', 'Solid Red');
myEnumType1.addEnumeral('BLUE', '1', 'Solid Blue');
myEnumType1.StorageType = 'int16';

% add a value type that uses the enum type as its data type
myValueType1 = addValueType(dictAPI, 'myValueType1');
myValueType1.DataType = 'int32';
myValueType1.Dimensions = '[2 3]';
myValueType1.DataType = myEnumType1;

%% add a structured type 
myStructType1 = addStructType(dictAPI, 'myStructType1');
structElement1 = myStructType1.addElement('Element1');
structElement1.Type.DataType = 'single';
structElement1.Type.Dimensions = '3';
structElement2 = myStructType1.addElement('Element2');
structElement2.Type = myValueType1;
% or
structElement2.Type = 'ValueType: myValueType1';

此示例将镜像现有 Simulink.Bus 对象的 StructType 类型添加到 Simulink 接口字典 MyInterfaces.sldd

% open interface dictionary
dictName = 'MyInterfaces.sldd';
dictAPI = Simulink.interface.dictionary.open(dictName);

% create Simulink.Bus object and add elements
simBusObj = Simulink.Bus;
busElement1 = Simulink.BusElement;
busElement1.Name = 'MyBusElement1';
busElement1.DataType = 'single';
simBusObj.Elements(1) = busElement1;
busElement2 = Simulink.BusElement;
busElement2.Name = 'MyBusElement2';
simBusObj.Elements(2) = busElement2;

% add structure type based on simBusObj
myNewStructType = addStructType(dictAPI,'StructFromSimBus',SimulinkBus=simBusObj)
myNewStructType = 
  StructType with properties:
           Name: 'StructFromSimBus'
    Description: ''
       Elements: [1×2 Simulink.interface.dictionary.StructElement]
          Owner: [1×1 Simulink.interface.Dictionary]

输入参数

全部折叠

接口字典,指定为 Simulink.interface.Dictionary 对象。在使用此函数之前,请使用 Simulink.interface.dictionary.createSimulink.interface.dictionary.open 创建或打开 dictObj

dictObjDataTypes 属性数组中的 DataType 定义名称,指定为字符向量或字符串标量。

示例: "airSpeed"

总线类型对象,指定为 Simulink.Bus 对象。

输出参量

全部折叠

结构体类型对象,以 Simulink.interface.dictionary.StructType 对象形式返回,其中包含元素并以 Simulink.Bus 作为底层实现。

版本历史记录

在 R2022b 中推出

全部折叠