Variables and objects generic eventsΒΆ

Introduction

The events displayed by the IUAVariable and IUAObject classes are described below.

IUAVariable.VariableChange

This occurs when the value of the project variable that the IUAVariable C# object references changes.

Important

if the project variable refers to a field variable, the event is generated only if the project variable is kept synchronized with the field through a RemoteVariableSynchronizer object (see RemoteVariableSynchronizer() constructor), unless a link to a Tag variable from a graphical object, Data logger object, alarm or Recipe Schema object already exists in Q Studio. In this case, in a NetLogic it is possible to subscribe the change value method directly to the linked Tag variable.

event EventHandler<VariableChangeEventArgs> VariableChange;

Event handler

The VariableChange event handler, whose signature is given below, makes it possible to subscribe a method to the event of the same name.

public delegate void VariableChange(object sender, VariableChangeEventArgs e);

Event handler arguments

sender object

C# object corresponding to the origin node of the event.

e VariableChangeEventArgs

C# object that contains the following properties:

  • variable IUAVariable: project variable that generated the event

  • newValue UAValue: new value of the variable

  • oldValue UAValue: previous value of the variable

  • indexes uint[]: (only for arrays) indexes of the array cells in which the value has changed.

    Note

    the property is empty if the value in each cell changes or if the project variable is scalar.

Example

Below is an example in which the Variable1_VariableChange method is executed each time the project variable Variable1 changes value.

public override void Start()
{
    var variable1 = Project.Current.GetVariable("Model/Variable1");
    variable1.VariableChange += Variable1_VariableChange;
}

private void Variable1_VariableChange(object sender, VariableChangeEventArgs e)
{
    var label1 = Owner.Get<Label>("Label1");
    label1.Text = "Value of " + e.Variable.BrowseName + " changed from " + e.OldValue + " to " + e.NewValue;
}

IUAObject.UAEvent

This occurs when the project object to which the IUAObject C# object refers generates any OPC UA event.

event EventHandler<UAEventArgs> UAEvent;

Event handler

public delegate void UAEvent(object sender, UAEventArgs e);

Event handler arguments

sender object

C# object corresponding to the object of the project origin of the event.

e UAEventArgs

C# object that contains the following properties:

  • EventType IUAObjectType: node of the type of event generated

  • Arguments UAEventArgumentList: C# object that contains the arguments of the generated event

Example

Below is an example in which the Button1_UAEvent method is executed each time the Button1 project button generates any event (for example, OnMouseClick, OnMouseDown or OnMouseUp).

public override void Start()
{
    var button1 = Owner.Get<Button>("Button1");
    button1.UAEvent += Button1_UAEvent;
}

private void Button1_UAEvent(object sender, UAEventArgs e)
{
    var label1 = Owner.Get<Label>("Label1");
    var button1 = (Button)sender;
    label1.Text = "Event on " + button1.BrowseName + " of type " + e.EventType.BrowseName + " , ";
}

See also

Related procedures

Subscribe methods to events