45 lines
1.0 KiB
Python
45 lines
1.0 KiB
Python
#!/usr/bin/env python
|
|
|
|
import os
|
|
import sys
|
|
import MySQLdb
|
|
|
|
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;"
|
|
cur.execute(query)
|
|
setup = cur.fetchall()
|
|
db.commit()
|
|
db.close()
|
|
|
|
PLC_IP_ADDRESS = setup[0][2]
|
|
|
|
#PYCOMM Connection to PLC
|
|
from pycomm.ab_comm.clx import Driver as ClxDriver
|
|
|
|
c = ClxDriver(True, 'ClxDriver.log')
|
|
|
|
def readString(tag):
|
|
read_vals = c.read_array(tag, 82)
|
|
string = filter(lambda b: b != "",map(lambda a: chr(a[1]),read_vals))
|
|
return "".join(string)
|
|
|
|
if c.open(PLC_IP_ADDRESS):
|
|
out = {}
|
|
try:
|
|
result = c.read_tag([tagName])
|
|
if result[0][2] == None:
|
|
raise ValueError('Tag not found')
|
|
out['status'] = "success"
|
|
out['value'] = result[0][1]
|
|
out['type'] = result[0][2]
|
|
except Exception, e:
|
|
out['status'] = "error"
|
|
out['message'] = "Tag not found"
|
|
return out
|
|
|
|
if __name__ == '__main__':
|
|
res = main(sys.argv[1])
|
|
print res
|