# watches a PV to see if is changing
# ALH will raise alarm if PV's value is static for > CountDelay seconds
# =======================================================
# Shadow the Watcher PV
record(calc,    "$(W)$(C)S") {
    field(DESC, "watcher shadow")
    field(CALC, "A")
    field(INPA, "$(S):$(N) CPP MS")
    field(FLNK, "$(W)$(C)P")	
    field(SCAN, "1 second")
    field(PINI, "YES")	
}

# If the current and previous value of Watcher PV are different,
# set previous value to current; else do nothing
record(calc, "$(W)$(C)P")
{
    field(DESC, "watcher counter")
    field(CALC, "(A!=B)?A:-1")
    field(INPA, "$(W)$(C)S")	
    field(INPB, "$(W)$(C)P")				
    field(FLNK, "$(W)$(C)")				
}

# if Watcher Pv has changed, 
record(calcout, "$(W)$(C)")
{
    field(DESC, "watcher counter")
    field(CALC, "(B=-1)?0:((A>=2147483647)?0:A+1)")
    field(INPA, "$(W)$(C)")
    field(INPB, "$(W)$(C)P")			
    field(OUT,  "$(W)WatchCount")			
}

