- Solution Name: Tag Estimated Values
- Software Version: v10
- Keywords: Tags. Tag Estimated Value. Tag Historian Value. Trend PlayBack. Display PlayBack.
Summary
Estimated Values can be used for multiple purposes, such as reducing noise in calculations. This solution example shows how to use this property in multiple ways.
Technical Information
The DisplayValue property will show one of three options: the Value tag property (the tag's current value), the EstimatedValue tag property (which is a user-defined calculation), or a Historian Value of the tag.
With this infrastructure, you can calculate the EstimatedValue for the Value property and dynamically choose whether your display or another system will show the units. To switch between multiple display values, use the Client.Context.DisplayValueMode property, where each specific number changes the DisplayValue (e.g., if set to 0, it will display the original value; if set to 1, it will display the estimated value).
Alternatively, you can use the following code snippet in the CodeBehind for dynamic switching.
@Client.Context.SetDisplayValueToEstimated(); // the DisplayValue will show the Tag EstimatedValue property @Client.Context.SetDisplayValueToCurrent(); // the DisplayValue will show the Tag Value property @Client.Context.SetDisplayValueToHistorian(DateTime selectedDateTime); // the DisplayValue will show the HistorianValue at the selected DateTime
The method for calculating EstimatedValue may vary depending on your application. However, in this solution example, we’ve set up a code snippet in Classes / Tasks that triggers every time a tag changes, ensuring the EstimatedValue is accurately recalculated with the new data. You can find the path to these Tasks in the image below.
Finally, the code used to obtain the first three significant figures is shown in the code snippet below.
double scale = Math.Pow(10, Math.Floor(Math.Log10(Math.Abs(@Tag.tag2))) + 1); if(@Tag.tag2 == 0) @Tag.tag2.EstimatedValue = 0; else @Tag.tag2.EstimatedValue = scale * Math.Round(@Tag.tag2 / scale, 3);
Reference Information
→ See Tags for more information.
In this section: