主要内容

导入系统作曲家架构使用ModelBuilder

作曲家™使用体系结构规范导入系统systemcomposer.io.ModelBuilder实用程序类。这些架构规范可以定义在一个外部来源,如一个Excel®文件。

在系统作曲家,架构完全由四组信息:

  • 组件及其体系结构层次结构中的位置。

  • 港口和组件的映射。

  • 连接组件之间通过端口。在这个例子中,我们也从外部源导入接口数据定义。

  • 接口架构模型和映射到港口。

下面的例子使用了systemcomposer.io.ModelBuilder类通过上述架构信息和导入系统作曲家模型。

在这个例子中,架构信息的小型无人机系统中定义一个Excel电子表格,用于创建一个系统作曲家体系结构模型。

外部源文件

  • Architecture.xlsx——这个Excel文件包含层次体系结构的信息模型。这个例子将外部源数据映射到系统作曲家模型元素。这些信息映射在列名系统作曲家模型元素。

#元素:元素的名称。可以组件或端口名称。父:父元素的名称。#类:可以是组件或端口(端口)的输入/输出方向。#域:映射组件属性。属性配置文件中定义的“制造商”UAVComponent下原型PartDescriptor映射到域值在excel中源文件。#:映射组件属性。属性“ModelName”定义在概要文件UAVComponent刻板印象PartDescriptor映射到值在excel中源文件。# InterfaceName:如果端口类型的类。InterfaceName地图界面与港口的名称。 # ConnectedTo : In case of port type, it specifies the connection to other port defined in format "ComponentName::PortName".
  • DataDefinitions.xlsx——这个Excel文件包含接口数据模型的定义。这个例子假定这个Excel数据定义的源文件之间的映射和接口层次结构在系统作曲家。

#名称:接口或元素的名称。#父:父接口名称的名字(只适用于元素)。#数据类型:数据类型的元素。可以另一个总线接口格式:InterfaceName #尺寸:尺寸的元素。#单元:单元属性的元素。#最低:最小值的元素。#最大:元素的最大值。

步骤1。实例化ModelBuilder

您可以实例化ModelBuilder类配置文件名称。

(统计,fa] = fileattrib (pwd);如果~足总。使用rWrite disp(该脚本必须运行在一个可写目录的);返回;结束

指定模型的名称。

modelName =“scExampleModelBuilder”;

指定配置文件的名称。

形象=“UAVComponent”;

指定源文件的名字读架构信息。

architectureFileName =“Architecture.xlsx”;

实例化ModelBuilder

builder = systemcomposer.io.ModelBuilder(配置文件);

步骤2。构建接口数据定义

阅读外部源文件中的信息DataDefinitions.xlsx构建数据模型的接口。

从Excel创建MATLAB®表源文件。

选择= detectImportOptions (“DataDefinitions.xlsx”);选择。DataRange =“A2”;

readtable从第二行开始读。

definitionContents = readtable (“DataDefinitions.xlsx”、选择);

systemcomposer.io.IdService类生成唯一的ID对于一个给定的键。

idService = systemcomposer.io.IdService ();rowItr = 1:元素个数(definitionContents (: 1)) parentInterface = definitionContents.Parent {rowItr};如果isempty (parentInterface)

的接口,接口名称添加到模型构建器。

interfaceName = definitionContents.Name {rowItr};

获得独特的界面ID

getID(容器,键)生成或返回相同(如果键已经存在)值为输入键在容器内。

interfaceID = idService.getID (“接口”,interfaceName);

使用builder.addInterface添加数据字典的接口。

builder.addInterface (interfaceName interfaceID);其他的

在一个元素的情况下,阅读的元素属性和元素添加到父接口。

elementName = definitionContents.Name {rowItr};interfaceID = idService.getID (“接口”,parentInterface);

ElementID在接口是独一无二的。附加E在一个的开始ID均匀性。生成的ID输入元素的父接口名作为容器内是独一无二的。

elemID = idService.getID (parentInterface elementName,“E”);

设置数据类型,尺寸,单位,最小和最大属性的元素。

数据类型= definitionContents.DataType {rowItr};尺寸=字符串(definitionContents.Dimensions (rowItr));单位= definitionContents.Units (rowItr);

确保输入builder效用函数总是一个字符串。

如果= ~ ischar(单位)单位;结束最小= definitionContents.Minimum {rowItr};最大= definitionContents.Maximum {rowItr};

使用builder.addElementInInterface添加一个元素的属性界面。

builder.addElementInInterface (elementName elemID interfaceID,数据类型,尺寸,单位,“真实”的、最大、最小);结束结束

步骤3。构建体系结构规范

从Excel架构规范是由MATLAB表源文件。

excelContents = readtable (architectureFileName);

遍历表中的每一行。

rowItr = 1:元素个数(excelContents (: 1))

读取Excel文件的每一行和列。

类= excelContents.Class (rowItr);父母= excelContents.Parent (rowItr);Name = excelContents.Element {rowItr};

填充的内容表。

如果比较字符串(类,“组件”)ID = idService.getID (“薪酬”、名称);

根ID是默认设置为零。

如果比较字符串(父,“scExampleSmallUAV”)parentID =“0”;其他的parentID = idService.getID (“薪酬”、家长);结束

使用builder.addComponent添加一个组件。

builder.addComponent(名称、ID parentID);

读取属性值。

类型= excelContents.Kind {rowItr};域= excelContents.Domain {rowItr};

使用builder.setComponentProperty建立原型和属性值。

builder.setComponentProperty (ID、“StereotypeName”,“UAVComponent.PartDescriptor”,“ModelName”、善良、“制造商”域);其他的

在这个例子中,连接的端口名和父组件名称作为键为端口生成惟一的id。

portID = idService.getID (“端口”strcat(名称、父));

港口在根结构,列表假设是0

如果比较字符串(父,“scExampleSmallUAV”)列表=“0”;其他的列表= idService.getID (“薪酬”、家长);结束

使用builder.addPort添加一个端口。

builder.addPort(Name,class,portID,compID );

InterfaceName指定接口的名称与港口。

interfaceName = excelContents.InterfaceName {rowItr};

接口ID。

getID将返回相同的id在步骤2中已经生成而添加接口。

interfaceID = idService.getID (“接口”,interfaceName);

使用builder.addInterfaceToPort接口映射到港口。

builder.addInterfaceToPort (interfaceID portID);

读了建立组件之间的连接信息。

与= excelContents.ConnectedTo {rowItr};

的格式:

(DestinationComponentName:: DestinationPortName)

对于这个示例,考虑当前端口的连接。

如果~ isempty(与)connID = idService.getID (“连接”,与);分裂=分裂(与,“::”);

得到的端口ID连接端口。

在这个例子中,端口ID是由连接端口名和父组件名称。如果端口ID已经生成,getID为输入键函数返回相同的ID。

connectedPortID = idService.getID (“端口”strcat(分裂(2)将(1)));

填充表的连接。

sourcePortID = portID;destPortID = connectedPortID;

使用builder.addConnection添加连接。

builder.addConnection(与、connID sourcePortID destPortID);结束结束结束

步骤3。导入模型从填充表builder.build函数

[模型,importReport] = builder.build (modelName);

2022 - 02年- 15 - _11 - 55 - 21. png

清理工件。

清理

版权2020年MathWorks公司。

另请参阅

||

相关的话题