In this example we have two value boxes linked to two separate tags. Using the "OnBeginValueChange" function, we can update a third value box to display the average of these two tags. (*Note: Both value boxes must be linked to the same OnBeginValueChange function.) The Average value box will change when either tag is updated.
To create the function in scripting simply click on the "<>" symbol next to the function name. This will open the script editor.
public void ValueBox_OnBeginValueChange(object sender, Tag tag, DateTime timestamp, TVQ tvq)
{
TVQ calculation = new TVQ();
TVQ tvq1 = ValueBox1.Value;
TVQ tvq2 = ValueBox2.Value;
if(tvq1.QualityIsGood && tvq2.QualityIsGood)
{
double average = (tvq1.ValueToDouble() + tvq2.ValueToDouble())/2;
calculation = new TVQ(DateTime.Now, average, 192);
}
ValueBox3.Value = calculation;
}
Comments
0 comments
Please sign in to leave a comment.