#!/usr/bin/env python import csv from datetime import datetime import os import sys import time from readConfig import readConfig from pycomm.ab_comm.clx import Driver as ClxDriver configProperties = readConfig() sys.path.append("../") path_to_CSV = "/mnt/usb/" def readTag(addr, tag): time.sleep(0.01) c = ClxDriver() if c.open(addr): try: v = c.read_tag(tag) # print(v) return v except Exception: print("ERROR RETRIEVING TAG: {}".format(tag)) c.close() print traceback.print_exc() pass c.close() now = datetime.now() nowDT = datetime.strftime(now,"%Y%m%d_%H%M%S") filename = path_to_CSV + "backup_"+nowDT+".csv" if os.path.exists(filename): os.remove(filename) taper_setup_params = [ ["Length","REAL"], ["Diameter","REAL"], ["Material","DINT"], ["c","REAL"], ["UseRodCount","BOOL"], ["RodCount","DINT"] ] data = {} tags_to_read = [['Casing_ID', 'REAL'], ['UnitConfig.MotorNameplate.Volts', 'REAL'], ['UnitConfig.MotorNameplate.Amps', 'REAL'], ['UnitConfig.MotorNameplate.Hertz', 'REAL'], ['UnitConfig.MotorNameplate.Poles', 'INT'], ['UnitConfig.MotorNameplate.RPM', 'REAL'], ['UnitConfig.MotorNameplate.ServiceFactor', 'REAL'], ['UnitConfig.MotorNameplate.Horsepower', 'REAL'], ['UnitConfig.Pump_Diameter', 'REAL'], ['UnitConfig.Pump_Constant', 'REAL'], ['UnitConfig.Anchor_Depth', 'REAL'], ['UnitConfig.Total_Stroke_Length', 'REAL'], ['UnitConfig.Motor_Sheave_Size', 'REAL'], ['UnitConfig.Gearbox_Limit', 'REAL'], ['UnitConfig.Gearbox_Ratio', 'REAL'], ['UnitConfig.Gearbox_Sheave', 'REAL'], ['UnitConfig.RPM_Maximum', 'REAL'], ['UnitConfig.RPM_Minimum', 'REAL'], ['UnitConfig.MotorCntrlMode', 'DINT'], ['UnitConfig.MaxFreq', 'REAL'], ['UnitConfig.Speed_Torque_Mode', 'DINT'], ['UnitConfig.Rating_Gearbox', 'REAL'], ['UnitConfig.Rating_Structural', 'REAL'], ['UnitConfig.Well_Type', 'SINT'], ['UnitConfig.Total_Vertical_Depth', 'REAL'], ['UnitConfig.Total_Vertical_Depth_Input', 'REAL'], ['UnitConfig.Tubing_Size_ID', 'REAL'], ['UnitConfig.Tubing_Size_OD', 'REAL'], ['UnitConfig.API_Oil', 'REAL'], ['UnitConfig.SG_Water', 'REAL'], ['UnitConfig.Percent_Water', 'REAL'], ['Youngs_Modulus_Fiberglass', 'REAL'], ['Youngs_Modulus_Steel', 'REAL'], ] with open(filename, 'wb') as myfile: wr = csv.writer(myfile) for t in tags_to_read: tagVal = readTag(configProperties['PLC_IP_ADDRESS'], t[0])[0] wr.writerow([t[0], tagVal, t[1]]) wr.writerow(["TAPER", "CONFIG"]) for i in range(0,11): for p in taper_setup_params: wr.writerow(["Taper.Taper[" + str(i) + "].Setup." + p[0], readTag(configProperties['PLC_IP_ADDRESS'], "Taper.Taper[" + str(i) + "].Setup." + p[0])[0], p[1]]) print "Backed up PLC settings to", filename