主要内容

导入系统编写器体系结构使用ModelBuilder

将体系结构规范导入System Composer™systemcomposer.io.ModelBuilder实用程序类。这些体系结构规范可以在外部源中定义,例如Excel®文件。

在System Composer中,架构完全由四组信息定义:

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

  • 端口及其到组件的映射。

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

  • 体系结构模型中的接口及其到端口的映射。

本例使用systemcomposer.io.ModelBuilder类来传递上述所有体系结构信息并导入System Composer模型。

在本例中,在Excel电子表格中定义了小型无人机系统的架构信息,并用于创建system Composer架构模型。

外部源文件

  • Architecture.xlsx—该Excel文件包含架构模型的层次信息。此示例将外部源数据映射到System Composer模型元素。该信息在列名中映射到System Composer模型元素。

# Element:元素名称。可以是组件名,也可以是端口名。# Parent:父元素名称。#类:可以是组件,也可以是端口(端口的输入/输出方向)。#域:映射为组件属性。在Stereotype PartDescriptor下的UAVComponent概要文件中定义的属性“Manufacturer”映射到excel源文件中的域值。# Kind:映射为组件属性。在Stereotype PartDescriptor下的UAVComponent配置文件中定义的属性“ModelName”映射到excel源文件中的Kind值。# InterfaceName:如果类是端口类型。InterfaceName映射到端口所链接的接口名称。 # ConnectedTo : In case of port type, it specifies the connection to other port defined in format "ComponentName::PortName".
  • DataDefinitions.xlsx-此Excel文件包含模型的接口数据定义。本例假设Excel源文件中的数据定义与System Composer中的接口层次结构之间存在这种映射。

# Name:接口或元素的名称。# Parent:父接口的名称(仅适用于元素)。# Datatype:元素数据类型。可以是另一个接口,格式为Bus: InterfaceName # Dimensions:元素的尺寸。# Units:元素的单位属性。# Minimum:元素的最小值。# Maximum:元素的最大值。

步骤1。实例化ModelBuilder

实例化ModelBuilder使用配置文件名称初始化。

[stat,fa] = fileattrib(pwd);如果~足总。使用rWrite disp(此脚本必须在可写目录中运行);返回结束

指定要构建的模型的名称。

modelName =“scExampleModelBuilder”

指定概要文件的名称。

形象=“UAVComponent”

指定要读取体系结构信息的源文件的名称。

architectureFileName =“Architecture.xlsx”

实例化ModelBuilder

builder = systemcomposer.io.ModelBuilder(profile);

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

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

从Excel源文件创建MATLAB®表。

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

readtable从第二行开始读。

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

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

idService = systemcomposer.io.IdService();rowItr =1: nummel (definitionContents(:,1)) parentInterface = definitionContents. parent {rowItr};如果isempty (parentInterface)

对于接口,将接口名称添加到模型构建器中。

interfaceName = definitionContents.Name{rowItr};

获得独特的界面ID

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

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”);

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

datatype = defintioncontents . datatype {rowItr};dimensions = string(defintioncontents . dimensions (rowItr));units = defintioncontents . units (rowItr);

确保构建器实用程序函数的输入始终是字符串。

如果~ischar(units)结束minimum = defintioncontents . minimum {rowItr};maximum = defintioncontents . maximum {rowItr};

使用builder.addElementInInterface在接口中添加具有属性的元素。

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

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

体系结构规范由MATLAB表从Excel源文件创建。

excelContents = readtable(architectureFileName);

遍历表中的每一行。

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

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

class = excelContents.Class(rowItr);Parent = excelContents.Parent(rowItr);Name = excelContents.Element{rowItr};

填充表的内容。

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

根ID默认设置为零。

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

使用builder.addComponent添加组件。

builder.addComponent(名称、ID parentID);

读取属性值。

kind = excelContents.Kind{rowItr};domain = excelContents.Domain{rowItr};

使用builder.setComponentProperty设置原型和属性值。

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

在本例中,端口名称和父组件名称的连接被用作生成端口唯一id的键。

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

对于根体系结构上的端口,列表假设为0

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

使用builder.addPort添加端口。

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

InterfaceName与该端口相连的接口名称。

interfaceName = excelContents.InterfaceName{rowItr};

获取接口ID。

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

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

使用builder.addInterfaceToPort将接口映射到端口。

builder.addInterfaceToPort (interfaceID portID);

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

connectedTo = excelContents.ConnectedTo{rowItr};

格式为:

(DestinationComponentName:: DestinationPortName)

对于本例,将当前端口视为连接的源。

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

获取连接端口的端口号。

本例中,端口ID由端口名称和父组件名称组合而成。如果已生成端口号,则getID函数返回与输入键相同的ID。

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

填充连接表。

sourcePortID = portID;destPortID = connectedPortID;

使用builder.addConnection添加连接。

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

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

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

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

清理工件。

清理

The MathWorks, Inc.版权所有

另请参阅

||

相关的话题