API for keeping field variables synchronized

Introduction

To keep project variables referenced to field variables of interest synchronized, it is necessary to add these project variables in a RemoteVariableSynchronizer object, whose constructor and related class methods are described below.

The object is necessary to implement C# logics related to the value change of field variables (see IUAVariable.VariableChange).

RemoteVariableSynchronizer() constructor

Create a RemoteVariableSynchronizer object, it can contain a list of project variables to be kept synchronized with the related field variables.

public RemoteVariableSynchronizer()

Example

Below is an example in which a variableSynchronizer object is created to keep the value of a Speed project variable synchronized with the value of a field variable that identifies the speed of a motor. The project variable, represented by the motorSpeed object, is added to the variableSynchronizer object via the Add() method (see RemoteVariableSynchronizer.Add(variables)).

When the field variable changes value, the motorSpeed_VariableChange method is executed. When the value of motorSpeed, i.e. of the field variable, is greater than 200, a warning message is generated.

In the Stop() method, the termination of the synchronization when the NetLogic parent node is removed is effected by invoking the Dispose() method.

Important

the RemoteVariableSynchronizer object must be declared as a class member within the NetLogic.

public class SpeedCheckerLogic : BaseNetLogic
{
    public override void Start()
    {
        motorSpeed = LogicObject.Owner.GetVariable("Speed");

        variableSynchronizer = new RemoteVariableSynchronizer();
        variableSynchronizer.Add(motorSpeed);
        variableSynchronizer.motorSpeed.VariableChange += motorSpeed_VariableChange;
   }

   private void motorSpeed_VariableChange(motorSpeed)
   {
       if (motorSpeed > 200)
       {
            Log.Warning("Speed limit reached!");
       }
   }

   private IUAVariable motorSpeed;
   private RemoteVariableSynchronizer variableSynchronizer;

RemoteVariableSynchronizer.Add(variables)

Depending on the overload, adds a variable or a list of variables to the RemoteVariableSynchronizer object on which it is invoked.

void public void Add(IUAVariable variables);
void public void Add(RemoteVariable variables);
void public void Add(IEnumerable<IUAVariable> variables);
void public void Add(IEnumerable<RemoteVariable> variables);

Argument

variables IUAVariable

IUAVariable C# object to add to the object on which the method is invoked.

variables RemoteVariable

RemoteVariable C# object, which identifies a cell of a one-dimensional or multidimensional array, to be added to the object on which the method is invoked.

variables IEnumerable<IUAVariable>

IUAVariable list to be added to the object on which the method is invoked.

variables IEnumerable<RemoteVariable>

RemoteVariable list to be added to the object on which the method is invoked.

Examples

Below is an example in which a variable speed is added to the variableSynchronizer object.

var speed = LogicObject.Owner.GetVariable("Speed");
var variableSynchronizer = new RemoteVariableSynchronizer();
variableSynchronizer.Add(speed);

Below is an example in which the index variable 10 is added to the variableSynchronizer object within the arrayVariable array.

var arrayVariable = LogicObject.Owner.GetVariable("ArrayVariable");
var variableSynchronizer = new RemoteVariableSynchronizer();
variableSynchronizer.Add(new RemoteVariable(arrayVariable, 10));

Below is an example in which the index variable 10.5 is added to the variableSynchronizer object within the scalarVariable multidimensional array.

var scalarVariable = LogicObject.Owner.GetVariable("ScalarVariable");
var variableSynchronizer = new RemoteVariableSynchronizer();
variableSynchronizer.Add(new RemoteVariable(scalarVariable, new uint[] { 10,5 }));

RemoteVariableSynchronizer.Remove(variables)

Depending on the overload, removes a variable or a list of variables from the RemoteVariableSynchronizer object on which it is invoked.

void public void Remove(IUAVariable variables);
void public void Remove(RemoteVariable variables);
void public void Remove(IEnumerable<IUAVariable> variables);
void public void Remove(IEnumerable<RemoteVariable> variables);

Argument

variables IUAVariable

IUAVariable C# object to remove from the object on which the method is invoked.

variables RemoteVariable

RemoteVariable C# object, which identifies a cell of a one-dimensional or multidimensional array, to be removed from the object on which the method is invoked.

variables IEnumerable<IUAVariable>

IUAVariable list to be removed from the object on which the method is invoked.

variables IEnumerable<RemoteVariable>

RemoteVariable list to be removed from the object on which the method is invoked.

Examples

Below is an example in which a variable speed is removed from the variableSynchronizer object

variableSynchronizer.Remove(speed);

Below is an example in which the 10``index variable is removed from the ``variableSynchronizer object within the arrayVariable array.

variableSynchronizer.Add(new RemoteVariable(arrayVariable, 10));

Below is an example in which the 10.5``index variable is removed from the ``variableSynchronizer object within the scalarVariable multidimensional array.

variableSynchronizer.Add(new RemoteVariable(scalarVariable, new uint[] { 10,5 }));

See also

Related concepts

Field variables

Related APIs

API for reading/writing of field variables