#!/usr/bin/env python import os import sys import sqlite3 as lite from pycomm.ab_comm.clx import Driver as ClxDriver 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() 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() c = ClxDriver() 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