pro.py 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. from socket import *
  2. import threading
  3. import time
  4. import app
  5. import main
  6. import datetime
  7. import user_socket
  8. import sql
  9. import pythoncom
  10. class work_server(threading.Thread):
  11. def __init__(self, threadID, name, counter):
  12. threading.Thread.__init__(self)
  13. self.threadID = threadID
  14. self.name = name
  15. self.counter = counter
  16. self.user_var = app.user_var
  17. self.opc_value = app.opc_value
  18. self.sqlclient = sql.sqlclient
  19. self.exit_stat = False
  20. self.tcpserverParam = user_socket.tcpserverParam
  21. self.plc_conn_timeout = 0
  22. self.order_change_timeout = 0
  23. def air_data_split(self, value):
  24. air_value = value.split('\t')
  25. idx = 0
  26. for air in air_value:
  27. if air == '(OK)' or air == '(TD)':
  28. break
  29. else:
  30. idx = idx + 1
  31. if idx >= 1 and len(air_value) - idx >= 5:
  32. return '<{0}>:{4} {5}:{1}:{2} {3}'.format(air_value[idx-1], air_value[idx], air_value[idx + 1],
  33. air_value[idx + 2], air_value[idx + 3], air_value[idx + 4])
  34. else:
  35. return ''
  36. def get_ateq_product_name(self, value):
  37. air_value = value.split('\t')
  38. return air_value[0]
  39. def opc_data_pro(self):
  40. value = self.opc_value.get_Bee()
  41. self.user_var.bee_stat = value
  42. value = self.opc_value.get_Number_type()
  43. self.user_var.number_type = '{0}{1}{2}'.format(chr(value[0]), chr(value[1]), chr(value[2]))
  44. value = self.opc_value.get_Batch_y()
  45. value = self.opc_value.get_Batch_m()
  46. value = self.opc_value.get_Batch_d()
  47. value = self.opc_value.get_Air_data_17700()
  48. self.user_var.product_17700_name = self.get_ateq_product_name(value)
  49. air_value = self.air_data_split(value)
  50. if air_value != '':
  51. self.user_var.airtightness_17700 = air_value
  52. self.user_var.airtightness_17700_str.set(self.user_var.airtightness_17700)
  53. value = self.opc_value.get_Air_data_17720()
  54. self.user_var.product_17720_name = self.get_ateq_product_name(value)
  55. air_value = self.air_data_split(value)
  56. if air_value != '':
  57. self.user_var.airtightness_17720 = air_value
  58. self.user_var.airtightness_17720_str.set(self.user_var.airtightness_17720)
  59. value = self.opc_value.get_Ok_count()
  60. self.user_var.order_ok_str.set(value)
  61. value = self.opc_value.get_Ng_count()
  62. self.user_var.order_ng_str.set(value)
  63. value = self.opc_value.get_Targe_count()
  64. self.user_var.order_targe_str.set(value)
  65. value = self.opc_value.get_SNP_count()
  66. self.user_var.order_snp_str.set(value)
  67. value = self.opc_value.get_Origin_ok()
  68. self.user_var.originchkok_stat = value
  69. value = self.opc_value.get_Origin_dir()
  70. self.user_var.origindir_stat = value
  71. value = self.opc_value.get_Upairtight_ok()
  72. self.user_var.upairtightok_stat = value
  73. value = self.opc_value.get_Upairtight_ng()
  74. self.user_var.upairtightng_stat = value
  75. value = self.opc_value.get_Downairtight_ok()
  76. self.user_var.downairtightok_stat = value
  77. value = self.opc_value.get_Downairtight_ng()
  78. self.user_var.downairtightng_stat = value
  79. value = self.opc_value.get_Upprint_ok()
  80. self.user_var.upprintok_stat = value
  81. value = self.opc_value.get_Downprint_ok()
  82. self.user_var.downprintok_stat = value
  83. value = self.opc_value.get_Upgage_s()
  84. self.user_var.upgages_stat = value
  85. value = self.opc_value.get_Downgage_s()
  86. self.user_var.downgages_stat = value
  87. value = self.opc_value.get_Upwork_s()
  88. self.user_var.upworks_stat = value
  89. value = self.opc_value.get_Downwork_s()
  90. self.user_var.downworks_stat = value
  91. value = self.opc_value.get_Upm_pen()
  92. self.user_var.upmpen_stat = value
  93. value = self.opc_value.get_Downm_pen()
  94. self.user_var.downmpen_stat = value
  95. value = self.opc_value.get_Upconnect()
  96. self.user_var.upconnect_stat = value
  97. value = self.opc_value.get_Downconnect()
  98. self.user_var.downconnect_stat = value
  99. value = self.opc_value.get_Motororgin_ok()
  100. self.user_var.motororiginok_stat = value
  101. value = self.opc_value.get_Motor_onup()
  102. self.user_var.motoronup_stat = value
  103. value = self.opc_value.get_Motor_ondown()
  104. self.user_var.motorondown_stat = value
  105. value = self.opc_value.get_Manual_print()
  106. value = self.opc_value.get_Manual_printup()
  107. value = self.opc_value.get_Manual_printdown()
  108. value = self.opc_value.get_Manual_printok()
  109. # stat = self.opc_value.get_PLC_ok()
  110. def check_opc_stat(self):
  111. self.opc_value.check_Bee()
  112. self.opc_value.check_Product_idx()
  113. self.opc_value.check_Product_name()
  114. self.opc_value.check_Batch_y()
  115. self.opc_value.check_Batch_m()
  116. self.opc_value.check_Batch_d()
  117. self.opc_value.check_Air_data_17700()
  118. self.opc_value.check_Air_data_17720()
  119. self.opc_value.check_Ok_count()
  120. self.opc_value.check_Ng_count()
  121. self.opc_value.check_Targe_count()
  122. self.opc_value.check_SNP_count()
  123. self.opc_value.check_Origin_ok()
  124. self.opc_value.check_Origin_dir()
  125. self.opc_value.check_Upairtight_ok()
  126. self.opc_value.check_Upairtight_ng()
  127. self.opc_value.check_Downairtight_ok()
  128. self.opc_value.check_Downairtight_ng()
  129. self.opc_value.check_Upprint_ok()
  130. self.opc_value.check_Downprint_ok()
  131. self.opc_value.check_Upgage_s()
  132. self.opc_value.check_Downgage_s()
  133. self.opc_value.check_Upwork_s()
  134. self.opc_value.check_Downwork_s()
  135. self.opc_value.check_Upm_pen()
  136. self.opc_value.check_Downm_pen()
  137. self.opc_value.check_Upconnect()
  138. self.opc_value.check_Downconnect()
  139. self.opc_value.check_Motororgin_ok()
  140. self.opc_value.check_Motor_onup()
  141. self.opc_value.check_Motor_ondown()
  142. self.opc_value.check_Manual_print()
  143. self.opc_value.check_Manual_printup()
  144. self.opc_value.check_Manual_printdown()
  145. self.opc_value.check_Manual_printok()
  146. self.opc_value.check_PLC_ok()
  147. self.opc_value.check_Airdata_stat()
  148. self.opc_value.check_Auto_printok()
  149. self.opc_value.check_Airtest_ok_r()
  150. self.opc_value.check_Airtest_ok_w()
  151. self.opc_value.check_Airtest_ng_r()
  152. self.opc_value.check_Airtest_ng_w()
  153. self.opc_value.check_Start_work()
  154. self.opc_value.check_Print_start()
  155. def batch_pro(self):
  156. value = datetime.datetime.now().month
  157. if value >= 1 and value <= 9:
  158. m_asc = value + 0x30
  159. elif value >= 10 and value <= 12:
  160. m_asc = value + 78
  161. m = self.opc_value.get_Batch_m()
  162. if m != m_asc:
  163. self.opc_value.set_Batch_m(m_asc)
  164. self.user_var.batch_m = '{}'.format(chr(m_asc))
  165. value = datetime.datetime.now().day
  166. d = self.opc_value.get_Batch_d()
  167. if d != value:
  168. self.opc_value.set_Batch_d(value)
  169. self.user_var.batch_d = '{0:02d}'.format(value)
  170. self.user_var.batch = self.user_var.batch_y + self.user_var.batch_m + self.user_var.batch_d
  171. self.user_var.batch_str.set(self.user_var.batch)
  172. def product_number_pro(self):
  173. self.user_var.number_value = '{0}{1}{2}{3}{4:04d}{5}'.format(self.user_var.number_type,
  174. self.user_var.batch_y, self.user_var.batch_m,
  175. self.user_var.batch_d,
  176. self.user_var.number_count,
  177. chr(self.user_var.team_sel + ord('A')))
  178. self.user_var.printf_num_str.set(self.user_var.number_value)
  179. self.user_var.serial_num_value = '{0:04d}{1:02d}{2:02d}{3:05d}'.format(datetime.datetime.now().year,
  180. datetime.datetime.now().month,
  181. datetime.datetime.now().day,
  182. self.user_var.serial_num)
  183. self.user_var.serial_num_str.set(self.user_var.serial_num_value)
  184. def insert_airdata(self):
  185. print("Save Data")
  186. # self.update_order_tbl(self.user_var.order_num, ok=self.user_var.order_ok,
  187. # ng=self.user_var.order_ng, targe=self.user_var.order_targe,
  188. # snp=self.user_var.order_snp)
  189. self.insert_data_tbl()
  190. def update_airdata(self, stat):
  191. print("Update Data")
  192. self.update_data_tbl(stat)
  193. def air_work_pro(self):
  194. if self.user_var.opc_conn_stat == "PLC已连接":
  195. datastat = self.opc_value.get_Airdata_stat()
  196. printok = self.opc_value.get_Auto_printok()
  197. airok_r = self.opc_value.get_Airtest_ok_r()
  198. airok_w = self.opc_value.get_Airtest_ok_w()
  199. airng_r = self.opc_value.get_Airtest_ng_r()
  200. airng_w = self.opc_value.get_Airtest_ng_w()
  201. startwork = self.opc_value.get_Start_work()
  202. if self.user_var.airdata_work_stat == 'working':
  203. if airok_r == True and airok_w == True:
  204. print("ok to printing")
  205. self.user_var.product_ok = True
  206. self.insert_airdata()
  207. # self.opc_value.set_Airdata_stat(1)
  208. self.opc_value.set_Airtest_ok_w(False)
  209. self.tcpserverParam.wr_data = self.user_var.number_value
  210. self.tcpserverParam.wr_stat = True
  211. self.user_var.airdata_work_stat = 'printing'
  212. elif airng_r == True and airng_w == True:
  213. print("ng to finish")
  214. self.user_var.order_ng = self.user_var.order_ng + 1
  215. self.user_var.order_targe = self.user_var.order_targe + 1
  216. self.update_order_tbl(self.user_var.order_num, ng=self.user_var.order_ng,
  217. targe=self.user_var.order_targe)
  218. self.user_var.product_ok = False
  219. self.insert_airdata()
  220. self.update_airdata(False)
  221. # self.opc_value.set_Airdata_stat(1)
  222. self.opc_value.set_Airtest_ng_w(False)
  223. self.user_var.airdata_work_stat = 'finish'
  224. elif self.user_var.airdata_work_stat == 'printing':
  225. if self.tcpserverParam.wr_stat == False:
  226. print("ok to printed")
  227. self.user_var.airdata_work_stat = 'printed'
  228. self.opc_value.set_Print_start(True)
  229. elif self.user_var.airdata_work_stat == 'printed':
  230. if printok == True:
  231. print("ok to finish")
  232. self.user_var.order_ok = self.user_var.order_ok + 1
  233. self.user_var.order_targe = self.user_var.order_targe + 1
  234. self.update_order_tbl(self.user_var.order_num, ok=self.user_var.order_ok,
  235. targe=self.user_var.order_targe)
  236. self.update_airdata(True)
  237. self.opc_value.set_Print_start(False)
  238. self.opc_value.set_Auto_printok(False)
  239. self.user_var.airdata_work_stat = 'finish'
  240. elif self.user_var.airdata_work_stat == 'finish':
  241. if startwork == False:
  242. print("to working")
  243. self.opc_value.set_Start_work(True)
  244. self.user_var.airdata_work_stat = 'working'
  245. self.user_var.serial_num = self.user_var.order_ok + self.user_var.order_ng + 1
  246. self.user_var.number_count = self.user_var.order_ok + 1
  247. self.product_number_pro()
  248. self.user_var.serial_num_working = self.user_var.serial_num_value
  249. # def database_pro(self):
  250. def update_data_tbl(self, status):
  251. sqlstr = 'UPDATE product_data_tbl SET '
  252. if status == True:
  253. sqlstr = sqlstr + "batch='{0}', testok={1}, data_17700='{2}', data_17720='{3}', end_time={4}, stat={5} WHERE serial = '{6}'".format(
  254. self.user_var.number_value, True, self.user_var.airtightness_17700, self.user_var.airtightness_17720,
  255. int(time.time()), True, self.user_var.serial_num_working)
  256. else:
  257. sqlstr = sqlstr + "end_time={0}, data_17700='{1}', data_17720='{2}', stat={3} WHERE serial = '{4}'".format(
  258. int(time.time()), self.user_var.airtightness_17700, self.user_var.airtightness_17720, True,
  259. self.user_var.serial_num_working)
  260. self.sqlclient.sql_action_all(sqlstr)
  261. def insert_data_tbl(self):
  262. sqlstr = "INSERT INTO product_data_tbl "
  263. sqlstr = sqlstr + "(batch, serial, product_name, testok, data_17700, data_17720, team, tester, begin_time, end_time, stat)"
  264. sqlstr = sqlstr + " VALUES ('{0}', '{1}', '{2}', {3}, '{4}', '{5}', '{6}', '{7}', {8}, {9}, {10})".format(
  265. 'NULL',
  266. self.user_var.serial_num_value,
  267. self.user_var.product_name,
  268. False,
  269. 'NULL',
  270. 'NULL',
  271. str(self.user_var.team),
  272. 'tester',
  273. int(time.time()),
  274. int(time.time()),
  275. False
  276. )
  277. self.sqlclient.sql_action_all(sqlstr)
  278. def update_order_tbl(self, order_num, ok=-1, ng=-1, targe=-1, snp=-1, end_time=-1, stat=False):
  279. first = False
  280. sqlstr = 'UPDATE order_tbl SET '
  281. if ok >=0:
  282. sqlstr = sqlstr + ' ok={0}'.format(ok)
  283. first = True
  284. if ng >= 0:
  285. if first == True:
  286. sqlstr = sqlstr + ', '
  287. sqlstr = sqlstr + 'ng={0} '.format(ng)
  288. first = True
  289. if targe >=0:
  290. if first == True:
  291. sqlstr = sqlstr + ', '
  292. sqlstr = sqlstr + 'targe={0} '.format(targe)
  293. first = True
  294. if snp >= 0:
  295. if first == True:
  296. sqlstr = sqlstr + ', '
  297. sqlstr = sqlstr + 'snp={0} '.format(snp)
  298. first = True
  299. if end_time >= 0:
  300. if first == True:
  301. sqlstr = sqlstr + ', '
  302. sqlstr = sqlstr + 'end_time={0} '.format(end_time)
  303. first = True
  304. if stat == True:
  305. if first == True:
  306. sqlstr = sqlstr + ', '
  307. sqlstr = sqlstr + 'stat={0} '.format(stat)
  308. sqlstr = sqlstr + " WHERE order_num = '{0}'".format(order_num)
  309. self.sqlclient.sql_action_all(sqlstr)
  310. def insert_order_tbl(self, ok, ng, targe, snp):
  311. self.user_var.order_ok = ok
  312. self.user_var.order_ng = ng
  313. self.user_var.order_targe = targe
  314. self.user_var.order_snp = snp
  315. sqlstr = "INSERT INTO order_tbl "
  316. sqlstr = sqlstr + "(order_num, product_idx, product_name, batch, team, ok, ng, targe, snp, begin_time, stat)"
  317. sqlstr = sqlstr + " VALUES ('{0}', {1}, '{2}', '{3}', '{4}', {5}, {6}, {7}, {8}, {9}, {10})".format(self.user_var.order_num,
  318. self.user_var.product_idx,
  319. self.user_var.product_name,
  320. self.user_var.batch,
  321. str(self.user_var.team),
  322. self.user_var.order_ok,
  323. self.user_var.order_ng,
  324. self.user_var.order_targe,
  325. self.user_var.order_snp,
  326. int(time.time()),
  327. False)
  328. self.sqlclient.sql_action_all(sqlstr)
  329. def order_tbl_check(self):
  330. sqlstr = 'SELECT id, order_num,product_idx, product_name, batch, team, ok, ng, targe, snp FROM order_tbl WHERE stat=False ORDER by begin_time DESC'
  331. results = self.sqlclient.sql_inquire_all(sqlstr)
  332. if results != None and len(results) > 0:
  333. idx = 0
  334. for row in results:
  335. if idx == 0:
  336. order_num = row[1]
  337. product_idx = row[2]
  338. product_name = row[3]
  339. batch = row[4]
  340. team = row[5]
  341. ok = row[6]
  342. ng = row[7]
  343. targe = row[8]
  344. snp = row[9]
  345. if self.user_var.batch == batch:
  346. self.user_var.order_num = order_num
  347. self.user_var.team = team
  348. self.user_var.team_sel = ord(self.user_var.team) - ord('A')
  349. self.user_var.team_value = self.user_var.team_list[self.user_var.team_sel]
  350. self.user_var.order_ok = ok
  351. self.user_var.order_ng = ng
  352. self.user_var.order_targe = targe
  353. self.user_var.order_snp = snp
  354. self.user_var.number_count = self.user_var.order_ok + 1
  355. self.user_var.serial_num = self.user_var.order_ok + self.user_var.order_ng + 1
  356. else:
  357. self.update_order_tbl(order_num, end_time=int(time.time()) ,stat=True)
  358. self.insert_order_tbl(0, 0, 0, 0)
  359. else:
  360. order_num = row[1]
  361. self.update_order_tbl(order_num, stat=True)
  362. idx = idx + 1
  363. else:
  364. self.insert_order_tbl(0,0,0,0)
  365. # def insert_param_tbl(self, type):
  366. # sqlstr = "INSERT INTO product_param_tbl "
  367. # sqlstr = sqlstr + "(product_idx,product_name,param_type,startuptime,airtime,presstime, testtime, \
  368. # exhaust, maxpress, minpress, setpress, capacity, \
  369. # posthreshold, pnegthreshold)"
  370. # if type == 17700:
  371. # sqlstr = sqlstr + " VALUES ({0}, '{1}', {2}, '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0')".format(
  372. # self.user_var.product_idx+1,
  373. # self.user_var.product_name,
  374. # 17700)
  375. # else:
  376. # sqlstr = sqlstr + " VALUES ({0}, '{1}', {2}, '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0')".format(
  377. # self.user_var.product_idx+1,
  378. # self.user_var.product_name,
  379. # 17720)
  380. # self.sqlclient.sql_action_all(sqlstr)
  381. #
  382. # def param_tbl_check(self):
  383. # sqlstr = "SELECT startuptime,airtime,presstime, testtime, exhaust, maxpress, minpress, setpress, capacity, \
  384. # posthreshold, pnegthreshold FROM product_param_tbl WHERE product_name='{0}' and \
  385. # param_type=17700".format(self.user_var.product_name)
  386. # paramresult = self.sqlclient.sql_inquire_all(sqlstr)
  387. # if paramresult != None and len(paramresult) > 0:
  388. # for paramrow in paramresult:
  389. # self.user_var.startdelay_17700_str.set(paramrow[0])
  390. # self.user_var.airtime_17700_str.set(paramrow[1])
  391. # self.user_var.presstime_17700_str.set(paramrow[2])
  392. # self.user_var.testtime_17700_str.set(paramrow[3])
  393. # self.user_var.exhaust_17700_str.set(paramrow[4])
  394. # self.user_var.maxpress_17700_str.set(paramrow[5])
  395. # self.user_var.minpress_17700_str.set(paramrow[6])
  396. # self.user_var.setpress_17700_str.set(paramrow[7])
  397. # self.user_var.capacity_17700_str.set(paramrow[8])
  398. # self.user_var.posthreshold_17700_str.set(paramrow[9])
  399. # self.user_var.pnegthreshold_17700_str.set(paramrow[10])
  400. # else:
  401. # self.user_var.startdelay_17700_str.set("0")
  402. # self.user_var.airtime_17700_str.set("0")
  403. # self.user_var.presstime_17700_str.set("0")
  404. # self.user_var.testtime_17700_str.set("0")
  405. # self.user_var.exhaust_17700_str.set("0")
  406. # self.user_var.maxpress_17700_str.set("0")
  407. # self.user_var.minpress_17700_str.set("0")
  408. # self.user_var.setpress_17700_str.set("0")
  409. # self.user_var.capacity_17700_str.set("0")
  410. # self.user_var.posthreshold_17700_str.set("0")
  411. # self.user_var.pnegthreshold_17700_str.set("0")
  412. # self.insert_param_tbl(17700)
  413. #
  414. # sqlstr = "SELECT startuptime,airtime,presstime, testtime, exhaust, maxpress, minpress, setpress, capacity, \
  415. # posthreshold, pnegthreshold FROM product_param_tbl WHERE product_name='{0}' and \
  416. # param_type=17720".format(self.user_var.product_name)
  417. # paramresult = self.sqlclient.sql_inquire_all(sqlstr)
  418. # if paramresult != None and len(paramresult) > 0:
  419. # for paramrow in paramresult:
  420. # self.user_var.startdelay_17720_str.set(paramrow[0])
  421. # self.user_var.airtime_17720_str.set(paramrow[1])
  422. # self.user_var.presstime_17720_str.set(paramrow[2])
  423. # self.user_var.testtime_17720_str.set(paramrow[3])
  424. # self.user_var.exhaust_17720_str.set(paramrow[4])
  425. # self.user_var.maxpress_17720_str.set(paramrow[5])
  426. # self.user_var.minpress_17720_str.set(paramrow[6])
  427. # self.user_var.setpress_17720_str.set(paramrow[7])
  428. # self.user_var.capacity_17720_str.set(paramrow[8])
  429. # self.user_var.posthreshold_17720_str.set(paramrow[9])
  430. # self.user_var.pnegthreshold_17720_str.set(paramrow[10])
  431. # else:
  432. # self.user_var.startdelay_17720_str.set("0")
  433. # self.user_var.airtime_17720_str.set("0")
  434. # self.user_var.presstime_17720_str.set("0")
  435. # self.user_var.testtime_17720_str.set("0")
  436. # self.user_var.exhaust_17720_str.set("0")
  437. # self.user_var.maxpress_17720_str.set("0")
  438. # self.user_var.minpress_17720_str.set("0")
  439. # self.user_var.setpress_17720_str.set("0")
  440. # self.user_var.capacity_17720_str.set("0")
  441. # self.user_var.posthreshold_17720_str.set("0")
  442. # self.user_var.pnegthreshold_17720_str.set("0")
  443. # self.insert_param_tbl(17720)
  444. def product_name_set(self):
  445. sqlstr = "SELECT product_idx,product_name,17700_name,17720_name FROM product_tbl WHERE stat=True"
  446. paramresult = self.sqlclient.sql_inquire_all(sqlstr)
  447. if paramresult != None and len(paramresult) > 0:
  448. for paramrow in paramresult:
  449. product_idx = paramrow[0]
  450. product_name = paramrow[1]
  451. name_17700 = paramrow[2]
  452. name_17720 = paramrow[3]
  453. if product_idx < 14:
  454. self.user_var.product_list[product_idx] = product_name
  455. self.user_var.product_list_str[product_idx].set(product_name)
  456. self.user_var.product_17700_list[product_idx] = name_17700
  457. self.user_var.product_17720_list[product_idx] = name_17720
  458. self.user_var.product_load = False
  459. def product_name_check(self):
  460. value = self.opc_value.get_Product_idx()
  461. self.user_var.opc_product_idx = value
  462. value = self.opc_value.get_Product_name()
  463. self.user_var.opc_product_name = value
  464. if self.user_var.opc_product_idx <= 14:
  465. if self.user_var.product_list[self.user_var.opc_product_idx-1] == self.user_var.opc_product_name:
  466. self.user_var.product_idx = self.user_var.opc_product_idx-1
  467. self.user_var.product_name = self.user_var.product_list[self.user_var.product_idx]
  468. self.user_var.product_17700_name = self.user_var.product_17700_list[self.user_var.product_idx]
  469. self.user_var.product_17720_name = self.user_var.product_17720_list[self.user_var.product_idx]
  470. self.user_var.product_name_noset = '品番已设置'
  471. self.user_var.product_idx_str.set(self.user_var.product_idx + 1)
  472. self.user_var.product_str.set(self.user_var.product_name)
  473. else:
  474. self.user_var.product_idx = 0
  475. self.user_var.product_name = ''
  476. self.user_var.product_17700_name = ''
  477. self.user_var.product_17720_name = ''
  478. self.user_var.product_name_noset = '品番不存在,请设置...'
  479. else:
  480. self.user_var.product_idx = 0
  481. self.user_var.product_name = ''
  482. self.user_var.product_17700_name = ''
  483. self.user_var.product_17720_name = ''
  484. self.user_var.product_name_noset = '品番编号超过14'
  485. def everyday_check(self):
  486. if self.order_change_timeout == 0:
  487. self.order_change_timeout = 10
  488. self.batch_pro()
  489. tt_check = False
  490. c_time = time.strftime("%H:%M:%S", time.localtime())
  491. if c_time[0:2] == '00': # 判断截取小时是否为0
  492. if c_time[3:5] == '00': # 判断截取分钟是否为0
  493. if c_time[6:8] == '00': # 判断截取秒是否为0
  494. tt_check = True
  495. if tt_check == True:
  496. self.update_order_tbl(self.user_var.order_num, end_time=int(time.time()), stat=True)
  497. self.user_var.order_count = 1
  498. self.user_var.order_num = '{0}{1}{2}{3:02d}'.format(self.user_var.number_type,
  499. datetime.datetime.now().strftime('%Y%m%d%H%M%S'),
  500. chr(self.user_var.team_sel + ord('A')),
  501. self.user_var.order_count)
  502. self.insert_order_tbl(0, 0, 0, 0)
  503. self.user_var.serial_num = self.user_var.order_ok + self.user_var.order_ng + 1
  504. self.user_var.number_count = self.user_var.order_ok + 1
  505. print("insert order_tbl everyday!")
  506. elif self.user_var.order_update_stat == True:
  507. self.user_var.order_update_stat = False
  508. self.update_order_tbl(self.user_var.order_num, end_time=int(time.time()), stat=True)
  509. self.insert_order_tbl(self.user_var.order_ok, self.user_var.order_ng,
  510. self.user_var.order_targe, self.user_var.order_snp)
  511. else:
  512. self.order_change_timeout = self.order_change_timeout - 1
  513. def plc_conn_check(self):
  514. if self.plc_conn_timeout == 0:
  515. self.plc_conn_timeout = 20
  516. if self.user_var.workstatstr == True:
  517. self.user_var.workstatstr = False
  518. self.opc_value.set_PLC_ok(True)
  519. else:
  520. self.user_var.workstatstr = True
  521. self.opc_value.set_PLC_ok(False)
  522. else:
  523. self.plc_conn_timeout = self.plc_conn_timeout - 1
  524. def exit(self):
  525. self.exit_stat = True
  526. def run(self):
  527. self.product_name_set()
  528. while self.user_var.opc_conn_stat != "PLC已连接":
  529. if self.exit_stat == True:
  530. break
  531. time.sleep(1)
  532. if self.exit_stat == False:
  533. self.batch_pro()
  534. self.order_tbl_check()
  535. # self.param_tbl_check()
  536. while self.exit_stat == False:
  537. with main.threadlock:
  538. if self.user_var.product_load == True:
  539. self.product_name_set()
  540. self.product_name_check()
  541. self.plc_conn_check()
  542. self.opc_data_pro()
  543. self.check_opc_stat()
  544. self.air_work_pro()
  545. self.everyday_check()
  546. self.product_number_pro()
  547. time.sleep(0.1)
  548. print("work进程结束!")
  549. self.user_var.pro_exit_stat = True