From 566df88da12bb0550b6179f34db44a7125e44d11 Mon Sep 17 00:00:00 2001 From: Patrick McDonagh Date: Sun, 24 Jan 2016 14:33:06 -0600 Subject: [PATCH] Converted to PyComm --- python/tagserver_SQLite.py | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/python/tagserver_SQLite.py b/python/tagserver_SQLite.py index 05e3262..22c1876 100644 --- a/python/tagserver_SQLite.py +++ b/python/tagserver_SQLite.py @@ -6,20 +6,36 @@ Created on Dec 8, 2015 @author: Patrick McDonagh ''' - -from datetime import datetime -import sys from random import randint import time import sqlite3 as lite -import tuxeip +from pycomm_micro.ab_comm.clx import Driver as ClxDriver +import logging - -# TUXEIP Connection to PLC -from tuxeip import TuxEIP, LGX, LGX_REAL con = lite.connect("/usr/db/data.db") +def readTag(addr, tag): + logging.basicConfig( + filename="ClxDriver.log", + format="%(levelname)-10s %(asctime)s %(message)s", + level=logging.DEBUG + ) + c = ClxDriver() + + if c.open(addr): + try: + v = c.read_tag(tag) + # print(v) + return v + except Exception as e: + err = c.get_status() + c.close() + print err + print e + pass + c.close() + def main(): with con: cur = con.cursor() @@ -35,15 +51,10 @@ def main(): for t in tags: tagList.append({"id": int(t[0]), "name": t[1], "val": None, "lastVal": None}) print(tagList) - # try: - tux = TuxEIP(libpath="/usr/lib/libtuxeip.so") - sess = tux.OpenSession(PLC_IP_ADDRESS) - reg = tux.RegisterSession(sess) - conn = tux.ConnectPLCOverCNET(sess, LGX, 1, 100, 123, randint(0, 9999), 123, 321, 100, 5000, 1, '01') while True: for r in tagList: - r["val"] = tux.ReadLGXDataAsFloat(sess, conn, r['name'], 1)[0] + r["val"] = readTag(PLC_IP_ADDRESS, r['name']) print("{0} - {1}".format(r["name"], r["val"])) if not r["val"] == r["lastVal"]: with con: