Advertisement
Guest User

Untitled

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