创建具有自定义行为的对象
通过对两个整数求和的简单 NetLogic 创建对象类型。
先决条件
设置默认外部代码编辑器。请参见设置默认代码编辑器。
- 创建具有自定义行为的对象类型
- 在项目视图中,右键单击模型,然后选择 。在模型下,将显示对象1。
- 将光标悬停在对象1上,选择并输入MyObject。
- 右键单击MyObject,然后选择 。MyObject更改为MyObject (type)。
- 右键单击MyObject (type),然后选择添加自定义行为。
- 右键单击MyObject (type),然后选择打开 .NET 代码编辑器 (外部)。外部代码编辑器将打开。
- 在外部代码编辑器中,进行以下编辑:#region Using directives using System; using UAManagedCore; using OpcUa = UAManagedCore.OpcUa; using FTOptix.UI; using FTOptix.HMIProject; using FTOptix.NativeUI; using FTOptix.Retentivity; using FTOptix.CoreBase; using FTOptix.Core; using FTOptix.NetLogic; #endregion [CustomBehavior] public class ObjectBehavior : BaseNetBehavior { public override void Start() { // Insert code to be executed when the user-defined behavior is started } public override void Stop() { // Insert code to be executed when the user-defined behavior is stopped }[ExportMethod] public void sumNumbers(int a, int b, out int c){ c=a+b;} #region Auto-generated code, do not edit! protected new Object Node => (Object)base.Node; #endregion }
- 保存 NetLogic 代码并关闭外部编辑器。
- 在FactoryTalk Optix Studio中,右键单击模型,然后选择 。
MyObject1
将显示在模型
下。提供反馈