主要内容

systemcomposer.arch.Component

系统的作曲家组件

描述

一个组件对象表示System Composer™模型中的组件。这个类继承自systemcomposer.arch.BaseComponent。这个类派生自systemcomposer.arch.Element

创建

在体系结构模型中创建组件。

模型= systemcomposer.createModel(“archModel”);Arch = get(模型,“架构”);component = addComponent(arch,“newComponent”);

属性

全部展开

组件的名称,指定为字符向量。

例子:“newComponent”

数据类型:字符

拥有组件的体系结构,指定为systemcomposer.arch.Architecture对象。

定义组件结构的体系结构,指定为systemcomposer.arch.Architecture对象。对于引用不同体系结构模型的组件,此属性返回该模型的根体系结构的句柄。对于变体组件,体系结构是活动变体的体系结构。

组件拥有的体系结构,指定为systemcomposer.arch.Architecture对象。对于引用体系结构的组件,此属性为空。对于可变组件,该属性是单个可变组件所在的体系结构。

组件端口的数组,指定为的数组systemcomposer.arch.ComponentPort对象。

组件端口的数组,指定为的数组systemcomposer.arch.ComponentPort对象。对于引用组件,此属性为空。

组件在画布上的位置,指定为坐标向量,以像素为单位[左上右下]

如果链接组件,则组件引用的模型的名称,指定为字符向量。

数据类型:字符

组件是否是适配器块,指定为逻辑1 (真正的)或0 ()。

数据类型:逻辑

模型组件的通用唯一标识符,指定为字符向量。

例子:91 d5de2c-b14c-4c76-a5d6-5dd0037c52df

数据类型:字符

唯一的外部标识符,指定为字符向量。外部ID将在模型组件的整个生命周期中以及通过保留模型的所有操作中保留UUID

数据类型:字符

组件的父系统编写器模型,指定为systemcomposer.arch.Model对象。

金宝app®组件句柄,指定为a。此属性对于几个与Simulink相关的工作流和使用是必需的金宝app金宝app仿真软件需求™api。

例子:handle = get(object,'金宝appSimulinkHandle')

数据类型:

金宝app组件的父系统编写器模型的Simulink句柄,指定为。此属性对于几个与Simulink相关的工作流和使用是必需的金宝app金宝app仿真软件的需求api。

例子:handle = get(object,'金宝appSimulinkModelHandle')

数据类型:

对象的功能

createArchitectureModel 从组件创建体系结构模型
create金宝appSimulinkBehavior 创建Simul金宝appink行为并链接到组件
createSubsystemBehavior 向组件添加子系统行为
createStateflowChartBehavior 向组件添加状态流程图行为
linkToModel 将组件链接到模型
inlineComponent 从组件中删除参考体系结构或行为
makeVariant 将组件转换为变量选择
isProtected 查找组件引用的模型是否受到保护
isReference 查找组件是否被引用到另一个模型
连接 创建架构模型连接
getPort 从组件获取端口
applyStereotype 将原型应用于架构模型元素
getStereotypes 将原型应用到架构模型的元素上
removeStereotype 从模型元素中移除原型
setProperty 设置与应用于元素的原型相对应的属性值
getProperty 获取与应用于元素的原型相对应的属性值
getPropertyValue 获取建筑属性值
getEvaluatedPropertyValue 从组件中获取属性的评估值
getStereotypeProperties 获取元素上的原型属性名
hasStereotype 查找元素是否应用了原型
hasProperty 查找元素是否具有属性
getQualifiedName 获取模型元素限定名
摧毁 移除模型元素

例子

全部折叠

使用System Composer™以编程方式构建架构模型。

构建模型

要构建模型,请添加一个包含数据接口、数据元素和值类型的数据字典,然后添加组件、端口和连接。为端口指定一个所属接口。在构建模型之后,您可以创建自定义视图来关注特定的考虑事项。您还可以查询模型,根据您指定的标准收集不同的模型元素。

添加组件、端口、连接和接口

创建一个模型并提取其体系结构。

模型= systemcomposer.createModel(“mobileRobotAPI”);arch = model.Architecture;

创建接口数据字典,并添加数据接口。向数据接口添加一个数据元素。将值类型添加到接口数据字典中。将数据元素的类型赋值给值类型。将数据字典链接到模型。

dictionary = systemcomposer.createDictionary(“SensorInterfaces.sldd”);interface = dictionary.addInterface“GPSInterface”);element = interface.addElement()“SignalStrength”);valueType = dictionary.addValueType()“SignalStrengthType”“单位”“数据库”“描述”“GPS信号强度”);element.setType (valueType);linkDictionary(模型,“SensorInterfaces.sldd”);

将更改保存到接口数据字典中。

dictionary.save

在“接口编辑器”中查看接口。

添加组件、端口和连接。将数据接口设置为ports,稍后将进行连接。

componentSensor = addComponent(arch,“传感器”);sensorPorts = addPort(componentSensor.)架构,{“MotionData”“SensorData”}, {“在”“出”});sensorPorts(2).setInterface(interface) componentPlanning = addComponent(arch,“规划”);planningPorts = addPort(componentPlanning. port)架构,{“命令”“SensorData1”“MotionCommand”}, {“在”“在”“出”});planningPorts(2).setInterface(interface) componentMotion = addComponent(arch,“运动”);motionPorts = addPort(componentMotion.)架构,{“MotionCommand”“MotionData”}, {“在”“出”});

上创建一个自有接口“MotionData”端口。在自有数据接口下添加一个自有数据元素。赋值数据元素"旋转”到单位设置为的值类型

ownedInterface = motionPorts(2).createInterface(“DataInterface”);ownedElement = owneinterface . addelement (“旋转”);subInterface = ownedElement.createOwnedType()“单位”“度”);

在“接口编辑器”中查看接口。选择“MotionData”端口运动组件。在接口编辑器中,从字典视图端口接口视图

使用接口规则和默认名称规则连接组件。接口规则用于连接共享同一接口的组件端口。默认情况下,名称规则连接具有相同名称的组件上的端口。

c_sensorData = connect(arch,componentSensor,componentPlanning,“规则”“接口”);c_motionData = connect(arch,componentMotion,componentSensor);c_motionCommand = connect(arch,componentPlanning,componentMotion);

添加并连接架构端口

在体系结构上添加一个体系结构端口。

archPort = addPort(arch,“命令”“在”);

连接命令需要一个组件端口作为参数。获取组件端口,然后连接。

compPort = getPort(componentPlanning;“命令”);c_Command = connect(archPort,compPort);

保存模型。

model.save

打开模型。

systemcomposer.openModel (“mobileRobotAPI”);

通过pressıng安排布局Ctrl + Shift +一个或者使用这个命令。

金宝appSimulink.BlockDiagram.arrangeSystem (“mobileRobotAPI”);

用原型创建和应用概要文件

概要文件是可以应用于任何模型的XML文件。您可以将带有属性的原型添加到概要文件中,然后用特定的值填充属性。与System Composer的内置分析功能一起,构造型可以帮助您优化系统的性能、成本和可靠性。

创建概要文件并添加原型

创建一个概要文件。

profile = systemcomposer.createProfile(“GeneralProfile”);

创建一个适用于所有元素类型的原型。

elemSType = addStereotype(profile,“projectElement”);

为不同类型的组件创建原型。您可以根据自己的设计需要选择这些类型。

pCompSType = addStereotype(profile)“physicalComponent”“AppliesTo”“组件”);sCompSType = addStereotype(profile,“softwareComponent”“AppliesTo”“组件”);

为连接创建一个构造型。

sConnSType = addStereotype(profile,“standardConn”“AppliesTo”“连接器”);

添加属性

向原型添加属性。您可以使用属性来捕获模型元素的元数据,并分析非功能性需求。在导入概要文件的任何模型中,这些属性被添加到原型应用到的所有元素中。

addProperty (elemSType“ID”“类型”“uint8”);addProperty (elemSType“描述”“类型”“字符串”);addProperty (pCompSType“成本”“类型”“双”“单位”“美元”);addProperty (pCompSType“重量”“类型”“双”“单位”‘g’);addProperty (sCompSType“develCost”“类型”“双”“单位”“美元”);addProperty (sCompSType“develTime”“类型”“双”“单位”“小时”);addProperty (sConnSType“unitCost”“类型”“双”“单位”“美元”);addProperty (sConnSType“unitWeight”“类型”“双”“单位”‘g’);addProperty (sConnSType“长度”“类型”“双”“单位”“米”);

保存配置文件

profile.save;

将概要文件应用于模型

将概要文件应用于模型。

applyProfile(模型,“GeneralProfile”);

对组件应用构造型。有些组件是物理组件,而其他组件是软件组件。

applyStereotype (componentPlanning“GeneralProfile.softwareComponent”) applyStereotype (componentSensor“GeneralProfile.physicalComponent”) applyStereotype (componentMotion“GeneralProfile.physicalComponent”

将连接器构造型应用于所有连接。

batchApplyStereotype(拱,“连接器”“GeneralProfile.standardConn”);

将通用元素原型应用于所有连接器和端口。

batchApplyStereotype(拱,“组件”“GeneralProfile.projectElement”);batchApplyStereotype(拱,“连接器”“GeneralProfile.projectElement”);

为每个组件设置属性。

setProperty (componentSensor“GeneralProfile.projectElement.ID”“001”);setProperty (componentSensor“GeneralProfile.projectElement.Description”"所有传感器的中心单元");setProperty (componentSensor“GeneralProfile.physicalComponent.Cost”“200”);setProperty (componentSensor“GeneralProfile.physicalComponent.Weight”“450”);setProperty (componentPlanning“GeneralProfile.projectElement.ID”“002”);setProperty (componentPlanning“GeneralProfile.projectElement.Description”“电脑”计划);setProperty (componentPlanning“GeneralProfile.softwareComponent.develCost”“20000”);setProperty (componentPlanning“GeneralProfile.softwareComponent.develTime”“300”);setProperty (componentMotion“GeneralProfile.projectElement.ID”“003”);setProperty (componentMotion“GeneralProfile.projectElement.Description”电机及电机控制器);setProperty (componentMotion“GeneralProfile.physicalComponent.Cost”“4500”);setProperty (componentMotion“GeneralProfile.physicalComponent.Weight”“2500”);

将连接的属性设置为相同。

connections = c_sensorData c_motionData c_motionCommand c_Command;k = 1:长度(连接数)“GeneralProfile.standardConn.unitCost”“0.2”);setProperty(连接(k),“GeneralProfile.standardConn.unitWeight”“100”);setProperty(连接(k),“GeneralProfile.standardConn.length”“0.3”);结束

