In some cases, it may be desirable that the trend of the tag value read from the field is continuously increasing (such as reading a counter). In such cases, when the data read from the field is contaminated because of device replacement, project update, and etc.; trends and counter total values may also get contaminated. To prevent this, a mechanism on SCADA can be configured in the following way.
- We need 3 seperate tags to solve the problem. As an example we will create a "CounterTag" tag. In parallel we will create a "CounterTag_latest" tag under "Database Channel" and a "CounterTag_controller" tag under Macro channel to fix field-based distortions so that this tag can read the latest value logged in the database.
- We will use the following query in the tag settings to get the most recent value we have logged into the "CounterTag_latest" tag:
select dataval from logs.lct_table where tag_id=2
This query will read the last logged value of the "CounterTag" tag with tag ID "2"
- Finally, we will add the control macro to the "CounterTag_controller" tag. The macro will be:
[v1=$4e0] [IF,v1,3] [$4=$6+0] [E] [v0=$4>$2] [IF,v0,3] [$2=$4+0] [E] [$4=$2+0] [E]
This macro consists of 3 main sections:
Lines numbered as "1"; reads the last logged value from the database when the server is running for the first time.
Lines numbered as "2"; sets the value to be the value on the field device if it is less than the last log value for any reason.
Lines numbered as "3"; is the part where macro continuously updates the control tag.
- In order to prevent erroneous logs in addition to the structure created above, the "log only while increasing" option should be enabled in the tag logging settings.