To conserve bandwidth and only deliver the most relevant data to the end-user we worked with one reseller to create the following plug-in for our SCADA Gateway. The full Python source for this plug-in is available right here. Contact our support department for help in developing a plugin for your specific application.
from pluginBase import baseModule
class AverageCurrentModule(baseModule):
# this module is setup to get the average current for a pump. In the setup it was written for,
# there is one CT monitoring all current, and two pumps setup to alternate. The pumps are monitored
# on status inputs 1 and 2, and the current transformer is hooked to analog 3.
def __init__(self):
self.last_data_pack = "0,0,0"
self.data_pack = self.last_data_pack
self.name = "Lift Station Avg Amps"
self.current_txfrmr = 1 # analog input current tranformer is connected to
self.pump_status = (1,2) # list of inputs that indicate the pump is on
self.current_list = [] # an empty list to hold the current readings
self.record_mode = False # flag to indicate if we are recording
def update(self,in_data_pack,force,devicemgr,device_list):
self.data_pack = in_data_pack
pump_on_flag = False # clear pump on flag
for status in self.pump_status: # check each pump status
if self.getStatus(status) == 1: # if any pump status is on
pump_on_flag = True # set the pump_on_flag flag on.
if pump_on_flag: # if any pump is on
#print "pump on recording"
self.record_mode = True # set record mode flag to true
self.current_list.append(self.getAnalog(self.current_txfrmr)) # record the current reading to ram
if not pump_on_flag and self.record_mode: # if all the pumps have gone off and record mode is set
print "pump off reporting"
print "recordings", self.current_list
self.record_mode = False # clear record mode
if len(self.current_list) > 10: # make sure we recorded at least 10 readings
avg = sum(self.current_list[4:-4])/len(self.current_list[4:-4]) # average the readings starting with the forth reading and leave out the last 4
else:
avg = 0 # not enough readings set the avg to zero
self.current_list = [] # clear the recorded readings
self.updateAnalog(self.current_txfrmr, avg) ## put the average into the datapack in place of current transformer value
return (self.data_pack,True) ## send the new modified datapack as a forced server update
self.updateAnalog(self.current_txfrmr, 0) ## force face to zero normally
return (self.data_pack, force) # force the datapack
