Advertisement
Guest User

Untitled

a guest
May 13th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.63 KB | None | 0 0
  1. 54685822831import sys
  2. sys.path.insert(0, "..")
  3. import socket
  4. import time
  5. from opcua import Client,ua
  6. import fdb
  7. import os
  8. from Tkinter import *
  9. from tkMessageBox import *
  10. import smbus
  11.  
  12. #################### DEFINITIONS ####################
  13. root = Tk()
  14. root["bg"]="black"
  15. root.attributes("-fullscreen",True)
  16. for i in xrange(2):
  17. root.columnconfigure(i,weight=1)
  18. for i in xrange(3):
  19. root.rowconfigure(i,weight=1)
  20. root.rowconfigure(1,weight=2)
  21. barcode = 0
  22. r_o=50
  23. barcode = 0
  24. bus = smbus.SMBus(1)
  25. address = 0x04
  26. zrobiono=1
  27. system=['50MM', 'CTR', '70MM SZNUR', 'DREWNO', '50 MONOKOMANDO']
  28. control=['None', 'LL', 'RR', 'L+R', 'RRR', 'L+RR', 'LL+R', 'LLL']
  29.  
  30. frame_label=Frame(root)#, border=1, relief='solid')
  31. frame_label.grid(column=0,row=0,sticky="wn")
  32. frame_label["bg"]="black"
  33.  
  34. frame_codes=Frame(root)#, border=1, relief='solid')
  35. frame_codes.grid(column=1,row=0,sticky='ne')
  36. frame_codes["bg"]="black"
  37.  
  38. frame_data=Frame(root)#,border=1, relief='solid')
  39. frame_data.grid(column=0, columnspan=2,row=1, sticky='nsew')
  40. frame_data["bg"]="black"
  41.  
  42. for i in xrange(4):
  43. frame_label.rowconfigure(i,weight=1)
  44. for i in xrange(3):
  45. frame_label.rowconfigure(i,weight=1)
  46. for i in xrange(2):
  47. frame_label.columnconfigure(i,weight=1)
  48.  
  49. def opcConnect():
  50. global systemNode
  51. global widthNode
  52. global controlNode
  53. global client
  54. client = Client("opc.tcp://prasahkl:prasahkl@192.168.0.20:4844/BuR/UA/EmbeddedServer") #connect using a user
  55. client.connect()
  56. root = client.get_root_node()
  57.  
  58. systemNode = root.get_child(["0:Objects", "4:PLC", "6:Modules", "6:::", "6:Global PV", "6:g_ActRec"])
  59. marginNode = root.get_child(["0:Objects", "4:PLC", "6:Modules", "6:::", "6:Global PV", "6:Parameter", "6:Margin"])
  60. widthNode = root.get_child(["0:Objects", "4:PLC", "6:Modules", "6:::", "6:Global PV", "6:Parameter", "6:Width"])
  61. controlNode = root.get_child(["0:Objects", "4:PLC", "6:Modules", "6:::", "6:Screen", "6:d_actRec", "6:MechanismLocationType"])
  62.  
  63. def writeNumber(value):
  64. bus.write_byte(address, value)
  65.  
  66. def connectFDB():
  67. global widthFDB
  68. global barcode
  69. global systemFDB
  70. global labelFDB
  71. global controlFDB
  72. global kolorFDB
  73. global monokomando
  74. global ster
  75. global stster
  76.  
  77. con = fdb.connect(host='192.168.0.1', database='/dane/baza/PROD1.gdb', user='sysdba', password='masterkey',charset='utf8')
  78. cur = con.cursor()
  79. SELECT = "select a.NAME, a.B, a.ST, a.TYP, a.KOLOR, a.RD, a.STER, a.STSTER from pos a where a.code=%s" % (barcode)
  80. cur.execute(SELECT)
  81. for (NAME, B, ST, TYP, KOLOR, RD, STER, STSTER) in cur:
  82. widthFDB=B
  83. labelFDB=NAME
  84. systemFDB=TYP
  85. controlFDB=ST
  86. kolorFDB=KOLOR
  87. monokomando=RD
  88. ster=STER
  89. stster=STSTER
  90.  
  91. def skaner(event):
  92. global barcode
  93. global labelFDB
  94. global widthFDB
  95. global systemFDB
  96. global controlFDB
  97. global kolorFDB
  98. global monokomando
  99. global systemNode
  100. global marginNode
  101. global widthNode
  102. global controlNode
  103. global control_set
  104. global system_set
  105. global ster
  106. global stster
  107. global zrobiono
  108. global client
  109.  
  110. barcode = bCode.get()
  111. login='000111'
  112. wycinanie='0005'
  113. wycinanie2='011'
  114.  
  115. if len(barcode)!=16:
  116. for i in range(0, len(barcode)):
  117. number=ord(barcode[i])
  118. writeNumber(number)
  119. time.sleep(0.025)
  120. writeNumber(10)
  121.  
  122. if len(barcode)==16:
  123. for i in range(0, len(login)):
  124. number=ord(login[i])
  125. writeNumber(number)
  126. time.sleep(0.025)
  127. writeNumber(10)
  128. time.sleep(0.025)
  129. for i in range(0, len(wycinanie)):
  130. number=ord(wycinanie[i])
  131. writeNumber(number)
  132. time.sleep(0.025)
  133. writeNumber(10)
  134. time.sleep(0.025)
  135. for i in range(0, len(wycinanie2)):
  136. number=ord(wycinanie2[i])
  137. writeNumber(number)
  138. time.sleep(0.025)
  139. writeNumber(10)
  140. time.sleep(0.025)
  141. for i in range(0, len(barcode)):
  142. number=ord(barcode[i])
  143. writeNumber(number)
  144. time.sleep(0.025)
  145. writeNumber(10)
  146. time.sleep(0.025)
  147.  
  148. connectFDB()
  149. kolorFDB = kolorFDB.rstrip('vf')
  150. kolorFDB = kolorFDB.rstrip('cn')
  151. system_set = systemChoice(int(kolorFDB.rstrip('-')))
  152. if system_set == 0:
  153. system_set = systemFDB
  154. if controlFDB != 'A' and controlFDB != 'B' and controlFDB != 'C' and controlFDB != 'D' and controlFDB != 'RL' and controlFDB != 'LR' and controlFDB != 'RR' and controlFDB != 'LL':
  155. controlFDB = stster
  156. if stster != 'A' and stster != 'B' and stster != 'C' and stster != 'D' and stster != 'RL' and stster != 'LR' and stster != 'RR' and stster != 'LL':
  157. controlFDB = ster
  158. control_set = controlChoice(system_set)
  159. system_data.config(text=system_set)
  160. width_data.config(text=widthFDB)
  161. label_label.config(text=labelFDB)
  162. control_data.config(text=control_set)
  163. zrobiono_data.config(text=zrobiono)
  164. bCode.config(state='readonly')
  165. zrobiono=zrobiono+1
  166. ####################################################################################################
  167. opcConnect()
  168. print widthNode.get_data_value()
  169. print system.index(system_set)
  170. systemNode.set_value(ua.Variant([system.index(system_set)], ua.VariantType.Byte))
  171. time.sleep(0.5)
  172. widthNode.set_value(ua.Variant([widthFDB], ua.VariantType.Float))
  173. time.sleep(0.5)
  174. try:
  175. controlNode.set_value(ua.Variant([control.index(control_set)], ua.VariantType.Int32))
  176. except Exception:
  177. print 'blad'
  178. ####################################################################################################
  179. client.disconnect()
  180. conf.config(state='normal')
  181. conf.focus_set()
  182.  
  183. def zapis_Sql():
  184.  
  185. global system_set
  186. global widthFDB
  187. global control_set
  188. global kolorFDB
  189.  
  190. bazaSql = MySQLdb.connect("192.168.0.111","root","serwishkl1","wycinanie_szyn")
  191. conSql = bazaSql.cursor()
  192. try:
  193. conSql.execute("INSERT INTO test(system,kolor,dlugosc,strona_sterowania) values ('%s','%s','%s','%s')" % (system_set, kolorFDB, widthFDB, control_set))
  194. bazaSql.commit()
  195. except:
  196. bazaSql.rollback()
  197. conSql.close()
  198.  
  199. def controlChoice(system_set):
  200. global controlFDB
  201. global widthFDB
  202. ret = 0
  203. widthFDB=widthFDB*10
  204. if system_set == 'CTR':
  205. if widthFDB <= 1000:
  206. if controlFDB == 'RL' or controlFDB == 'A' or controlFDB == 'LR' or controlFDB == 'B':
  207. ret = 'L+R'
  208. if controlFDB == 'LL' or controlFDB == 'C':
  209. ret = 'LL'
  210. if controlFDB == 'RR' or controlFDB == 'D':
  211. ret = 'RR'
  212. if widthFDB > 1000:
  213. if controlFDB == 'RL' or controlFDB == 'A':
  214. ret = 'L+RR'
  215. if controlFDB == 'LR' or controlFDB == 'B':
  216. ret = 'LL+R'
  217. if controlFDB == 'LL' or controlFDB == 'C':
  218. ret = 'LLL'
  219. if controlFDB == 'RR' or controlFDB == 'D':
  220. ret = 'RRR'
  221. if system_set == 'DREWNO':
  222. if widthFDB <= 1400:
  223. if controlFDB == 'RL' or controlFDB == 'A' or controlFDB == 'LR' or controlFDB == 'B':
  224. ret = 'L+R'
  225. if controlFDB == 'LL' or controlFDB == 'C':
  226. ret = 'LL'
  227. if controlFDB == 'RR' or controlFDB == 'D':
  228. ret = 'RR'
  229. if widthFDB > 1400:
  230. if controlFDB == 'RL' or controlFDB == 'A':
  231. ret = 'L+RR'
  232. if controlFDB == 'LR' or controlFDB == 'B':
  233. ret = 'LL+R'
  234. if controlFDB == 'LL' or controlFDB == 'C':
  235. ret = 'LLL'
  236. if controlFDB == 'RR' or controlFDB == 'D':
  237. ret = 'RRR'
  238. if system_set == '70MM SZNUR':
  239. if widthFDB <= 1500:
  240. if controlFDB == 'RL' or controlFDB == 'A' or controlFDB == 'LR' or controlFDB == 'B':
  241. ret = 'L+R'
  242. if controlFDB == 'LL' or controlFDB == 'C':
  243. ret = 'LL'
  244. if controlFDB == 'RR' or controlFDB == 'D':
  245. ret = 'RR'
  246. if widthFDB > 1500:
  247. if controlFDB == 'RL' or controlFDB == 'A':
  248. ret = 'L+RR'
  249. if controlFDB == 'LR' or controlFDB == 'B':
  250. ret = 'LL+R'
  251. if controlFDB == 'LL' or controlFDB == 'C':
  252. ret = 'LLL'
  253. if controlFDB == 'RR' or controlFDB == 'D':
  254. ret = 'RRR'
  255. if system_set == '50MM':
  256. if widthFDB <= 2120:
  257. if controlFDB == 'RL' or controlFDB == 'A' or controlFDB == 'LR' or controlFDB == 'B':
  258. ret = 'L+R'
  259. if controlFDB == 'LL' or controlFDB == 'C':
  260. ret = 'LL'
  261. if controlFDB == 'RR' or controlFDB == 'D':
  262. ret = 'RR'
  263. if widthFDB > 2120:
  264. if controlFDB == 'RL' or controlFDB == 'A':
  265. ret = 'L+RR'
  266. if controlFDB == 'LR' or controlFDB == 'B':
  267. ret = 'LL+R'
  268. if controlFDB == 'LL' or controlFDB == 'C':
  269. ret = 'LLL'
  270. if controlFDB == 'RR' or controlFDB == 'D':
  271. ret = 'RRR'
  272. if system_set == '50 MONOKOMANDO':
  273. ret = 'None'
  274.  
  275. return ret
  276.  
  277. def systemChoice(kolor):
  278. global monokomando
  279. global systemFDB
  280. ret = 0
  281. drewno = [101, 155, 105, 106, 138, 141, 102, 133, 154, 130, 144,
  282. 110, 135, 108, 146, 151, 312, 113, 313, 158, 131, 112,
  283. 114, 116, 134, 125, 126, 119, 147, 309, 311, 136, 115,
  284. 132, 128, 129, 120, 121, 123, 156, 5500, 5468, 5499,
  285. 5101, 5102, 5105, 5106, 5108, 5110, 5112, 5113, 5114,
  286. 5115, 5116, 5119, 5120, 5121, 5123, 5125, 5126, 5128,
  287. 5129, 5130, 5131, 5132, 5133, 5134, 5135, 5136, 5138,
  288. 5141, 5144, 5146, 5147, 5151, 5154, 5155, 5156, 5158,
  289. 5112, 5462, 5534, 5541, 5528, 5535, 5543, 5537, 5529,
  290. 5538, 5531, 5531, 5539, 5530, 5542, 5533, 5540, 5536,
  291. 526, 522, 527, 525, 523, 524, 5532, 5535, 5543, 5537,
  292. 5529, 5531, 5539, 5530, 5542, 533, 5540, 5536, 5528,
  293. 5550, 5468, 5499, 106, 5478]
  294.  
  295. CTR = [400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411,
  296. 412, 413, 415, 416, 417, 418, 419, 420, 542, 544, 685, 686,
  297. 687, 688, 689, 690, 691, 421, 422]
  298.  
  299. if ret == 0:
  300. for i in range(0, len(drewno)):
  301. if kolor == drewno[i]:
  302. ret = 'DREWNO'
  303. break
  304. else:
  305. ret = 0
  306. if ret == 0:
  307. for i in range(0, len(CTR)):
  308. if kolor == CTR[i]:
  309. ret = 'CTR'
  310. break
  311. else:
  312. ret = 0
  313. if ret == 0:
  314. if monokomando.rstrip('-') == "K" or monokomando.rstrip('-')=="E" or monokomando.rstrip('-')=="EL":
  315. ret = '50 MONOKOMANDO'
  316. else:
  317. ret = 0
  318. if ret == 0:
  319. if systemFDB.rstrip('-') == "50" or systemFDB.rstrip('-') == "i50":
  320. ret = '50MM'
  321. elif systemFDB.rstrip('-') == 'i70' or systemFDB.rstrip('-') == '70':
  322. ret = '70MM SZNUR'
  323. else:
  324. ret = 0
  325.  
  326. return ret
  327.  
  328. def confirm(event):
  329. global systemNode
  330. global controlNode
  331. global widthNode
  332. global system
  333. global control
  334. global widthFDB
  335. global system_set
  336. global control_set
  337.  
  338. p = conf.get()
  339. conf.delete(0,END)
  340. for i in range(0, len(p)):
  341. number=ord(p[i])
  342. writeNumber(number)
  343. time.sleep(0.025)
  344. writeNumber(10)
  345. if p=='00':
  346. erase()
  347. conf.config(state="disable")
  348. bCode.config(state='normal')
  349. bCode.delete(0,END)
  350. bCode.focus_set()
  351. if p=='03':
  352. zapis_Sql()
  353. conf.config(state="disable")
  354. bCode.config(state='normal')
  355. bCode.delete(0,END)
  356. bCode.focus_set()
  357.  
  358. def erase():
  359. global labelFDB
  360. global widthFDB
  361. global systemFDB
  362. global controlFDB
  363. global monokomando
  364.  
  365. monokomando = ''
  366. controlFDB = ''
  367. labelFDB = ''
  368. widthFDB = ''
  369. systemFDB = ''
  370. system_data.config(text='')
  371. width_data.config(text='')
  372. control_data.config(text='')
  373. label_label.config(text='')
  374.  
  375. #### GUI #####
  376.  
  377. bCode = Entry(frame_codes,font=("Arial",16),background="black",foreground="green",highlightbackground="black",disabledbackground="black",disabledforeground="white",selectbackground="yellow")
  378. bCode.bind("<Return>",skaner)
  379. bCode.grid(column=1,row=0)
  380. conf=Entry(frame_codes,font=("Arial",16),background="black",foreground="green",highlightbackground="black",disabledbackground="black",disabledforeground="white")
  381. conf.bind("<Return>",confirm)
  382. conf.grid(column=1,row=1)
  383.  
  384. label_label = Label(frame_label,font=("Arial",30),wraplength=1000,background="black",foreground="white")
  385. label_label.grid()
  386. system_label = Label(frame_data,font=("Arial",r_o),text="System: ",background="black",foreground="white")
  387. system_label.grid(row=0,column=0,sticky="nw")
  388. width_label= Label(frame_data,font=("Arial",r_o),text="Szerokosc: ",background="black",foreground="white")
  389. width_label.grid(row=1,column=0,sticky="NSw")
  390. control_label= Label(frame_data,font=("Arial",r_o),text="Strona st: ",background="black",foreground="white")
  391. control_label.grid(row=2,column=0,sticky="NSw")
  392. zrobione_label=Label(frame_data,font=("Arial",r_o),text="Zrobiono: ",background="black",foreground="white")
  393. zrobione_label.grid(row=3,column=0,sticky="Sw")
  394.  
  395. system_data = Label(frame_data,font=("Arial",r_o),background="black",foreground="white")
  396. system_data.grid(row=0,column=1,sticky="nw")
  397. width_data= Label(frame_data,font=("Arial",r_o),background="black",foreground="white")
  398. width_data.grid(row=1,column=1,sticky="NSw")
  399. control_data= Label(frame_data,font=("Arial",r_o),background="black",foreground="white")
  400. control_data.grid(row=2,column=1,sticky="Sw")
  401. zrobiono_data= Label(frame_data,font=("Arial",r_o),background="black",foreground="white")
  402. zrobiono_data.grid(row=3,column=1,sticky="Sw")
  403.  
  404. if __name__ == '__main__':
  405. bCode.focus_set()
  406. conf.config(state='disable')
  407.  
  408. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement