Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import sys
- import os
- import threading
- import time
- import OpenOPC
- #import for library
- from lackey import *
- from Tkinter import *
- #Variable
- watch_dog = 0
- firstBarcode = "112345678"
- secondcode = "12345678"
- #
- #OPC Control
- #
- opc = OpenOPC.client()
- #check all avalible OPC server
- opcservers= opc.servers()
- print opcservers
- #check all avalible tag for Kepware OPC server
- opc.list()
- # open connection to Server
- opc.connect('Kepware.KEPServerEX.V6')
- #read value from server
- print opc['Simulation Examples.Test.RR01']
- opc.close()
- # Check OPC rutine
- def Check_OPC():
- opc.connect('Kepware.KEPServerEX.V6')
- print opc['Simulation Examples.Test.RR01']
- opc.close()
- # Check Logo rutine
- def Check_Logo():
- if exists(Pattern("images/logo.png").similar(0.65)):
- # Check Logo for Watch Dog and then read value from OPC
- print ("Logo is oK")
- watch_dog = 1
- else:
- watch_dog = 0
- print ("EP is Offline")
- #
- def Check_OPC():
- opc.connect('Kepware.KEPServerEX.V6')
- print opc['Simulation Examples.Test.RR01']
- opc.close()
- # Check Logo rutine
- def Check_Logo():
- if exists(Pattern("images/logo.png").similar(0.65)):
- # Check Logo for Watch Dog and then read value from OPC
- print ("Logo is oK")
- watch_dog = 1
- else:
- watch_dog = 0
- print ("EP is Offline")
- # Watch Dog
- class WatchDog(object):
- """ Watch dog example class
- The run() method will be started and it will run in the background
- until the application exits.
- """
- def __init__(self, beat, interval=1 ):
- """ Constructor
- :type interval: int
- :param interval: Check interval, in seconds
- : time.sleep(self.interval)
- """
- self.watch_dog = beat
- self.interval = interval
- thread = threading.Thread(target=self.run, args=())
- thread.daemon = True # Daemonize thread
- thread.start() # Start the execution
- def run(self):
- # Method that runs forever
- while True:
- wait(2)
- Check_OPC()
- wait(2)
- Check_Logo()
- # Functions
- #
- # Main rutine
- def main_loop():
- while exists("images/logo.png", 10):
- watch_dog = 0
- click(Pattern("images/product.png").similar(0.95))
- click(Pattern("images/Vrijgeven.png").similar(0.95))
- print watch_dog
- click("images/Print.png")
- click(Pattern("images/yellow_input.png").exact())
- type(firstBarcode)
- ask_loop()
- # end main rutine
- # Exit rutine
- def exit_program():
- exitmsges = tkMessageBox.showinfo("Ariana","Thank you for use.")
- print exitmsges
- wait(1)
- sys.exit()
- #end Exit rutine
- # start window rutine
- def ask_loop():
- startmsges = tkMessageBox.askyesno("Ariana","Do you want to start?")
- print startmsges
- answer = startmsges
- # If you want start or continue then ...
- if startmsges == True:
- print "Start"
- main_loop()
- # If you want finish
- if startmsges == False:
- exit_program()
- #end start windows rutine
- # OPC server status check
- def opc_status():
- opc.connect('Kepware.KEPServerEX.V6')
- print opc.list()
- print opc.info()
- opc.close()
- #
- #Program start
- Control = WatchDog(WatchDog)
- # HERE START GUI
- hlavni = Tk()
- nabidka = Menu(hlavni)
- hlavni.config(menu=nabidka)
- # Here run watch dog and OPC
- menuSoubor = Menu(nabidka)
- nabidka.add_cascade(label="Control", menu=menuSoubor)
- menuSoubor.add_command(label=u"Start", command=ask_loop)
- menuSoubor.add_command(label=u"Status", command=opc_status)
- menuSoubor.add_separator()
- menuSoubor.add_command(label="Exit", command=exit_program)
- print Control
- if watch_dog == 1:
- w = Message(hlavni, text="EP Online")
- w.pack()
- mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement