Added alerts and removed unmarshalling
This commit is contained in:
@@ -5,18 +5,19 @@ from pycomm.ab_comm.clx import Driver as clx
|
||||
from pycomm.cip.cip_base import CommError, DataError
|
||||
|
||||
class DataPoint(object):
|
||||
def __init__(self,changeThreshold=0,guaranteed=3600, name="datapoint",alertThreshold=[],alertCondition=[],alertResponse=[],alertContact=[]):
|
||||
def __init__(self,changeThreshold=0,guaranteed=3600, name="datapoint",alertThreshold=[],alertCondition=[],alertResponse=[],alertContact=[], alertName=[]):
|
||||
self.value = None
|
||||
self.lastvalue = None
|
||||
self.lastsend = 0
|
||||
self.changeThreshold = changeThreshold
|
||||
self.guaranteed = guaranteed
|
||||
self.name = name
|
||||
self.alerted = False
|
||||
self.alertThreshold = alertThreshold
|
||||
self.alertCondition = alertCondition
|
||||
self.alertResponse = alertResponse
|
||||
self.alertContact = alertContact
|
||||
self.alertName = alertName
|
||||
self.alerted = [False] * len(self.alertThreshold)
|
||||
|
||||
|
||||
def checkSend(self,value):
|
||||
@@ -37,8 +38,8 @@ class DataPoint(object):
|
||||
"not": "value != threshold"
|
||||
}
|
||||
|
||||
for thres,cond in zip(self.alertThreshold,self.alertCondition):
|
||||
#check value for alert threshold
|
||||
"""for thres,cond,name,contact,alerted in zip(self.alertThreshold,self.alertCondition, self.alertName, self.alertContact,self.alerted):
|
||||
#check value for alert threshold send back first alarmed value
|
||||
evalVars = {
|
||||
"value": value,
|
||||
"threshold": thres
|
||||
@@ -47,12 +48,32 @@ class DataPoint(object):
|
||||
if func == None:
|
||||
print("Not an available function: {}".format(cond))
|
||||
else:
|
||||
if eval(func, evalVars):
|
||||
return {"message":"Read value for {} is {} threshold value {}".format(self.name,value,thres)}
|
||||
if eval(func, evalVars) and not alerted:
|
||||
|
||||
return {"alert": name}
|
||||
else:
|
||||
self.alerted = False
|
||||
return None
|
||||
|
||||
"""
|
||||
for x in range(len(self.alerted)):
|
||||
#check value for alert threshold send back first alarmed value
|
||||
evalVars = {
|
||||
"value": value,
|
||||
"threshold": self.alertThreshold[x]
|
||||
}
|
||||
func = conditions.get(self.alertCondition[x])
|
||||
if func == None:
|
||||
print("Not an available function: {}".format(self.alertCondition[x]))
|
||||
else:
|
||||
result = eval(func,evalVars)
|
||||
if result and not self.alerted[x]:
|
||||
self.alerted[x] = True
|
||||
return {"alert": self.alertName[x], "contact": self.alertContact[x]}
|
||||
elif result and self.alerted[x]:
|
||||
pass
|
||||
else:
|
||||
self.alerted[x] = False
|
||||
return None
|
||||
|
||||
class modbusDataPoint(DataPoint):
|
||||
def __init__(self,changeThreshold,guaranteed,name,register=1,baud=19200,stopBits=1,parity=None, device='/dev/ttyS0'):
|
||||
@@ -69,8 +90,8 @@ class modbusDataPoint(DataPoint):
|
||||
pass
|
||||
|
||||
class plcDataPoint(DataPoint):
|
||||
def __init__(self,changeThreshold,guaranteed,name,plcIP='192.168.1.10',plcType='Micro800',tag=None,alertThreshold=[],alertCondition=[],alertResponse=[],alertContact=[]):
|
||||
DataPoint.__init__(self,changeThreshold,guaranteed,name,alertThreshold,alertCondition,alertResponse,alertContact)
|
||||
def __init__(self,changeThreshold,guaranteed,name,plcIP='192.168.1.10',plcType='Micro800',tag=None,alertThreshold=[],alertCondition=[],alertResponse=[],alertContact=[], alertName=[]):
|
||||
DataPoint.__init__(self,changeThreshold,guaranteed,name,alertThreshold,alertCondition,alertResponse,alertContact,alertName)
|
||||
self.plcIP = plcIP
|
||||
self.plcType = plcType
|
||||
self.tag = tag
|
||||
|
||||
Reference in New Issue
Block a user