LogGroupIO deadband

If I use OnChange function to LogGroupIO, can I set some kind of deadband?

@tomgiorgio

Are you trying to use the same deadband value for all your tags?

You can use scripting to monitor the tag via ONCHANGE and then use an IF statement to compare the previous tag value and the current tag value by using a global variable in BASIC

Here’s an example where I monitor an integer tag called “testtag” and compare its previous value to its current value.If the tag value changes by more than a value of 3 then it logs group A otherwise it does not log.

Initsection:
a% = testtag@
ONCHANGE "testtag", "goto logcheck"

Logcheck section:
logcheck:

If(Abs(a% - testtag@) > 3) THEN
LoggroupIO("A")
a% = testtag@
Print "Logging performed"
ELSE
a% = testtag@ // you can remove this if you do not want the tag variable to update if it changes by less than 3
ENDIF
END

I would be using a different deadband value for each tag

@tomgiorgio

I have prepared a pretty comprehensive script that should address this use case. Take a look below and let me know if this is kind of what you had in mind.

You can download the raw program file from the bottom and import it into your device.


Description:

This script essentially operates by tracking the previous value and comparing it against the current value. The script works by doing these processes in this order:

  1. Loop through all tags

  2. If the tag has a blank description, write a description with the current value. This is used for tracking the value when we do the deadband checking

  3. Set an ONCHANGE listener for all tags to check the log needs

  4. Load the current value, previous value and deadband and check if the value has changed enough to require logging.

  5. Update the description field with the new tag value

I opted to use the description field in the tag to store the previous value as it does not require any special configuration, is readily accessible and doesn’t require duplicate tags to track the value.

The nice thing about this script is that it is completely tag independent. Each tag can have a custom logging deadband and will still complete the actions as needed.


Script:

  1. INIT SECTION
REM This variable ensures that inside of the LoggingFunction only runs once
REM The function will run recursively otherwise. DO NOT REMOVE
x% = 0

REM Instantiate init values and assign on change listener to all tags in the
REM device
FOR i% = 0 TO 300
   SETSYS Tag, "load", -i%
   t$ = GETSYS Tag, "Name"
   d$ = GETSYS Tag, "Description"
   
   REM If the description is blank we need to init it to make sure there are no
   REM missed changes
   IF d$ = "" THEN
     c$ = GETSYS TAG, "TagValue"
     c% = VAL(c$)
     SETSYS TAG, "Description", c%
     SETSYS TAG, "SAVE"
   ENDIF

   REM Set the onchange lis
   ONCHANGE t$, "goto LoggingFunction"
NEXT i%

  1. Logging Sections:
REM Check if the current value has changed more than the specified
REM deadband from the previous value. If so do our loggroupio
LoggingFunction:
  if x% < 1 THEN
    tagId% = GETSYS PRG, "EVTINFO"
    SETSYS TAG, "LOAD", tagId%
    
    REM Load current, previous and deadband values
    c$ = GETSYS TAG, "TAGValue"
    c% = VAL(c$)
    p$ = GETSYS TAG, "Description"
    p% = VAL(p$)
    d$ = GETSYS TAG, "LogDB"
    d% = VAL(d$)
    
    REM check if the current value minus the previous value (or vice versa) is greater than or equal to the deadband value
    IF c% - p% >= d% OR p% - c% >= d% THEN
      REM PUT YOUR LOGGROUPIO OR OTHER REQUESTS HERE
      REM Example:
      PRINT "Value has changed enough to log!"
    ENDIF
    
    REM Assign the current value to the previous field
    GOTO CrossAssign
  ENDIF
  x% = 0
END

REM Assign the current value to the description field for comparation on next change 
CrossAssign:
 tagId% = GETSYS PRG, "EVTINFO"
 SETSYS TAG, "LOAD", tagId%
 t$ = GETSYS TAG, "TagValue"
 SETSYS TAG, "Description", t$
 SETSYS TAG, "SAVE"
 x% = x% + 1
END


In Action:


https://hms-networks-s3.s3.amazonaws.com/original/2X/3/3ce4bfbea0c2b3a01d2fa468fa24206c69fdf9df.webm

Download:

Program File Download: program.bas (2.2 KB)

1 Like