Converted to PyComm
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user