Converting analog values to discrete values (ToDiscrete)
- Last UpdatedFeb 07, 2025
- 3 minute read
The analog to discrete conversion filter allows you to convert value streams for any analog tag in the query tag list into discrete value streams. The filter can be used with all the retrieval modes.
To convert analog values to discrete values, specify the ToDiscrete() filter in the wwFilter column. This filter has two parameters:
|
Parameter |
Valid Values |
Default Value |
|---|---|---|
|
CutoffValue |
any double value |
0.0 |
|
Operator |
>, >=, or <= |
> |
The following are supported syntaxes.
-
ToDiscrete()
-
ToDiscrete(2)
-
ToDiscrete(2, >=)
The following are unsupported syntaxes.
-
ToDiscrete(2,)
-
ToDiscrete(, >=)
-
ToDiscrete(>=)
The cutoff value holds the value that signifies the boundary between values that are to be interpreted as OFF and values that are to be interpreted as ON.
The operator parameter controls the value range relative to the cutoff value to convert to the ON value and vice versa.
NULLs encountered in the analog value stream are copied unchanged to the discrete value stream. The quality of each discrete point is copied from the analog point that causes its production. However, the quality detail for values modified with this filter will have the QualityDetail flag 0x2000 (value changed by filter) set. For example, consider the following ValueState query:
SELECT DateTime, vValue, StateTime, wwFilter
FROM History
WHERE TagName IN ('SysTimeSec')
AND DateTime >= '2008-01-15 15:00:00'
AND DateTime <= '2008-01-15 17:00:00'
AND wwRetrievalMode = 'ValueState'
AND wwStateCalc = 'MinContained'
AND wwResolution = 7200000
AND wwFilter = 'ToDiscrete(29, >)'
Here the operator is specified as >, so values greater than but not including 29 are internally converted to ON, whereas values from 0 to 29 are converted to OFF. This query could return the following rows:
|
DateTime |
vValue |
StateTime |
wwFilter |
|---|---|---|---|
|
2008-01-15 15:00:00.000 |
0 |
30000 |
ToDiscrete(29, >) |
|
2008-01-15 15:00:00.000 |
1 |
30000 |
ToDiscrete(29, >) |
|
2008-01-15 17:00:00.000 |
0 |
30000 |
ToDiscrete(29, >) |
|
2008-01-15 17:00:00.000 |
1 |
30000 |
ToDiscrete(29, >) |
The values returned in the StateTime column show that the shortest amount of time that SysTimeSec had values equivalent to either ON or OFF and remained in that state was 30 seconds. A similar RoundTrip query would look like this:
SELECT DateTime, vValue, StateTime, wwFilter
FROM History
WHERE TagName IN ('SysTimeSec')
AND DateTime >= '2008-01-15 15:00:00'
AND DateTime <= '2008-01-15 17:00:00'
AND wwRetrievalMode = 'RoundTrip'
AND wwStateCalc = 'MaxContained'
AND wwResolution = 7200000
AND wwFilter = 'ToDiscrete(29, <=)'
Here the operator is specified as <=, so the resulting conversion is exactly opposite to that performed in the previous query. Now values smaller than or equal to 29 are internally converted to ON, whereas values from 30 to 59 are converted to OFF. This query could return the following rows:
|
DateTime |
vValue |
StateTime |
wwFilter |
|
2008-01-15 15:00:00.000 |
0 |
60000 |
ToDiscrete(29, <=) |
|
2008-01-15 15:00:00.000 |
1 |
60000 |
ToDiscrete(29, <=) |
|
2008-01-15 17:00:00.000 |
0 |
60000 |
ToDiscrete(29, <=) |
|
2008-01-15 17:00:00.000 |
1 |
60000 |
ToDiscrete(29, <=) |
The values returned in the StateTime column now show that the longest amount of time found between roundtrips for both the OFF and the ON state within the 2-hour cycles was 60 seconds.
Using the ToDiscrete() filter is similar to using edge detection for event tags. Edge detection returns the actual value with a timestamp in history for when a value matched a certain criteria. The ToDiscrete() filter returns either a 1 or 0 to show that the criteria threshold was crossed. The ToDiscrete() filter is more flexible, however, in the following ways:
-
You can use it with delta and full retrieval.
-
You can combine it with "time-in-state" calculations to determine how long a value is above a certain threshold or the duration between threshold times.
Use the ToDiscrete() filter if you are mostly interested in when something occurred, and not necessarily the exact value of the event.
For more information on edge detection, see Edge detection for events (wwEdgeDetection).