我想每秒钟监视一次PLC值,包括模拟值和数字值。我当前的代码能够读取值,但不会更新。我想我需要在其中使用线程概念。
from Tkinter import *
import Tkinter as tk
from PIL import ImageTk, Image
from cpppo.server.enip import client
import thread
root = tk.Tk()
root.geometry("1920x1080")
def AIn(Cfg_Tag,parent,Xaxis,Yaxis,Unit):
tag = Label(parent,text = Cfg_Tag, relief = RAISED, height = 1, width =15)
tag.pack()
tag.place(x=Xaxis,y=Yaxis)
unit = Label(parent,text = Unit, relief = RAISED ,height =1, width = 5)
unit.pack()
unit.place(x=Xaxis+70,y=Yaxis+22)
HOST = "10.191.175.229"
TAGS = [Cfg_Tag]
with client.connector(host=HOST) as conn:
for index, descr, op, reply, status, value in conn.synchronous(
operations=client.parse_operations(TAGS)):
#print(": %20s: %s" % (descr, value))
Value= value
value1 = Label(parent,text = Value, relief = RAISED, height = 1, width = 9)
value1.pack(side = "right")
value1.place(x=Xaxis,y=Yaxis+22)
#Value = value
AIn("add",root,100,100,"DegC")
#AIn("0096_PIT_1121",root,100,100,"65356", "DegC")
#root.after(2000, AIn)
root.mainloop()
输出显示应不断更新值。