test_auto.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. import pymysql
  2. import time
  3. import datetime
  4. import random
  5. import json
  6. import paramiko
  7. # 測試自動流程
  8. #
  9. # 第一步份
  10. # 發酵入料先改成FI_waiting 會自動改成FI_Inputtingbean
  11. # 脫皮出料改成PO_Outputtingbean
  12. #
  13. # 這樣如果兩個槽都是FI_inputtingbean跟PO_Outputtingbean會再改成standby並傳mqtt
  14. #
  15. # 第二部分
  16. # 發酵入料改成FI_Outputtingbean,發酵槽改成F_Waiting會自動改成F_InputtingBean,然後會改成standby並傳mqtt
  17. #
  18. # 第三部分
  19. # 發酵槽改成F_outputting,發酵出料改成Fo_Waiting會自動改成FO_InputtingBean,然後會改成standby並傳mqtt
  20. #
  21. # 第四部份
  22. # 發酵出料改成FO_Outputtingbean,乾燥入料改成DI_Waiting會自動改成DI_InputtingBean,然後會改成standby並傳mqtt
  23. def first_parts():
  24. insert = conn.cursor()
  25. insert_status = "INSERT INTO `ferment_container_status`(`Ferment_Input_1`,`Ferment_Input_2`," \
  26. "`Ferment_Tank_1`,`Ferment_Tank_2`, `Ferment_Tank_3`, `Ferment_Tank_4`, `Ferment_Tank_5`," \
  27. "`Ferment_Tank_6`, `Ferment_Tank_7`,`Ferment_Tank_8`, `Ferment_Tank_9`, `Ferment_Tank_10`," \
  28. "`Ferment_Tank_11`, `Ferment_Tank_12`, `Ferment_Output_1`,`Ferment_Output_2`)" \
  29. "SELECT `Ferment_Input_1`, `Ferment_Input_2`," \
  30. "`Ferment_Tank_1`,`Ferment_Tank_2`, `Ferment_Tank_3`, `Ferment_Tank_4`, `Ferment_Tank_5`," \
  31. "`Ferment_Tank_6`, `Ferment_Tank_7`,`Ferment_Tank_8`, `Ferment_Tank_9`, `Ferment_Tank_10`," \
  32. "`Ferment_Tank_11`, `Ferment_Tank_12`, `Ferment_Output_1`,`Ferment_Output_2`" \
  33. "FROM ferment_container_status ORDER BY `datetime` DESC LIMIT 1"
  34. insert.execute(insert_status)
  35. conn.commit()
  36. update_status = conn.cursor()
  37. Ferment_name = 'Ferment_Input_'
  38. re = "UPDATE `ferment_container_status` SET " + Ferment_name + str(
  39. 1) + " = 'FI_Waiting' ORDER BY `datetime` DESC LIMIT 1 "
  40. update_status.execute(re)
  41. conn.commit()
  42. insert1 = conn.cursor()
  43. insert_status1 = "INSERT INTO `clean_container_status`(`Clean_Input_1`,`Clean_Input_2`," \
  44. "`Clean_Tank_1`,`Clean_Tank_2`, `Clean_Tank_3`, `Clean_Tank_4`, `Reclaimed_Tank_1`," \
  45. "`ColorSelect_Input_1`, `ColorSelect_Input_2`,`ColorSelect_Tank_1`, `ColorSelect_Tank_2`, `ColorSelect_Output_g1`," \
  46. "`ColorSelect_Output_b1`, `ColorSelect_Output_g2`, `ColorSelect_Output_b2`,`Peel_Tank_1`,`Peel_Tank_2`,`Peel_Output_1`," \
  47. "`Peel_Output_2`,`Peel_Output_b1`)" \
  48. "SELECT `Clean_Input_1`,`Clean_Input_2`," \
  49. "`Clean_Tank_1`,`Clean_Tank_2`, `Clean_Tank_3`, `Clean_Tank_4`, `Reclaimed_Tank_1`," \
  50. "`ColorSelect_Input_1`, `ColorSelect_Input_2`,`ColorSelect_Tank_1`, `ColorSelect_Tank_2`, `ColorSelect_Output_g1`," \
  51. "`ColorSelect_Output_b1`, `ColorSelect_Output_g2`, `ColorSelect_Output_b2`,`Peel_Tank_1`,`Peel_Tank_2`,`Peel_Output_1`," \
  52. "`Peel_Output_2`,`Peel_Output_b1`" \
  53. "FROM clean_container_status ORDER BY `datetime` DESC LIMIT 1"
  54. insert1.execute(insert_status1)
  55. conn.commit()
  56. update_status_peel = conn.cursor()
  57. Peel_name = 'Peel_Output_'
  58. re_peel = "UPDATE `clean_container_status` SET " + Peel_name + str(1) + "= 'PO_OutputtingBean' " \
  59. "ORDER BY `datetime` DESC LIMIT 1 "
  60. update_status_peel.execute(re_peel)
  61. conn.commit()
  62. print('模擬:修改脫皮機狀態成-->PO_Outputtingbean')
  63. print('模擬:修改發酵入料儲豆槽狀態成-->FI_Waiting')
  64. def second_parts():
  65. insert = conn.cursor()
  66. insert_status = "INSERT INTO `ferment_container_status`(`Ferment_Input_1`,`Ferment_Input_2`," \
  67. "`Ferment_Tank_1`,`Ferment_Tank_2`, `Ferment_Tank_3`, `Ferment_Tank_4`, `Ferment_Tank_5`," \
  68. "`Ferment_Tank_6`, `Ferment_Tank_7`,`Ferment_Tank_8`, `Ferment_Tank_9`, `Ferment_Tank_10`," \
  69. "`Ferment_Tank_11`, `Ferment_Tank_12`, `Ferment_Output_1`,`Ferment_Output_2`)" \
  70. "SELECT `Ferment_Input_1`, `Ferment_Input_2`," \
  71. "`Ferment_Tank_1`,`Ferment_Tank_2`, `Ferment_Tank_3`, `Ferment_Tank_4`, `Ferment_Tank_5`," \
  72. "`Ferment_Tank_6`, `Ferment_Tank_7`,`Ferment_Tank_8`, `Ferment_Tank_9`, `Ferment_Tank_10`," \
  73. "`Ferment_Tank_11`, `Ferment_Tank_12`, `Ferment_Output_1`,`Ferment_Output_2`" \
  74. "FROM ferment_container_status ORDER BY `datetime` DESC LIMIT 1"
  75. insert.execute(insert_status)
  76. conn.commit()
  77. update_status = conn.cursor()
  78. Ferment_name = 'Ferment_Input_'
  79. re = "UPDATE `ferment_container_status` SET " + Ferment_name + str(
  80. 1) + " = 'FI_OutputtingBean' ORDER BY `datetime` DESC LIMIT 1 "
  81. update_status.execute(re)
  82. conn.commit()
  83. update_status_fer_Tank = conn.cursor()
  84. Ferment_Tank_name = 'Ferment_Tank_'
  85. re_fer_Tank = "UPDATE `ferment_container_status` SET " + Ferment_Tank_name + str(1) + "= 'F_Waiting' " \
  86. "ORDER BY `datetime` DESC LIMIT 1 "
  87. update_status_fer_Tank.execute(re_fer_Tank)
  88. conn.commit()
  89. print('模擬:修改發酵入料儲豆槽狀態成-->FI_OutputtingBean')
  90. print('模擬:修改發酵槽狀態成-->F_Waiting')
  91. def third_parts():
  92. insert = conn.cursor()
  93. insert_status = "INSERT INTO `ferment_container_status`(`Ferment_Input_1`,`Ferment_Input_2`," \
  94. "`Ferment_Tank_1`,`Ferment_Tank_2`, `Ferment_Tank_3`, `Ferment_Tank_4`, `Ferment_Tank_5`," \
  95. "`Ferment_Tank_6`, `Ferment_Tank_7`,`Ferment_Tank_8`, `Ferment_Tank_9`, `Ferment_Tank_10`," \
  96. "`Ferment_Tank_11`, `Ferment_Tank_12`, `Ferment_Output_1`,`Ferment_Output_2`)" \
  97. "SELECT `Ferment_Input_1`, `Ferment_Input_2`," \
  98. "`Ferment_Tank_1`,`Ferment_Tank_2`, `Ferment_Tank_3`, `Ferment_Tank_4`, `Ferment_Tank_5`," \
  99. "`Ferment_Tank_6`, `Ferment_Tank_7`,`Ferment_Tank_8`, `Ferment_Tank_9`, `Ferment_Tank_10`," \
  100. "`Ferment_Tank_11`, `Ferment_Tank_12`, `Ferment_Output_1`,`Ferment_Output_2`" \
  101. "FROM ferment_container_status ORDER BY `datetime` DESC LIMIT 1"
  102. insert.execute(insert_status)
  103. conn.commit()
  104. update_status_fer_Tank = conn.cursor()
  105. Ferment_Tank_name = 'Ferment_Tank_'
  106. re_fer_Tank = "UPDATE `ferment_container_status` SET " + Ferment_Tank_name + str(1) + "= 'F_OutputtingBean' " \
  107. "ORDER BY `datetime` DESC LIMIT 1 "
  108. update_status_fer_Tank.execute(re_fer_Tank)
  109. update_status_fer = conn.cursor()
  110. Ferment_name = 'Ferment_Output_'
  111. re_fer = "UPDATE `ferment_container_status` SET " + Ferment_name + str(1) + "= 'FO_Waiting' " \
  112. "ORDER BY `datetime` DESC LIMIT 1 "
  113. update_status_fer.execute(re_fer)
  114. conn.commit()
  115. print('模擬:修改發酵槽狀態成-->F_OutputtingBean')
  116. print('模擬:修改發酵出料儲豆槽狀態成-->FO_Waiting')
  117. def four_parts():
  118. insert = conn.cursor()
  119. insert_status = "INSERT INTO `ferment_container_status`(`Ferment_Input_1`,`Ferment_Input_2`," \
  120. "`Ferment_Tank_1`,`Ferment_Tank_2`, `Ferment_Tank_3`, `Ferment_Tank_4`, `Ferment_Tank_5`," \
  121. "`Ferment_Tank_6`, `Ferment_Tank_7`,`Ferment_Tank_8`, `Ferment_Tank_9`, `Ferment_Tank_10`," \
  122. "`Ferment_Tank_11`, `Ferment_Tank_12`, `Ferment_Output_1`,`Ferment_Output_2`)" \
  123. "SELECT `Ferment_Input_1`, `Ferment_Input_2`," \
  124. "`Ferment_Tank_1`,`Ferment_Tank_2`, `Ferment_Tank_3`, `Ferment_Tank_4`, `Ferment_Tank_5`," \
  125. "`Ferment_Tank_6`, `Ferment_Tank_7`,`Ferment_Tank_8`, `Ferment_Tank_9`, `Ferment_Tank_10`," \
  126. "`Ferment_Tank_11`, `Ferment_Tank_12`, `Ferment_Output_1`,`Ferment_Output_2`" \
  127. "FROM ferment_container_status ORDER BY `datetime` DESC LIMIT 1"
  128. insert.execute(insert_status)
  129. conn.commit()
  130. update_status_fer = conn.cursor()
  131. Ferment_name = 'Ferment_Output_'
  132. re_fer = "UPDATE `ferment_container_status` SET " + Ferment_name + str(1) + "= 'FO_OutputtingBean' " \
  133. "ORDER BY `datetime` DESC LIMIT 1 "
  134. update_status_fer.execute(re_fer)
  135. conn.commit()
  136. insert = conn.cursor()
  137. insert_status = "INSERT INTO `dry_container_status`(`Dry_Input_1`,`Dry_Input_2`," \
  138. "`Dry_Tank_1`,`Dry_Tank_2`, `Dry_Tank_3`, `Dry_Tank_4`, `Dry_Tank_5`," \
  139. "`Dry_Tank_6`, `Dry_Tank_7`,`Dry_Tank_8`, `Dry_Tank_9`, `Dry_Tank_10`," \
  140. "`Dry_Tank_11`, `Dry_Tank_12`, `Dry_Output_1`,`Dry_Output_2`)" \
  141. "SELECT `Dry_Input_1`,`Dry_Input_2`," \
  142. "`Dry_Tank_1`,`Dry_Tank_2`, `Dry_Tank_3`, `Dry_Tank_4`, `Dry_Tank_5`," \
  143. "`Dry_Tank_6`, `Dry_Tank_7`,`Dry_Tank_8`, `Dry_Tank_9`, `Dry_Tank_10`," \
  144. "`Dry_Tank_11`, `Dry_Tank_12`, `Dry_Output_1`,`Dry_Output_2`" \
  145. "FROM dry_container_status ORDER BY `datetime` DESC LIMIT 1"
  146. insert.execute(insert_status)
  147. conn.commit()
  148. update_status_dry = conn.cursor()
  149. Dry_name = 'Dry_Input_'
  150. re_dry = "UPDATE `dry_container_status` SET "+Dry_name+str(1)+"= 'DI_Waiting' " \
  151. "ORDER BY `datetime` DESC LIMIT 1 "
  152. update_status_dry.execute(re_dry)
  153. conn.commit()
  154. print('模擬:修改發酵出料槽狀態成-->FO_OutputtingBean')
  155. print('模擬:修改乾燥入料儲豆槽狀態成-->DI_Waiting')
  156. if __name__ == "__main__":
  157. conn = pymysql.connect(
  158. host='127.0.0.1',
  159. user='root',
  160. password='g53743001',
  161. db='coffee',
  162. charset='utf8')
  163. #first_parts()
  164. #time.sleep(1)
  165. #second_parts()
  166. #time.sleep(1)
  167. #third_parts()
  168. #time.sleep(1)
  169. four_parts()
  170. #time.sleep(1)