Skip to content

Instantly share code, notes, and snippets.

@AlessioForafo
AlessioForafo / StartStopeNode.cs
Last active September 26, 2025 09:52
Stop and start of a node, such as a driver station
//ATTENTION: this is not an offcial method and it could be NOT work in future release of FT Optix
private void RestartNode(IUANode node)
{
if (node is IUAObject nodeObject && node.Status == NodeStatus.Started)
{
nodeObject.Stop();
nodeObject.Start();
}
}
@AlessioForafo
AlessioForafo / SystemShutDown.cs
Created September 24, 2025 09:34
Execute PC shut down (only for WIndows systems)
[ExportMethod]
public void SystemShutDown()
{
var psi = new ProcessStartInfo("shutdown", "/s /t 0");
psi.CreateNoWindow = true;
psi.UseShellExecute = false;
Process.Start(psi);
}
@AlessioForafo
AlessioForafo / Add_Remove_Users_Observer.cs
Created September 16, 2025 07:06
Example to monitor adding or removing of users at runtime. Can be modify to monitor also other folder in the project
//RuntimeNetLogic per monitorare l'aggiunta/rimozione degli utenti dalla cartella Security/Users
//Il NetLogic può essere posizionato nella cartella NetLogic del progetto
//Nell'esempio viene stampato nei log un messaggio ad ogni aggiunta/rimozione di un utente
//Utile ad esempio per monitorare l'aggiunta/rimozione di un utente di dominio/windows
//L'esempio può essere adattato per sottoscriversi all'aggiunta/rimozione di nodi in qualsiasi cartella di progetto
public class CreazioneUtenti : BaseNetLogic
{
private IEventRegistration userCreationObserver;
@AlessioForafo
AlessioForafo / Node_Reference.cs
Created July 31, 2025 14:05
API to get the type from which is derivated a screen object
var message = LogicObject.GetVariable("Variable1");
//API to find the object type from which is derivated the object instanced in the page
var appoggio = Owner.Refs.GetNode(OpcUa.ReferenceTypes.HasTypeDefinition);
//API to get the node path in the project's tree
message.Value = Log.Node(appoggio);
//----Result:
//----Root/Objects/NewHMIProject9/UI/Screens/Screen1
@AlessioForafo
AlessioForafo / ModifyExistingRecipeSchema.cs
Created May 7, 2025 06:52
DesignTime NetLogic for adding columns to an existing recipe schema
[ExportMethod]
public void ModifyRecipeSchema()
{
IUAVariable var2 = Project.Current.GetVariable("Model/Variable2");
IUAVariable var3 = Project.Current.GetVariable("Model/Variable3");
RecipeSchema recipeSchema = Project.Current.Get<RecipeSchema>("Recipes/RecipeSchema1");
//creazione e aggiunta variabili nel Recipe Schema EditModel
IUAObject editModelObj = recipeSchema.GetObject("EditModel");
@AlessioForafo
AlessioForafo / ElencoAllarmiAttivi.cs
Created March 27, 2025 15:09
Stampa su file di log l'elenco degli allarmi attivi
[ExportMethod]
public void AllarmiAttivi()
{
var retainedAlarmsObject = LogicObject.Context.GetNode(FTOptix.Alarm.Objects.RetainedAlarms);
// Get the object containing the actual list of alarms
var localizedAlarmsObject = retainedAlarmsObject.GetVariable("LocalizedAlarms");
var localizedAlarmsNodeId = (NodeId)localizedAlarmsObject.Value;
IUANode localizedAlarmsContainer = null;
if (localizedAlarmsNodeId?.IsEmpty == false)
localizedAlarmsContainer = LogicObject.Context.GetNode(localizedAlarmsNodeId);
@AlessioForafo
AlessioForafo / CreateChangedVariableMethod.cs
Created March 3, 2025 11:17
Example to create a changed event method from a DesignTimeNetlogic
[ExportMethod]
public void Method1()
{
IUAVariable targetVariable = null;
try
{
targetVariable = InformationModel.GetVariable(LogicObject.GetVariable("VariableToAddChangeMethod").Value);
}
catch
{
@AlessioForafo
AlessioForafo / CreateNetLogic.cs
Created February 26, 2025 13:53
Create a RuntimeNetLogic from a DesignTimeNetLogic
#region Using directives
using FTOptix.Core;
using FTOptix.HMIProject;
using FTOptix.NetLogic;
using System.IO;
using UAManagedCore;
using OpcUa = UAManagedCore.OpcUa;
#endregion
public class BlinkerCreator : BaseNetLogic {
@AlessioForafo
AlessioForafo / CloseDropDownButton.cs
Created February 6, 2025 13:03
Close drop down button from C#
var drop = (DropDownButton)Owner;
drop.ExecuteMethod("Close");
@AlessioForafo
AlessioForafo / USBCheckWindows.cs
Created February 3, 2025 17:00
USB Check (Windows)
private PeriodicTask task;
public override void Start()
{
task = new PeriodicTask(CheckUSB, 1000, LogicObject);
task.Start();
}
private void CheckUSB()
{