Updated configProperties to include plc_type
This commit is contained in:
@@ -9,11 +9,13 @@ Created on Dec 8, 2015
|
||||
import time
|
||||
import sqlite3 as lite
|
||||
from pycomm.ab_comm.clx import Driver as ClxDriver
|
||||
from pycomm_micro.ab_comm.clx import Driver as u800Driver
|
||||
import logging
|
||||
|
||||
# con = lite.connect("/usr/db/data.db")
|
||||
con = lite.connect('/mnt/usb/data.db')
|
||||
|
||||
configProperties = {}
|
||||
|
||||
def readTag(addr, tag):
|
||||
logging.basicConfig(
|
||||
@@ -57,29 +59,36 @@ def main():
|
||||
configObj[x[0]] = x[1]
|
||||
|
||||
try:
|
||||
PLC_IP_ADDRESS = str(configObj['ip_address'])
|
||||
print("FYI, using PLC IP Address from the database {0}".format(PLC_IP_ADDRESS))
|
||||
configProperties['PLC_IP_ADDRESS'] = str(configObj['ip_address'])
|
||||
print("FYI, using PLC IP Address from the database {0}".format(configProperties['PLC_IP_ADDRESS']))
|
||||
except KeyError:
|
||||
print("FYI, there is no PLC IP Address stored in the database, defaulting to 192.168.1.10")
|
||||
PLC_IP_ADDRESS = "192.168.1.10"
|
||||
configProperties['PLC_IP_ADDRESS'] = "192.168.1.10"
|
||||
|
||||
try:
|
||||
scan_rate = int(configObj['scan_rate'])
|
||||
print("FYI, using Scan Rate from the database {0}".format(scan_rate))
|
||||
configProperties['plc_type'] = str(configObj['plc_type'])
|
||||
print("FYI, using PLC Type from the database {0}".format(configProperties['plc_type']))
|
||||
except KeyError:
|
||||
print("FYI, there is no PLC Type stored in the database, defaulting to CLX")
|
||||
configProperties['plc_type'] = "CLX"
|
||||
|
||||
try:
|
||||
configProperties['scan_rate'] = int(configObj['scan_rate'])
|
||||
print("FYI, using Scan Rate from the database {0}".format(configProperties['scan_rate']))
|
||||
except KeyError:
|
||||
print("FYI, there is no Scan Rate stored in the database, defaulting to 10 seconds")
|
||||
scan_rate = 10
|
||||
configProperties['scan_rate'] = 10
|
||||
|
||||
try:
|
||||
sa_test = str(configObj['save_all'])
|
||||
if sa_test == "true":
|
||||
save_all = True
|
||||
configProperties['save_all'] = True
|
||||
else:
|
||||
save_all = False
|
||||
print("FYI, value for save_all is {0}".format(save_all))
|
||||
configProperties['save_all'] = False
|
||||
print("FYI, value for save_all is {0}".format(configProperties['save_all']))
|
||||
except KeyError:
|
||||
print("FYI, there is no save_all value stored in the database, using False")
|
||||
save_all = False
|
||||
configProperties['save_all'] = False
|
||||
|
||||
|
||||
|
||||
@@ -96,9 +105,14 @@ def main():
|
||||
while True:
|
||||
try:
|
||||
for r in tagList:
|
||||
r["val"] = readTag(PLC_IP_ADDRESS, str(r['name']))[0]
|
||||
r['val'] = 0
|
||||
if configProperties['plc_type'] == "u800":
|
||||
u800.readMicroTag(configProperties['PLC_IP_ADDRESS'], str(r['name']))[0]
|
||||
else:
|
||||
r["val"] = readTag(configProperties['PLC_IP_ADDRESS'], str(r['name']))[0]
|
||||
|
||||
print("{0} - {1}".format(r["name"], r["val"]))
|
||||
if (not save_all and not r["val"] == r["lastVal"]) or save_all:
|
||||
if (not configProperties['save_all'] and not r["val"] == r["lastVal"]) or configProperties['save_all']:
|
||||
with con:
|
||||
cur = con.cursor()
|
||||
aQuery = """INSERT INTO vals (tagID, val) VALUES ('%d', '%f');""" % (r["id"], float(r["val"]))
|
||||
@@ -108,7 +122,7 @@ def main():
|
||||
print("<saved>")
|
||||
r["lastVal"] = r["val"]
|
||||
print("-----------")
|
||||
time.sleep(scan_rate)
|
||||
time.sleep(configProperties['scan_rate'])
|
||||
|
||||
except Exception as err:
|
||||
print err
|
||||
|
||||
Reference in New Issue
Block a user