主要内容

导入系统编写器体系结构使用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);如果~足总。UserWrite disp (此脚本必须在可写目录中运行);返回结束要构建的模型的名称。modelName =“scExampleModelBuider”%配置文件名称。形象=“UAVComponent”%用于读取体系结构信息的源文件的名称。architectureFileName =“Architecture.xlsx”实例化ModelBuilder。builder = systemcomposer.io.ModelBuilder(profile);

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

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

从Excel源文件创建MATLAB®表。

opts = detectImportOptions(“DataDefinitions.xlsx”);选择。DataRange =“A2”% force readtable从第二行开始读取。definitionContents =可读(“DataDefinitions.xlsx”、选择);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 (interfaceName interfaceID);其他的对于元素,读取元素属性并将元素添加到%父接口。elementName = definitionContents.Name{rowItr};interfaceID = idService.getID(“接口”, parentInterface);% ElementID在接口中是唯一的。在ID的开头附加'E'以保持一致性。生成的IDinput元素在作为容器的父接口名称中是唯一的。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函数用于在界面中添加带有属性的元素。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(“薪酬”、名称);% Root ID默认为0。如果比较字符串(父,“scExampleSmallUAV”) parentID =“0”其他的parentID = idService.getID(“薪酬”、家长);结束用于添加组件的生成器实用程序函数。builder.addComponent(名称、ID parentID);读取属性值kind = excelContents.Kind{rowItr};domain = excelContents.Domain{rowItr};% *构建器设置原型和属性值。builder.setComponentProperty (ID、“StereotypeName”“UAVComponent。PartDescriptor”“ModelName”、善良、“制造商”域);其他的在本例中,端口名称和父组件名称的连接%作为键,用于为端口生成唯一的id。portID = idService.getID(“端口”strcat(名称、父));用于根体系结构上的端口。compID假设为0。如果比较字符串(父,“scExampleSmallUAV”) compID =“0”其他的compID = idService.getID(“薪酬”、家长);结束%生成器实用程序函数添加端口。构建器。addPort(名称、类、portID列表);% InterfaceName指定与端口相连的接口名称。interfaceName = excelContents.InterfaceName{rowItr};获取接口ID。getID()将返回相同的id%,在步骤2中添加接口时生成。interfaceID = idService.getID(“接口”, interfaceName);%生成器将接口映射到端口。builder.addInterfaceToPort (interfaceID portID);读取connectedTo信息以建立之间的连接%的组件。connectedTo = excelContents.ConnectedTo{rowItr};% connectedTo的格式为:% (DestinationComponentName:: DestinationPortName)。对于本例,将当前端口视为连接的源。如果~isempty(connectedTo) = idService.getID(“连接”,与);分裂=分裂(connectedTo,“::”);获取连接端口的端口ID。%本例中端口号为连接方式生成%端口名称和父组件名称。如果端口号为alreadygetID()函数为输入键返回相同的id。connectedPortID = idService.getID(“端口”strcat(分裂(2)将(1)));%使用构建器填充连接表。sourcePortID = portID;destPortID = connectedPortID;%生成器来添加连接。builder.addConnection(与、connID sourcePortID destPortID);结束结束结束

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

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

关闭模式

bdclose (modelName)

另请参阅

||

相关的话题