Counter retrieval - query example
- Last UpdatedFeb 06, 2025
- 2 minute read
To use the counter mode, set the following parameter in your query.
wwRetrievalMode = 'Counter'
In the following example, the rollover value for the SysTimeSec system tag is set to 0. In a five-minute time span, the SysTimeSec tag increments a total of 300 times. The following query returns the total count within the five-minute time span, which begins with StartTime and ends with DateTime. The QualityDetail of 212 indicates that a counter rollover occurred during the query time range.
select StartDateTime, DateTime, TagName, Value, wwUnit, QualityDetail as QD from History
where TagName = 'SysTimeSec'
and DateTime > '2020-12-02 1:00'
and DateTime <= '2020-12-02 1:05'
and wwRetrievalMode = 'counter'
and wwCycleCount = 1
The results are:
|
StartTime |
DateTime |
TagName |
Value |
wwUnit |
QD |
|
2020-12-02 01:00:00.0000000 |
2020-12-02 01:05:00.0000000 |
SysTimeSec |
300 |
Second |
212 |
To display the results using a different unit of measure, you can use the wwExpression query parameter with the following syntax:
wwExpression = 'UOM(TagName, target unit)'
The following example is similar to the previous example. The following query returns the total count within the five-minute time span, which begins with StartTime and ends with DateTime, and converts the retrieved value from its original units (seconds) to minutes.
select StartDateTime, DateTime, TagName, Value, Quality, QualityDetail as QD from History
where TagName = 'SysTimeSec'
and DateTime > '2020-12-02 1:00'
and DateTime <= '2020-12-02 1:05'
and wwRetrievalMode = 'counter'
and wwCycleCount = 1
and wwExpression = 'UOM(SysTimeSec,Minute)'
The results are:
|
StartTime |
DateTime |
TagName |
Value |
wwUnit |
QD |
|
2020-12-02 01:00:00.0000000 |
2020-12-02 01:05:00.0000000 |
SysTimeSec |
5 |
Minute |
212 |
Note: Engineering unit conversion requires the advanced feature license. If your Historian does not have the advanced feature license activated, the results are returned in the original units.