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
- print ("Logo is oK")
- global watch_dog
- watch_dog = 1
- else:
- global watch_dog
- 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):
- 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()
- #
- # Exit rutine
- def exit_program():
- exitmsges = tkMessageBox.showinfo("Ariana","Thank you for use.")
- print exitmsges
- wait(1)
- sys.exit()
- #
- # 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()
- # OPC server status check
- def opc_status():
- opc.connect('Kepware.KEPServerEX.V6')
- print opc.list()
- print "\n"
- print opc.info()
- print "\n"
- print watch_dog
- opc.close()
- #
- #Program start
- #
- Control = WatchDog(WatchDog)
- # HERE START GUI
- hlavni = Tk()
- hlavni.title("Ariana 0.1")
- hlavni.resizable(width=False, height=False)
- hlavni.minsize(200, 250)
- hlavni.maxsize(200, 250)
- nabidka = Menu(hlavni)
- hlavni.config(menu=nabidka)
- Label(hlavni, text="Ariana Online",
- fg="black",
- font="Verdana 10 bold").pack()
- if watch_dog == 0:
- Label(hlavni, text="EP Offline",
- fg="white", bg="red",
- font="Verdana 10 bold").pack()
- if watch_dog == 1:
- Label(hlavni, text="EP Online",
- fg="white", bg="green",
- font="Verdana 10 bold").pack()
- 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)
- mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement