主要内容

systemcomposer.arch.ComponentPort

类,表示组件的输入和输出端口

描述

ComponentPort.类表示组件的输入和输出端口。这个类继承自systemcomposer.arch.BasePort.这个类派生自systemcomposer.arch.Element

创建

组件端口是通过在组件的体系结构上创建体系结构端口来构造的。

addPort (compObj。架构,“portName”“在”);compPortObj = getPort (compObj,“portName”);

属性

全部展开

端口的名称,指定为字符向量。

例子:“portName”

数据类型:char

端口方向,指定为带值的字符向量“输入”“输出”

数据类型:char

与端口相关联的接口名称,指定为字符向量。

数据类型:char

与端口关联的接口,指定为systemcomposer.interface.SignalInterface对象。

端口连接器,指定为数组systemcomposer.arch.Connector对象。

端口是否有连接,逻辑1指定(真正的)或0().

数据类型:逻辑

拥有端口的组件,指定为systemcomposer.arch.Architecture对象。

映射到端口的组件中的体系结构端口,指定为asystemcomposer.arch.architionPort.对象。

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

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

数据类型:char

唯一的外部标识符,指定为字符向量。外部ID将在元素的整个生命周期和所有保存uuid.

数据类型:char

组件端口的父模型,指定为systemcomposer.arch.Model对象。

金宝appSimulink句柄用于组件端口,指定为数值。这个属性对于几个与Simulink相关的工作流和使用Simulink需求api金宝app是必要的。

例子:处理=得到(对象,“SimulinkHan金宝appdle”)

数据类型:

金宝appSimulink组件端口的父模型句柄,指定为数值。这个属性对于几个与Simulink相关的工作流和使用Simulink需求api金宝app是必要的。

例子:处理=得到(对象,“SimulinkMod金宝appelHandle”)

数据类型:

对象的功能

setName 设置端口名称
setInterface 设置接口为端口
CreateAnonyousInterface. 为端口创建和设置匿​​名界面
applyStereotype 将原型应用到架构模型元素
getstereotypes. 获取应用于架构模型元素的原型
removeStereotype 从模型元素中移除原型
连接 创建架构模型连接
setProperty 设置应用于元素的原型对应的属性值
getProperty. 获取应用于元素的原型对应的属性值
getPropertyValue 获得建筑产权的价值
getEvaluatedPropertyValue 从组件获取属性的评估值
getStereotypeProperties 获取元素上的构造型属性名
摧毁 删除模型元素

例子

全部折叠

此示例显示如何使用System Composer™API构建架构模型。

准备工作空间

从工作区中清除所有概要文件。

systemcomposer.profile.Profile.closeAll;

建立一个模型

要构建模型,需要添加一个带有接口和接口元素的数据字典,然后添加组件、端口和连接。在构建模型之后,您可以创建自定义视图来关注特定的关注点。您还可以查询模型,根据您指定的条件收集不同的模型元素。

添加组件、端口和连接

创建模型并提取其架构。

模型= systemcomposer.createModel ('mobilerobotapi');拱= model.Architecture;

创建数据字典,添加接口。将接口链接到模型。

字典= systemcomposer.createDictionary ('sensorinterfaces.sldd');界面= addInterface(字典,“GPSInterface”);interface.addelement(“质量”);LinkDictionary(模型,'sensorinterfaces.sldd');

添加组件、端口和连接。将接口设置为稍后将连接的端口。

组件= addComponent(拱门,{“传感器”“规划”“运动”});SensorPorts = Addport(组件(1).Architecture,{'motiondata'“SensorData”},{“在”“出”});sensorPorts (2) .setInterface(接口);planningPorts = addPort(组件(2)。架构,{“命令”“SensorData1”“MotionCommand”},{“在”“在”“出”});Plannports(2).setInterface(接口);MotionPorts = Addport(组件(3).architecture,{“MotionCommand”'motiondata'},{“在”“出”});

使用接口规则连接组件。此规则在共享相同接口的组件上连接端口。

c_sensorData =连接(拱门,组件(1),组件(2),'规则'“接口”);c_motiondata = connect(arch,组件(3),组件(1));c_motioncommand = connect(arch,组件(2),组件(3));

保存数据字典

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

dictionary.save ();

添加和连接架构端口

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

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

连接命令需要组件端口作为参数。获取部件端口并连接:

compPort = getPort(组件(2),“命令”);c_command = Connect(Archport,Compport);

保存模型。

保存(模型)

打开模型

Open_System(GCS);

通过pressıng安排布局ctrl + shift + a或者使用以下命令:

金宝appSimulink.BlockDiagram.arrangeSystem ('mobilerobotapi');

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

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

创建概要文件并添加原型

创建配置文件。

形象= systemcomposer.createProfile (“GeneralProfile”);

创建一个应用于所有元素类型的原型:

elemSType = addStereotype(概要文件,“projectElement”);

为不同类型的组件创建原型。这些类型由设计需求决定,并由您自行决定:

pCompSType = addStereotype(概要文件,'LeatherComponent'“AppliesTo”“组件”);sCompSType = addStereotype(概要文件,“softwareComponent”“AppliesTo”“组件”);