添加层次结构

添加两个名为控制器范围运动组件。定义端口。通过应用连接器原型,将组件连接到体系结构并相互连接。架构图中的层次结构创建了额外的详细级别,用于指定组件的内部行为。

motionArch = componentMotion.Architecture;motionController = motionArch.addComponent(“控制器”);controllerPorts = addPort(motionController。架构,{“controlIn”“controlOut”}, {“在”“出”});controllerCompPortIn = motionController.getPort()“controlIn”);controllerCompPortOut = motionController.getPort(“controlOut”);motionScope = motionArch.addComponent(“范围”);scopePorts = addPort(motionScope。架构,{“scopeIn”“scopeOut”}, {“在”“出”});scopecompporttin = motionScope.getPort“scopeIn”);scopeCompPortOut = motionScope.getPort(“scopeOut”);c_planningController = connect(motionPorts(1),controllerCompPortIn);对于输出连接,必须指定接口元素c_planningScope = connect(scopeCompPortOut,motionPorts(2),“DestinationElement”“旋转”);c_planningConnect = connect(controllerCompPortOut, scopecompporttin,“GeneralProfile.standardConn”);

保存模型。

model.save

通过pressıng安排布局Ctrl + Shift +一个或者使用这个命令。

金宝appSimulink.BlockDiagram.arrangeSystem (“mobileRobotAPI /运动”);

创建模型引用

模型引用可以帮助您按层次组织大型模型,并定义架构或行为,以便您可以重用。当组件引用另一个模型时,组件上的任何现有端口都将被删除,而被引用模型上存在的端口将出现在组件上。

创建一个新的System Composer模型。转换传感器组件转换为引用组件以引用新模型。的附加端口传感器组件,则必须更新所引用的模型“mobileSensor”

referenceModel = systemcomposer.createModel(“mobileSensor”);referenceArch = referencmodel . architecture;newComponents = addComponent(referenceArch,“ElectricSensor”);linkDictionary (referenceModel“SensorInterfaces.sldd”);referenceModel。保存linkToModel (componentSensor,“mobileSensor”);

对链接的参考模型的体系结构和组件应用构造型。

referenceModel.applyProfile (“GeneralProfile”);referenceArch.applyStereotype (“GeneralProfile.softwareComponent”);batchApplyStereotype (referenceArch“组件”“GeneralProfile.projectElement”

向参考组件添加端口和连接。

sensorPorts = addPort(componentSensor.)架构,{“MotionData”“SensorData”}, {“在”“出”});sensorPorts (2) .setInterface(接口)连接(拱、componentSensor componentPlanning,“规则”“接口”);连接(拱门,componentMotion componentSensor);

保存模型。

referenceModel。保存model.save

制作可变组件

你可以将规划组件转换为一个变体组件makeVariant函数。原始组件作为可用的变体选择之一嵌入到变体组件中。您可以在变体组件中设计其他变体选择,并切换活动选择。变体组件允许您在架构模型中以编程方式选择行为设计,以执行交易研究和分析。

[variantComp,choice1] = makeVariant(componentPlanning);

添加一个名为PlanningAlt。第二个参数定义名称,第三个参数定义标签。标签标识选择。主动选择是由标签控制的。

选择2 =添加选择(变量,{“PlanningAlt”}, {“PlanningAlt”});

在上面创建必要的端口PlanningAlt

setactivchoice (variantComp,choice2) planningAltPorts = addPort(choice2)架构,{“命令”“SensorData1”“MotionCommand”}, {“在”“在”“出”});planningAltPorts (2) .setInterface(接口)

使PlanningAlt活跃的变种。

setActiveChoice (variantComp“PlanningAlt”

通过pressıng安排布局Ctrl + Shift +一个或者使用这个命令。

金宝appSimulink.BlockDiagram.arrangeSystem (“mobileRobotAPI /规划”);

保存模型。

model.save

清理

取消这段代码的注释,并运行它来清理这个示例创建的工件。

% bdclose(“mobileRobotAPI”)% bdclose(“mobileSensor”)% 金宝appSimulink.data.dictionary.closeAll% systemcomposer.profile.Profile.closeAll%删除(“Profile.xml”)%删除(“SensorInterfaces.sldd”)

更多关于

全部展开

在R2019a中引入