Skip to main content

WEBfactory 2010

Logging data with hysteresis and timeout deadband reached

Abstract

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

Example signal name : Buffer 1 (Setpoint1)

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

    Logging_hysteresis.jpg

    Setting hysteresis inStudioWEBfactory 2010

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

    Setting_Log_conditions.jpg

    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
    
    Setting_up_the_Vchannel.jpg

    Note

    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 2010 server has to be started at least one time to force the WEBfactory 2010 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
                ts=cdate(rs.fields("MaxLoggingTime").value)
            End If
        end if
     
        rs.close
        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() 
        Else
    ' if timeout is not reached just return last log timestamp
            result = ts
        End If
     
        cn.Close
        Set cn = nothing
     
        CheckDeathBand = result
    
    'End Function
    
    Checking_deadband.jpg

    Creating the CheckDeathBand function

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