Robotstudio软件二次开发:基于C#语言的Smart组件开发基础

Robotstudio软件除了支持Add-Ins插件的二次开发以外 , 还支持Smart组件的二次开发 。 开发语言同样是基于.NET框架的C#语言或VB语言 。 Smart组件是Robotstudio软件中实现高级仿真功能的智能组件 , 软件自身提供的Smart组件包含信号与属性、传感器、建模、运动等子对象组件 。 当软件自带的Smart组件无法满足仿真需求的时候 , 我们就可以通过对Robotstudio软件的二次开发 , 开发出满足需求新的Smart组件 。 本期 , 再来为大家介绍一下Robotstudio软件中Smart组件的开发方法 , 我们还是从实现“Hello Word!”消息输出开始 。
Robotstudio软件版本:RobotStudio 6.08
SDK版本:RobotStudio SDK.6.08
开发软件版本:Microsoft Visual Studio Professional 2019
一、开发环境配置开发环境的搭建比较简单 , 在上一篇文章《基于C#语言的Robotstudio软件二次开发基础》中已经介绍过了 , 小伙伴可在文章列表中查看一下 , 这里不再赘述 。
二、开发项目创建1.创建新项目 , 项目模板选择ABB机器人提供的Smart组件二次开发模板“Robotstudio 6.08 Smart Component” 。
Robotstudio软件二次开发:基于C#语言的Smart组件开发基础文章插图
2.配置新项目时可以对项目进行命名 , 修改项目保存位置 。
Robotstudio软件二次开发:基于C#语言的Smart组件开发基础文章插图
3.项目创建成功后 , 软件代码编辑区会自动打开SmartComponent1.xml、CodeBehind.cs两个文件 。 若是自动打开 , 可以在右侧的“解决方案资源管理器”对话框中双击两个相应的项目文件打开 。
Robotstudio软件二次开发:基于C#语言的Smart组件开发基础文章插图
说明:自动生成的*.xml代码编辑文件主要用于Smart组件的功能属性设置 , 如Smart组件的外观、标题、离散变量与连续变量的属性等 , 也可以认为是Smart组件前台开发 。 *.cs代码编辑文件主要用于Smart组件的功能实现 , 如信号置位后的输出响应等 , 也可以认为是Smart组件的后台开发 。
三、代码编写【Robotstudio软件二次开发:基于C#语言的Smart组件开发基础】1.在SmartComponent1.xml代码编辑窗口中 , 删除下图中红色方框中的代码 , 并修改箭头所指位置处的“SampleSignal”为“Button” 。 红色方框中的代码分别是设置Snart组件的连续变量属性、绑定信息属性以及图形化属性设置 , 本例暂时不需要 , 因此删除 。
Signals用于设置Smart组件的信号属性 , 代码的含义:设置I/O信号名称为SampleSignal , 信号类型为数字量输入 。
Robotstudio软件二次开发:基于C#语言的Smart组件开发基础文章插图
SmartComponent1.xml完整程序代码如下所示:
President2.CodeBehind.cs代码编辑窗口中 , 同样删除下图红色方框中的代码 , 然后在红色箭头所指位置处编写如下代码:
Robotstudio软件二次开发:基于C#语言的Smart组件开发基础文章插图
CodeBehind.cs完整代码如下所示:
using System;using System.Collections.Generic;using System.Text;using ABB.Robotics.Math;using ABB.Robotics.RobotStudio;using ABB.Robotics.RobotStudio.Stations;namespace SmartComponent1{////// Code-behind class for the SmartComponent1 Smart Component.////// /// The code-behind class should be seen as a service provider used by the/// Smart Component runtime. Only one instance of the code-behind class/// is created, regardless of how many instances there are of the associated/// Smart Component./// Therefore, the code-behind class should not store any state information./// Instead, use the SmartComponent.StateCache collection./// public class CodeBehind : SmartComponentCodeBehind{////// Called when the value of an I/O signal value has changed.//////Component that owns the changed signal. ///Changed signal. public override void OnIOSignalValueChanged(SmartComponent component, IOSignal changedSignal){if (changedSignal.Name == "Button"){Logger.AddMessage(new LogMessage("Hello World!"));}}}}