Script not working

Jan 0 Reputation points
2024-05-14T07:33:46.9533333+00:00

Hello, its my first time here in this forum, i work with factory talk optix software to programe HMI it support .net am not familiar with c# but i asked chatgbt about to create i have no errors after Build but nothing is happens am tring to check if var1 is =="3" change to "10" otherwise return var1 value var1 is string datatype my code

#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

{

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

}

}

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,472 questions
{count} votes