RemoteVariableSynchronizer() constructor
IMPORTANT:
The RemoteVariableSynchronizer allows you to force tags to constantly synchronize with a controller. Constant synchronization is resource-demanding and may significantly impact the performance of a
FactoryTalk Optix Application
and a controller.Rockwell Automation
recommends that you:
- Limit the RemoteVariableSynchronizer usage to a small set of tags. If you need to force read or write a tag in a NetLogic, use IUAVariable.RemoteRead(timeoutMilliseconds) or IUAVariable.RemoteWrite(value, timeoutMilliseconds)instead.
- Add timespan as an argument of the constructor to reduce the communication load. If you do not specify the timespan, tags synchronization runs in a continuous loop. As soon as the last tag values is received, a new synchronization cycle begins with no wait time.
Use the RemoteVariableSynchronizer to keep a specific set of tags synchronized with a controller in a NetLogic. For example, use the RemoteVariableSynchronizer to subscribe to a VariableChange event. See Create a subscription.
Tags are automatically synchronized, so you do not need to use the RemoteVariableSynchronizerTags when:
- Tags are used in the currently displayed interface
- Tags are used in a data logger
- A tag is an input variable for an alarm
- A tag has a ValueChange event
Create a
RemoteVariableSynchronizer
object that can contain a list of project variables to be kept synchronized with the related field variables.public RemoteVariableSynchronizer()
IMPORTANT:
The
RemoteVariableSynchronizer
object must be declared as a class member within the NetLogic.Constructor with the default polling time
In the following example, 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.When the field variable changes its value, the
motorSpeed_VariableChange
method is executed. When the value of motorSpeed
(of the field variable), is greater than 200, a warning message is generated. The default polling time is set to full speed.private void Start() { motorSpeed = LogicObject.Owner.GetVariable("Speed");variableSynchronizer = new RemoteVariableSynchronizer();variableSynchronizer.Add(motorSpeed); motorSpeed.VariableChange += MotorSpeed_VariableChange; } private void MotorSpeed_VariableChange(object sender, VariableChangeEventArgs e) { if (motorSpeed.Value > 200) { Log.Warning("Speed limit reached!"); } } private IUAVariable motorSpeed; private RemoteVariableSynchronizer variableSynchronizer;
In the
Stop()
method, the end of the synchronization when the NetLogic parent node is removed is caused by invoking the Dispose()
method.Constructor with a custom polling time
In the following example, the polling time for
RemoteVariableSynchronizer
is set to 5000
milliseconds.public override void Start() { var variable1 = Project.Current.Get<IUAVariable>("Model/Variable1"); variable1.VariableChange += Variable1_VariableChange;synchronizer = new RemoteVariableSynchronizer(TimeSpan.FromMilliseconds(5000));synchronizer.Add(variable1); } private void Variable1_VariableChange(object sender, VariableChangeEventArgs e) { Log.Info($"Variable1 {e.NewValue}"); } public override void Stop() { synchronizer.Dispose(); var variable1 = Project.Current.Get<IUAVariable>("Model/Variable1"); variable1.VariableChange -= Variable1_VariableChange; } RemoteVariableSynchronizer synchronizer;
Provide Feedback