Updated to work with Sqlite

This commit is contained in:
Patrick McDonagh
2016-03-30 15:58:10 -05:00
parent 2437380c6e
commit 00af9f0144
3 changed files with 49 additions and 25 deletions

View File

@@ -91,8 +91,8 @@ def main():
if retry_attempts < retries_allowed:
main()
else:
print {'status':'error', 'message':e}
return {'status':'error', 'message':e}
print {'status':'error', 'message':'{}'.format(e)}
return {'status':'error', 'message':'{}'.format(e)}
if __name__ == '__main__':
main()

View File

@@ -2,18 +2,31 @@
import os
import sys
import MySQLdb
import sqlite3 as lite
def main(tagName):
db = MySQLdb.connect(host="127.0.0.1",user="website",passwd="henrypump",db="WellData")
cur = db.cursor()
query = "SELECT * FROM WellData.config ORDER BY dateChanged DESC LIMIT 1;"
con = lite.connect("/mnt/usb/data.db")
PLC_IP_ADDRESS = "192.168.1.10"
PLC_TYPE = "VFD"
def getPLCIP():
global PLC_IP_ADDRESS, PLC_TYPE
with con:
cur = con.cursor()
query = "SELECT * FROM config ORDER BY dateChanged DESC LIMIT 1;"
cur.execute(query)
setup = cur.fetchall()
db.commit()
db.close()
try:
PLC_IP_ADDRESS = setup[0][2]
PLC_TYPE = setup[0][1]
except:
PLC_IP_ADDRESS = "192.168.1.10"
PLC_TYPE = "VFD"
return
def main(tagName):
global PLC_IP_ADDRESS
getPLCIP()
#PYCOMM Connection to PLC
from pycomm.ab_comm.clx import Driver as ClxDriver

View File

@@ -1,24 +1,32 @@
from pycomm.ab_comm.clx import Driver as ClxDriver
import sys
import MySQLdb
from time import sleep
import sqlite3 as lite
con = lite.connect("/mnt/usb/data.db")
PLC_IP_ADDRESS = "192.168.1.10"
PLC_TYPE = "VFD"
def closeEnough(a,b):
return abs(a - b) <= 0.1
def getPLCIP():
db = MySQLdb.connect(host="127.0.0.1",user="website",passwd="henrypump",db="WellData")
cur = db.cursor()
query = "SELECT * FROM WellData.config ORDER BY dateChanged DESC LIMIT 1;"
global PLC_IP_ADDRESS, PLC_TYPE
with con:
cur = con.cursor()
query = "SELECT * FROM config ORDER BY dateChanged DESC LIMIT 1;"
cur.execute(query)
setup = cur.fetchall()
db.commit()
db.close()
return setup[0][2]
try:
PLC_IP_ADDRESS = setup[0][2]
PLC_TYPE = setup[0][1]
except:
PLC_IP_ADDRESS = "192.168.1.10"
PLC_TYPE = "VFD"
return
def readTag(tagName):
PLC_IP_ADDRESS = getPLCIP()
global PLC_IP_ADDRESS
c = ClxDriver(True, 'ClxDriver.log')
@@ -43,9 +51,10 @@ def readTag(tagName):
return out
def main(tag, value):
global PLC_IP_ADDRESS
getPLCIP()
r = 0
PLC_IP_ADDRESS = getPLCIP()
readObj = readTag(tag)
if readObj['status'] == "error":
@@ -70,8 +79,10 @@ def main(tag, value):
def writeTagAndVerify(tag,value, sleepValue=2):
"""Writes the specified value to tag and confirms that the value has been set"""
global PLC_IP_ADDRESS
r = 0
PLC_IP_ADDRESS = getPLCIP()
getPLCIP()
readObj = readTag(tag)
if readObj['status'] == "error":
return readObj