WEBfactory 2010

Logging data with hysteresis and timeout deadband reached


Check out this artcile and learn how to log data with hysteresis and timeout deadband reached.

If Signal value has to be logged when:

  • Change of value is at least +- 1

  • When deadband timeout is reached and value hasn’t changed

The optimal solution:

  • Use Logging hyteresis at signal change

  • Create additional VChannel script for detecting deadband timeout


Example signal name : Buffer 1 (Setpoint1)

  1. Set logging hysteresis in WEBfactoryStudio for signal „Buffer 1“ to 1 (or any other desired value)


    Setting hysteresis inStudioWEBfactory

  2. Set logging parameters in WEBfactoryStudio for signal „Buffer1“ to Log Mode „OnChange“ (Log Conditions).


    Setting the Log Contidions for the Buffer1 signal

  3. Create VChannel signal with name e.g. „Buffer1Timeout“. Set Input Trigger for VChannel e.g. signal “Local Second” or “Local Hour”. Create VChannel Script as follows:

    Sub GetResult()
    'To avoid unneccessary triggering of the VChannel it is recommended to use the MODULO value of the 'trigger signal
        ' If ((X(1) Mod 5) = 0) Then
            Dim signalName              'Signalname of Log Item
            Dim logGUID                 'GUID of Log-Tags or name of Logging Tabelle
            Dim deathBandTimeSpan       'timespan for Timeout deadband
            Dim diffUTCLocalTime        'difference between UTC time and local time in seconds
            Dim currentSignalValue
            Dim res
            signalName = "Buffer 1"
            logGUID = "L_8D9998A3D1464A829AB07AE516D7C06A"
            diffUTCLocalTime = -7200
            deathBandTimeSpan = 5
            currentSignalValue = ReadSignal(signalName)  'get actual signal value
            res = CheckDeathBand(currentSignalValue, logGUID, deathBandTimeSpan, diffUTCLocalTime)
            Result = res
        ' End If
    End Sub


    Hint: please modify the above parameters depending on your personal needs. The GUID for the LogTag can be read from SQL server by using SQL Management Studio. The WEBfactory server has to be started at least one time to force the WEBfactory server generating the Log GUID

  4. Create function „CheckDeathBand“ in VChannel script library to have the function reusable. The function is built as follows:

    'Function CheckDeathBand (currentSignalValue, logGUID, deathBandTimeSpan, diffUTCLocalTime) 
    Dim cnnString
    Dim sqlString
    Dim ts
    Dim result
        cnnString= DSN ' Connection String
        sqlString = "SELECT max([LoggingTime]) as MaxLoggingTime FROM [" & logGUID & "]"
        Set cn = CreateObject("ADODB.Connection")
        cn.Open cnnString       
        Set rs = CreateObject("ADODB.Recordset")
        rs.Open sqlString, cn, 0, 1
        If not rs.eof Then 
            If rs.fields("MaxLoggingTime").actualsize > 0 Then
            End If
        end if
        Set rs = nothing
    'check for last log entry is older than 5 seconds. (use h for hours)       
        If (datediff("s", ts, now()) + diffUTCLocalTime) > 5 Then	 
    ' create log entry when timeout is reached	
            cn.Execute  "INSERT INTO " & logGUID & " (LoggingTime,LoggingValue) VALUES (GETUTCDATE()," & replace(cstr(currentSignalValue), ",","." )  & ")"	
            result =  now() 
    ' if timeout is not reached just return last log timestamp
            result = ts
        End If
        Set cn = nothing
        CheckDeathBand = result
    'End Function

    Creating the CheckDeathBand function

    For additional log signals, the steps 1 – 3 have to be repeated and the variables have to be adapted.