Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 54685822831import sys
- sys.path.insert(0, "..")
- import socket
- import time
- from opcua import Client,ua
- import fdb
- import os
- from Tkinter import *
- from tkMessageBox import *
- import smbus
- #################### DEFINITIONS ####################
- root = Tk()
- root["bg"]="black"
- root.attributes("-fullscreen",True)
- for i in xrange(2):
- root.columnconfigure(i,weight=1)
- for i in xrange(3):
- root.rowconfigure(i,weight=1)
- root.rowconfigure(1,weight=2)
- barcode = 0
- r_o=50
- barcode = 0
- bus = smbus.SMBus(1)
- address = 0x04
- zrobiono=1
- system=['50MM', 'CTR', '70MM SZNUR', 'DREWNO', '50 MONOKOMANDO']
- control=['None', 'LL', 'RR', 'L+R', 'RRR', 'L+RR', 'LL+R', 'LLL']
- frame_label=Frame(root)#, border=1, relief='solid')
- frame_label.grid(column=0,row=0,sticky="wn")
- frame_label["bg"]="black"
- frame_codes=Frame(root)#, border=1, relief='solid')
- frame_codes.grid(column=1,row=0,sticky='ne')
- frame_codes["bg"]="black"
- frame_data=Frame(root)#,border=1, relief='solid')
- frame_data.grid(column=0, columnspan=2,row=1, sticky='nsew')
- frame_data["bg"]="black"
- for i in xrange(4):
- frame_label.rowconfigure(i,weight=1)
- for i in xrange(3):
- frame_label.rowconfigure(i,weight=1)
- for i in xrange(2):
- frame_label.columnconfigure(i,weight=1)
- def opcConnect():
- global systemNode
- global widthNode
- global controlNode
- global client
- client = Client("opc.tcp://prasahkl:prasahkl@192.168.0.20:4844/BuR/UA/EmbeddedServer") #connect using a user
- client.connect()
- root = client.get_root_node()
- systemNode = root.get_child(["0:Objects", "4:PLC", "6:Modules", "6:::", "6:Global PV", "6:g_ActRec"])
- marginNode = root.get_child(["0:Objects", "4:PLC", "6:Modules", "6:::", "6:Global PV", "6:Parameter", "6:Margin"])
- widthNode = root.get_child(["0:Objects", "4:PLC", "6:Modules", "6:::", "6:Global PV", "6:Parameter", "6:Width"])
- controlNode = root.get_child(["0:Objects", "4:PLC", "6:Modules", "6:::", "6:Screen", "6:d_actRec", "6:MechanismLocationType"])
- def writeNumber(value):
- bus.write_byte(address, value)
- def connectFDB():
- global widthFDB
- global barcode
- global systemFDB
- global labelFDB
- global controlFDB
- global kolorFDB
- global monokomando
- global ster
- global stster
- con = fdb.connect(host='192.168.0.1', database='/dane/baza/PROD1.gdb', user='sysdba', password='masterkey',charset='utf8')
- cur = con.cursor()
- 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)
- cur.execute(SELECT)
- for (NAME, B, ST, TYP, KOLOR, RD, STER, STSTER) in cur:
- widthFDB=B
- labelFDB=NAME
- systemFDB=TYP
- controlFDB=ST
- kolorFDB=KOLOR
- monokomando=RD
- ster=STER
- stster=STSTER
- def skaner(event):
- global barcode
- global labelFDB
- global widthFDB
- global systemFDB
- global controlFDB
- global kolorFDB
- global monokomando
- global systemNode
- global marginNode
- global widthNode
- global controlNode
- global control_set
- global system_set
- global ster
- global stster
- global zrobiono
- global client
- barcode = bCode.get()
- login='000111'
- wycinanie='0005'
- wycinanie2='011'
- if len(barcode)!=16:
- for i in range(0, len(barcode)):
- number=ord(barcode[i])
- writeNumber(number)
- time.sleep(0.025)
- writeNumber(10)
- if len(barcode)==16:
- for i in range(0, len(login)):
- number=ord(login[i])
- writeNumber(number)
- time.sleep(0.025)
- writeNumber(10)
- time.sleep(0.025)
- for i in range(0, len(wycinanie)):
- number=ord(wycinanie[i])
- writeNumber(number)
- time.sleep(0.025)
- writeNumber(10)
- time.sleep(0.025)
- for i in range(0, len(wycinanie2)):
- number=ord(wycinanie2[i])
- writeNumber(number)
- time.sleep(0.025)
- writeNumber(10)
- time.sleep(0.025)
- for i in range(0, len(barcode)):
- number=ord(barcode[i])
- writeNumber(number)
- time.sleep(0.025)
- writeNumber(10)
- time.sleep(0.025)
- connectFDB()
- kolorFDB = kolorFDB.rstrip('vf')
- kolorFDB = kolorFDB.rstrip('cn')
- system_set = systemChoice(int(kolorFDB.rstrip('-')))
- if system_set == 0:
- system_set = systemFDB
- if controlFDB != 'A' and controlFDB != 'B' and controlFDB != 'C' and controlFDB != 'D' and controlFDB != 'RL' and controlFDB != 'LR' and controlFDB != 'RR' and controlFDB != 'LL':
- controlFDB = stster
- if stster != 'A' and stster != 'B' and stster != 'C' and stster != 'D' and stster != 'RL' and stster != 'LR' and stster != 'RR' and stster != 'LL':
- controlFDB = ster
- control_set = controlChoice(system_set)
- system_data.config(text=system_set)
- width_data.config(text=widthFDB)
- label_label.config(text=labelFDB)
- control_data.config(text=control_set)
- zrobiono_data.config(text=zrobiono)
- bCode.config(state='readonly')
- zrobiono=zrobiono+1
- ####################################################################################################
- opcConnect()
- print widthNode.get_data_value()
- print system.index(system_set)
- systemNode.set_value(ua.Variant([system.index(system_set)], ua.VariantType.Byte))
- time.sleep(0.5)
- widthNode.set_value(ua.Variant([widthFDB], ua.VariantType.Float))
- time.sleep(0.5)
- try:
- controlNode.set_value(ua.Variant([control.index(control_set)], ua.VariantType.Int32))
- except Exception:
- print 'blad'
- ####################################################################################################
- client.disconnect()
- conf.config(state='normal')
- conf.focus_set()
- def zapis_Sql():
- global system_set
- global widthFDB
- global control_set
- global kolorFDB
- bazaSql = MySQLdb.connect("192.168.0.111","root","serwishkl1","wycinanie_szyn")
- conSql = bazaSql.cursor()
- try:
- conSql.execute("INSERT INTO test(system,kolor,dlugosc,strona_sterowania) values ('%s','%s','%s','%s')" % (system_set, kolorFDB, widthFDB, control_set))
- bazaSql.commit()
- except:
- bazaSql.rollback()
- conSql.close()
- def controlChoice(system_set):
- global controlFDB
- global widthFDB
- ret = 0
- widthFDB=widthFDB*10
- if system_set == 'CTR':
- if widthFDB <= 1000:
- if controlFDB == 'RL' or controlFDB == 'A' or controlFDB == 'LR' or controlFDB == 'B':
- ret = 'L+R'
- if controlFDB == 'LL' or controlFDB == 'C':
- ret = 'LL'
- if controlFDB == 'RR' or controlFDB == 'D':
- ret = 'RR'
- if widthFDB > 1000:
- if controlFDB == 'RL' or controlFDB == 'A':
- ret = 'L+RR'
- if controlFDB == 'LR' or controlFDB == 'B':
- ret = 'LL+R'
- if controlFDB == 'LL' or controlFDB == 'C':
- ret = 'LLL'
- if controlFDB == 'RR' or controlFDB == 'D':
- ret = 'RRR'
- if system_set == 'DREWNO':
- if widthFDB <= 1400:
- if controlFDB == 'RL' or controlFDB == 'A' or controlFDB == 'LR' or controlFDB == 'B':
- ret = 'L+R'
- if controlFDB == 'LL' or controlFDB == 'C':
- ret = 'LL'
- if controlFDB == 'RR' or controlFDB == 'D':
- ret = 'RR'
- if widthFDB > 1400:
- if controlFDB == 'RL' or controlFDB == 'A':
- ret = 'L+RR'
- if controlFDB == 'LR' or controlFDB == 'B':
- ret = 'LL+R'
- if controlFDB == 'LL' or controlFDB == 'C':
- ret = 'LLL'
- if controlFDB == 'RR' or controlFDB == 'D':
- ret = 'RRR'
- if system_set == '70MM SZNUR':
- if widthFDB <= 1500:
- if controlFDB == 'RL' or controlFDB == 'A' or controlFDB == 'LR' or controlFDB == 'B':
- ret = 'L+R'
- if controlFDB == 'LL' or controlFDB == 'C':
- ret = 'LL'
- if controlFDB == 'RR' or controlFDB == 'D':
- ret = 'RR'
- if widthFDB > 1500:
- if controlFDB == 'RL' or controlFDB == 'A':
- ret = 'L+RR'
- if controlFDB == 'LR' or controlFDB == 'B':
- ret = 'LL+R'
- if controlFDB == 'LL' or controlFDB == 'C':
- ret = 'LLL'
- if controlFDB == 'RR' or controlFDB == 'D':
- ret = 'RRR'
- if system_set == '50MM':
- if widthFDB <= 2120:
- if controlFDB == 'RL' or controlFDB == 'A' or controlFDB == 'LR' or controlFDB == 'B':
- ret = 'L+R'
- if controlFDB == 'LL' or controlFDB == 'C':
- ret = 'LL'
- if controlFDB == 'RR' or controlFDB == 'D':
- ret = 'RR'
- if widthFDB > 2120:
- if controlFDB == 'RL' or controlFDB == 'A':
- ret = 'L+RR'
- if controlFDB == 'LR' or controlFDB == 'B':
- ret = 'LL+R'
- if controlFDB == 'LL' or controlFDB == 'C':
- ret = 'LLL'
- if controlFDB == 'RR' or controlFDB == 'D':
- ret = 'RRR'
- if system_set == '50 MONOKOMANDO':
- ret = 'None'
- return ret
- def systemChoice(kolor):
- global monokomando
- global systemFDB
- ret = 0
- drewno = [101, 155, 105, 106, 138, 141, 102, 133, 154, 130, 144,
- 110, 135, 108, 146, 151, 312, 113, 313, 158, 131, 112,
- 114, 116, 134, 125, 126, 119, 147, 309, 311, 136, 115,
- 132, 128, 129, 120, 121, 123, 156, 5500, 5468, 5499,
- 5101, 5102, 5105, 5106, 5108, 5110, 5112, 5113, 5114,
- 5115, 5116, 5119, 5120, 5121, 5123, 5125, 5126, 5128,
- 5129, 5130, 5131, 5132, 5133, 5134, 5135, 5136, 5138,
- 5141, 5144, 5146, 5147, 5151, 5154, 5155, 5156, 5158,
- 5112, 5462, 5534, 5541, 5528, 5535, 5543, 5537, 5529,
- 5538, 5531, 5531, 5539, 5530, 5542, 5533, 5540, 5536,
- 526, 522, 527, 525, 523, 524, 5532, 5535, 5543, 5537,
- 5529, 5531, 5539, 5530, 5542, 533, 5540, 5536, 5528,
- 5550, 5468, 5499, 106, 5478]
- CTR = [400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411,
- 412, 413, 415, 416, 417, 418, 419, 420, 542, 544, 685, 686,
- 687, 688, 689, 690, 691, 421, 422]
- if ret == 0:
- for i in range(0, len(drewno)):
- if kolor == drewno[i]:
- ret = 'DREWNO'
- break
- else:
- ret = 0
- if ret == 0:
- for i in range(0, len(CTR)):
- if kolor == CTR[i]:
- ret = 'CTR'
- break
- else:
- ret = 0
- if ret == 0:
- if monokomando.rstrip('-') == "K" or monokomando.rstrip('-')=="E" or monokomando.rstrip('-')=="EL":
- ret = '50 MONOKOMANDO'
- else:
- ret = 0
- if ret == 0:
- if systemFDB.rstrip('-') == "50" or systemFDB.rstrip('-') == "i50":
- ret = '50MM'
- elif systemFDB.rstrip('-') == 'i70' or systemFDB.rstrip('-') == '70':
- ret = '70MM SZNUR'
- else:
- ret = 0
- return ret
- def confirm(event):
- global systemNode
- global controlNode
- global widthNode
- global system
- global control
- global widthFDB
- global system_set
- global control_set
- p = conf.get()
- conf.delete(0,END)
- for i in range(0, len(p)):
- number=ord(p[i])
- writeNumber(number)
- time.sleep(0.025)
- writeNumber(10)
- if p=='00':
- erase()
- conf.config(state="disable")
- bCode.config(state='normal')
- bCode.delete(0,END)
- bCode.focus_set()
- if p=='03':
- zapis_Sql()
- conf.config(state="disable")
- bCode.config(state='normal')
- bCode.delete(0,END)
- bCode.focus_set()
- def erase():
- global labelFDB
- global widthFDB
- global systemFDB
- global controlFDB
- global monokomando
- monokomando = ''
- controlFDB = ''
- labelFDB = ''
- widthFDB = ''
- systemFDB = ''
- system_data.config(text='')
- width_data.config(text='')
- control_data.config(text='')
- label_label.config(text='')
- #### GUI #####
- bCode = Entry(frame_codes,font=("Arial",16),background="black",foreground="green",highlightbackground="black",disabledbackground="black",disabledforeground="white",selectbackground="yellow")
- bCode.bind("<Return>",skaner)
- bCode.grid(column=1,row=0)
- conf=Entry(frame_codes,font=("Arial",16),background="black",foreground="green",highlightbackground="black",disabledbackground="black",disabledforeground="white")
- conf.bind("<Return>",confirm)
- conf.grid(column=1,row=1)
- label_label = Label(frame_label,font=("Arial",30),wraplength=1000,background="black",foreground="white")
- label_label.grid()
- system_label = Label(frame_data,font=("Arial",r_o),text="System: ",background="black",foreground="white")
- system_label.grid(row=0,column=0,sticky="nw")
- width_label= Label(frame_data,font=("Arial",r_o),text="Szerokosc: ",background="black",foreground="white")
- width_label.grid(row=1,column=0,sticky="NSw")
- control_label= Label(frame_data,font=("Arial",r_o),text="Strona st: ",background="black",foreground="white")
- control_label.grid(row=2,column=0,sticky="NSw")
- zrobione_label=Label(frame_data,font=("Arial",r_o),text="Zrobiono: ",background="black",foreground="white")
- zrobione_label.grid(row=3,column=0,sticky="Sw")
- system_data = Label(frame_data,font=("Arial",r_o),background="black",foreground="white")
- system_data.grid(row=0,column=1,sticky="nw")
- width_data= Label(frame_data,font=("Arial",r_o),background="black",foreground="white")
- width_data.grid(row=1,column=1,sticky="NSw")
- control_data= Label(frame_data,font=("Arial",r_o),background="black",foreground="white")
- control_data.grid(row=2,column=1,sticky="Sw")
- zrobiono_data= Label(frame_data,font=("Arial",r_o),background="black",foreground="white")
- zrobiono_data.grid(row=3,column=1,sticky="Sw")
- if __name__ == '__main__':
- bCode.focus_set()
- conf.config(state='disable')
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement