it’s my first time here in this forum. I work with FactoryTalk Optix software to program HMI. It supports .NET. I’m not familiar with C#, but I asked ChatGPT about it to create. I have no errors after building, but nothing happens. I’m trying to check if var1 is equal to “3” then change it to “10”, otherwise return the value of var1. Var1 is of string datatype. Here’s 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
{
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
}
}
- No errors
- The path is correct to the corresponding variable
- Tried to change the initial value of var1 to 3 or Null nothing happend
Garo Kajalyan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.