Advertisement
Guest User

Untitled

a guest
Nov 8th, 2017
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.79 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import sys
  3. import os
  4. import threading
  5. import time
  6. import OpenOPC
  7.  
  8. #import for library
  9. from lackey import *
  10. from Tkinter import *
  11.  
  12. #Variable
  13.  
  14. watch_dog = 0
  15. firstBarcode = "112345678"
  16. secondcode = "12345678"
  17. #
  18. #OPC Control
  19. #
  20. opc = OpenOPC.client()
  21. #check all avalible OPC server
  22. opcservers= opc.servers()
  23. print opcservers
  24. #check all avalible tag for Kepware OPC server
  25. opc.list()
  26. # open connection to Server
  27. opc.connect('Kepware.KEPServerEX.V6')
  28. #read value from server
  29. print opc['Simulation Examples.Test.RR01']
  30. opc.close()
  31. # Check OPC rutine
  32. def Check_OPC():
  33.   opc.connect('Kepware.KEPServerEX.V6')
  34.   print opc['Simulation Examples.Test.RR01']
  35.   opc.close()
  36.  
  37. # Check Logo rutine
  38. def Check_Logo():
  39.  if exists(Pattern("images/logo.png").similar(0.65)):
  40.  # Check Logo for Watch Dog
  41.     print ("Logo is oK")
  42.     global watch_dog
  43.     watch_dog = 1
  44.  else:
  45.     global watch_dog
  46.     watch_dog = 0  
  47.     print ("EP is Offline")
  48.  
  49. #
  50.            
  51. # Watch Dog
  52. class WatchDog(object):
  53.     """ Watch dog example class
  54.    The run() method will be started and it will run in the background
  55.    until the application exits.
  56.    """
  57.  
  58.     def __init__(self, beat, interval=1 ):
  59.         """ Constructor
  60.        :type interval: int
  61.        :param interval: Check interval, in seconds
  62.        :   time.sleep(self.interval)
  63.        """
  64.         self.watch_dog = beat
  65.         self.interval = interval
  66.        
  67.         thread = threading.Thread(target=self.run, args=())
  68.         thread.daemon = True                            # Daemonize thread
  69.         thread.start()                                  # Start the execution
  70.  
  71.        
  72.     def run(self):
  73.         #  Method that runs forever
  74.         while True:
  75.             wait(2)
  76.             Check_OPC()
  77.             wait(2)
  78.             Check_Logo()
  79.  
  80.  
  81. # Functions
  82.      
  83. # Main rutine
  84. def main_loop():
  85.  while exists("images/logo.png", 10):
  86.    
  87.    click(Pattern("images/product.png").similar(0.95))
  88.    click(Pattern("images/Vrijgeven.png").similar(0.95))
  89.  
  90.    print watch_dog
  91.    click("images/Print.png")
  92.    click(Pattern("images/yellow_input.png").exact())
  93.    type(firstBarcode)
  94.    ask_loop()
  95. #
  96. # Exit rutine
  97.  
  98. def exit_program():
  99.  exitmsges = tkMessageBox.showinfo("Ariana","Thank you for use.")
  100.  print exitmsges
  101.  wait(1)
  102.  sys.exit()
  103. #
  104. # start window rutine
  105. def ask_loop():
  106.   startmsges = tkMessageBox.askyesno("Ariana","Do you want to start?")
  107.   print startmsges
  108.   answer = startmsges
  109.   # If you want start or continue then ...
  110.   if startmsges == True:
  111.  
  112.    print "Start"  
  113.    main_loop()
  114.  
  115.   # If you want finish  
  116.   if startmsges == False:
  117.      
  118.    exit_program()
  119.  
  120.  
  121. # OPC server status check
  122. def opc_status():
  123.     opc.connect('Kepware.KEPServerEX.V6')
  124.     print opc.list()
  125.     print "\n"
  126.     print opc.info()
  127.     print "\n"
  128.     print watch_dog
  129.     opc.close()
  130.  
  131. #
  132. #Program start
  133. #
  134. Control = WatchDog(WatchDog)
  135.  
  136. # HERE START GUI
  137. hlavni = Tk()
  138. hlavni.title("Ariana 0.1")
  139. hlavni.resizable(width=False, height=False)
  140. hlavni.minsize(200, 250)
  141. hlavni.maxsize(200, 250)
  142.  
  143. nabidka = Menu(hlavni)
  144. hlavni.config(menu=nabidka)
  145.  
  146. Label(hlavni, text="Ariana Online",
  147.       fg="black",
  148.       font="Verdana 10 bold").pack()
  149. if watch_dog == 0:
  150.  Label(hlavni, text="EP Offline",
  151.        fg="white", bg="red",
  152.        font="Verdana 10 bold").pack()
  153. if watch_dog == 1:
  154.  Label(hlavni, text="EP Online",
  155.        fg="white", bg="green",
  156.        font="Verdana 10 bold").pack()
  157.  
  158.  
  159. menuSoubor = Menu(nabidka)
  160. nabidka.add_cascade(label="Control", menu=menuSoubor)
  161. menuSoubor.add_command(label=u"Start", command=ask_loop)
  162. menuSoubor.add_command(label=u"Status", command=opc_status)
  163.  
  164. menuSoubor.add_separator()
  165. menuSoubor.add_command(label="Exit", command=exit_program)
  166.  
  167.  
  168.  
  169. mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement