MySQL working, need to retro SQLite

This commit is contained in:
Patrick McDonagh
2016-04-12 18:31:14 -05:00
parent c568c2dfdb
commit c8baa20927
17 changed files with 408 additions and 608 deletions

View File

@@ -29,7 +29,7 @@ def readTag(addr, tag):
class Tag():
global readTag, con
def __init__(self, name, tag, data_type, change_threshold, guarantee_sec, mapFn=None, plc_type='CLK'):
def __init__(self, name, tag, db_id, data_type, change_threshold, guarantee_sec, mapFn=None, plc_type='CLK', plc_ip_address='192.168.1.10'):
self.name = name
self.tag = tag
self.data_type = data_type
@@ -41,13 +41,15 @@ class Tag():
self.mapFn = mapFn
self.plc_type = plc_type
self.readFn = readTag
self.db_id = db_id
if self.plc_type == "u800":
self.readFn = u800.readTag
self.plc_ip_address = plc_ip_address
def read(self, forceSend):
writeToDB = False
if self.tag:
v = readFn(PLC_IP_ADDRESS, self.tag)
v = readFn(self.plc_ip_address, self.tag)
if v:
if self.data_type == 'BOOL' or self.data_type == 'STRING':
val = v[0]
@@ -70,7 +72,7 @@ class Tag():
self.sendToDB()
def sendToDB(self):
query = "INSERT INTO tag_vals (dtime, name, val) VALUES ({}, '{}', {})".format(time.time(), self.name, self.value)
query = "INSERT INTO tag_vals (dtime, tagID, val) VALUES ({}, '{}', {})".format(time.time(), self.db_id, self.value)
print query
# TODO: CHECK ON THIS LOGIC -- with con:
cur = con.cursor()