You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

FactoryTalk Optix中.NET逻辑代码无报错但未执行问题求助

FactoryTalk Optix .Net逻辑代码未执行预期操作

首次在论坛发帖,使用FactoryTalk Optix进行HMI编程,该软件支持.NET。因不熟悉C#,通过ChatGPT生成了一段代码,编译后无报错,但代码未执行任何预期操作。需求为:当字符串类型变量var1的值等于"3"时,将其修改为"10";否则保留原变量值。

使用的代码如下:

#region Using directives

using System;
using UAManagedCore;
using OpcUa = UAManagedCore.OpcUa;
using FTOptix.HMIProject;
using FTOptix.Alarm;
using FTOptix.UI;
using FTOptix.NativeUI;
using FTOptix.NetLogic;
using FTOptix.Recipe;
using FTOptix.SQLiteStore;
using FTOptix.Store;
using FTOptix.RAEtherNetIP;
using FTOptix.DataLogger;
using FTOptix.CoreBase;
using FTOptix.CommunicationDriver;
using FTOptix.Retentivity;
using FTOptix.System;
using FTOptix.EventLogger;
using FTOptix.SerialPort;
using FTOptix.Core;

#endregion

public class RuntimeNetLogic1 : BaseNetLogic
{

//Copy
    public override void Start()
    {
        // Get the variable
        IUAVariable var1 = Project.Current.GetVariable("Model/var1");
        // Check if var1 exists and its value is a string
        if (var1 != null && var1.DataType == OpcUa.DataTypes.String)
        {
            // Convert the value to string
            string var1Value = var1.Value.ToString();

            // Check if var1Value is "3"
            if (var1Value == "3")
            {
                // If var1Value is "3", change it to "10"
                var1.SetValue("10");
            }
            else
            {
                // Log the value of var1
                Log.Info("Value of var1: " + var1Value);
            }
        }
        else
        {
            // Log a message indicating that var1 is not a valid string variable
            Log.Warning("Variable var1 does not exist or is not a string type.");
        }
    }

    public override void Stop()
    {
        // Insert code to be executed when the user-defined logic is stopped
    }
}

已排查情况:

  • 编译无错误
  • 变量路径正确
  • 修改var1初始值为3或Null均无效果

内容的提问来源于stack exchange,提问作者Garo Kajalyan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 21:40:12