为连接创建一个模板:

sConnSType = addStereotype(概要文件,“standardConn”“AppliesTo”“连接器”);

添加属性

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

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

保存配置文件

保存(配置文件);

将配置文件应用于模型

将概要文件应用到模型:

applyProfile(模型,“GeneralProfile”);

将原型应用于组件。有些组件是物理组件,有些是软件组件。

applyStereotype(组件(2),“GeneralProfile.softwareComponent”) applyStereotype(组件(1),“GeneralProfile.physicalComponent”(3) applyStereotype(组件),“GeneralProfile.physicalComponent”

将连接器刻板印象应用于所有连接:

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

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

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

为每个组件设置属性:

setProperty(组件(1),“GeneralProfile.projectElement.ID”“001”);setProperty(组件(1),“GeneralProfile.projectElement.Description”“‘所有传感器的中央单元’”);setProperty(组件(1),“GeneralProfile.physicalComponent.Cost”'200');setProperty(组件(1),“GeneralProfile.physicalComponent.Weight”“450”);setProperty(组件(2),“GeneralProfile.projectElement.ID”“002”);setProperty(组件(2),“GeneralProfile.projectElement.Description”“电脑”计划);setProperty(组件(2),“GeneralProfile.softwareComponent.develCost”“20000”);setProperty(组件(2),“GeneralProfile.softwareComponent.develTime”'300');setProperty(组件(3),“GeneralProfile.projectElement.ID”“003”);setProperty(组件(3),“GeneralProfile.projectElement.Description”“电机及电机控制器”);setProperty(组件(3),“GeneralProfile.physicalComponent.Cost”“4500”);setProperty(组件(3),“GeneralProfile.physicalComponent.Weight”“2500”);

设置连接的属性相同:

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

添加层次结构

添加两个组件控制器范围运动组件。定义的端口。应用连接器构造型将它们与体系结构以及彼此连接起来。体系结构图中的层次结构创建了额外的详细级别,指定组件在内部的行为方式。

motionArch =组件(3).Architecture;运动= motionArch.addComponent ({“控制器”“范围”});controllerPorts = addPort(运动(1)。架构,{“controlIn”“controlOut”},{“在”“出”});ControllerCompportin = Motion(1).getPort(“controlIn”);(1) .getPort (controllerCompPortOut =运动“controlOut”);scopeports = Addport(Motion(2).Architecture,{“scopeIn”“scopeOut”},{“在”“出”});(2) .getPort (scopeCompPortIn =运动“scopeIn”);scopecompportout = motion(2).getport(“scopeOut”);c_planningController =连接(motionPorts (1) controllerCompPortIn);c_planningScope =连接(scopeCompPortOut motionPorts (2));c_planningConnect =连接(controllerCompPortOut scopeCompPortIn,“GeneralProfile.standardConn”);

保存模型。

保存(模型)

通过pressıng安排布局ctrl + shift + a或者使用以下命令:

金宝appSimulink.BlockDiagram.arrangeSystem ('mobilerobotapi / motion');

创建模型引用

模型引用对于分层组织大型模型非常有用,并允许您一次性定义体系结构或行为并重用它。当一个组件引用另一个模型时,该组件上的任何现有端口都将被删除,被引用模型上存在的端口将出现在该组件上。

创建一个新的System Composer模型。转换传感器组件转换为引用组件以引用新模型。在。上添加其他端口传感器组件,您必须更新引用的模型mobileSensor

newModel = systemcomposer.createModel ('mobilesensor');newArch = newModel.Architecture;newComponents = addComponent (newArch,“ElectricSensor”);保存(newModel);linkToModel(组件(1),'mobilesensor');

将原型应用到链接的引用模型的体系结构和组件。

referenceModel = get_param ('mobilesensor'“SystemComposerModel”);referenceModel.applyProfile (“GeneralProfile”);referenceModel.Architecture.applyStereotype (“GeneralProfile.softwareComponent”);batchapplystereotype(ReferenceModel.architecture,“组件”“GeneralProfile.projectElement”

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

SensorPorts = Addport(组件(1).Architecture,{'motiondata'“SensorData”},{“在”“出”});sensorPorts (2) .setInterface(接口)连接(拱、组件(1),(2)组件,'规则'“接口”);连接(拱门,组件(3),组件(1));

保存模型。

保存(ReferenceModel)保存(型号)

制作一个变型组件

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

[variantComp, choice1] = makeVariant(组件(2));

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

choice2 = addChoice (variantComp, {'策略'},{'策略'});

创建所需的端口策划

setActiveChoice(VariantComp,Choice2)Cransaltports = Addport(Choice2.Architecture,{“命令”“SensorData1”“MotionCommand”},{“在”“在”“出”});planningAltPorts (2) .setInterface(接口);

使策划活跃的变体。

setActiveChoice (variantComp'策略'

通过pressıng安排布局ctrl + shift + a或者使用以下命令:

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

保存模型。

保存(模型)

清理

取消注释以下代码,并运行以清理由本示例创建的工件:

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

更多关于

全部展开

介绍了R2019a