Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import serial
- from tkinter import *
- from time import gmtime, strftime, localtime, sleep
- from datetime import datetime
- import webbrowser
- import serial.tools.list_ports
- listp = serial.tools.list_ports.comports()
- connected = []
- for element in listp:
- connected.append(element.device)
- with open("CanSatConf.Conf","r+") as f:
- lines = f.readlines()
- lines[0] = lines[0].replace("\n", "")
- def opport():
- global ser, PortS, e, s1
- with open("CanSatConf.Conf","w") as f:
- f.write(e.get())
- f.write('\n')
- f.write(e2.get())
- s1 = e2.get()
- ser = serial.Serial(e.get())
- PortS.destroy()
- def AddT(INP):
- x = open("Log.txt", "a")
- x.write(strftime("%H:%M:%S", localtime())+INP)
- x.close()
- PortS = Tk()
- PortS.title("CanSat-Configurator")
- Label(PortS, text="COM ports: "+str(connected)).grid(row=0, column=0)
- e = Entry(PortS)
- e.grid(row=0, column=1)
- e.insert(END, lines[0])
- Label(PortS, text="Start time: ").grid(row=1, column=0)
- e2 = Entry(PortS)
- e2.grid(row=1, column=1)
- e2.insert(END, lines[1])
- Button(PortS, text="SET", command=opport, width = 10).grid(row=2, column=0, sticky=N+S, columnspan=2)
- PortS.mainloop()
- mainw = Tk()
- mainw.title("CanSat")
- mainw.iconbitmap('download.ico')
- mainw.minsize(width=222, height=0)
- FMT = "%H:%M:%S"
- tdelta = 0
- pt = ""
- Celkove = 0
- Teplota_Zem = 0
- Tlak_Zem = 0
- GPS0 = 0
- GPS1 = 0
- Teplota_Can = 0
- Tlak_Can = 0
- Baterie = 0
- Vyska = 0
- VyskaG = 0
- Rychm = 0
- tdelta2 = StringVar()
- pt2 = StringVar()
- Celkove2 = StringVar()
- Teplota_Zem2 = StringVar()
- Tlak_Zem2 = StringVar()
- GPS02 = StringVar()
- GPS12 = StringVar()
- Teplota_Can2 = StringVar()
- Tlak_Can2 = StringVar()
- Baterie2 = StringVar()
- Vyska2 = StringVar()
- VyskaG2 = StringVar()
- Rychm2 = StringVar()
- Vyska2.set("")
- tdelta2.set("")
- pt2.set("")
- Celkove2.set("")
- Teplota_Zem2.set("")
- Tlak_Zem2.set("")
- GPS02.set("")
- GPS12.set("")
- Teplota_Can2.set("")
- Tlak_Can2.set("")
- Baterie2.set("")
- VyskaG2.set("")
- Rychm2.set("")
- def GPSS():
- url = "https://www.google.cz/maps/search/"+(str(float(GPS0)/100000))+"+"+(str(float(GPS1)/100000))
- webbrowser.open(url)
- pass
- Label(mainw, text=" ").grid(row=0, column=0)
- Label(mainw, text="Celkove prenosy: ").grid(row=0, column=1)
- Label(mainw, textvariable=Celkove2).grid(row=0, column=2)
- Label(mainw, text="Teplota zem: ").grid(row=1, column=1)
- Label(mainw, textvariable=Teplota_Zem2).grid(row=1, column=2)
- Label(mainw, text="Tlak Zem: ").grid(row=2, column=1)
- Label(mainw, textvariable=Tlak_Zem2).grid(row=2, column=2)
- Label(mainw, text="GPS0: ").grid(row=3, column=1)
- Label(mainw, textvariable=GPS02).grid(row=3, column=2)
- Label(mainw, text="GPS1: ").grid(row=4, column=1)
- Label(mainw, textvariable=GPS12).grid(row=4, column=2)
- Label(mainw, text="Teplota Can: ").grid(row=5, column=1)
- Label(mainw, textvariable=Teplota_Can2).grid(row=5, column=2)
- Label(mainw, text="Tlak Can: ").grid(row=6, column=1)
- Label(mainw, textvariable=Tlak_Can2).grid(row=6, column=2)
- Label(mainw, text="Napeti baterie: ").grid(row=7, column=1)
- Label(mainw, textvariable=Baterie2).grid(row=7, column=2)
- Label(mainw, text="Odhadovana vyska: ").grid(row=8, column=1)
- Label(mainw, textvariable=Vyska2).grid(row=8, column=2)
- Label(mainw, text="Posledni prijem: ").grid(row=9, column=1)
- Label(mainw, textvariable=pt2).grid(row=9, column=2)
- Label(mainw, text="Funguje: ").grid(row=10, column=1)
- Label(mainw, textvariable=tdelta2).grid(row=10, column=2)
- Button(mainw, text="Open Location", command=GPSS).grid(row=11, column=2)
- def myapp():
- global Celkove, Teplota_Zem, Tlak_Zem, GPS0, GPS1, Teplota_Can, Tlak_Can, Baterie, pt, tdelta, Celkove2, Teplota_Zem2, Tlak_Zem2, GPS02, GPS12, Teplota_Can2, Tlak_Can2, Baterie2, pt2, tdelta2, Rychm2, VyskaG2, Rychm, VyskaG
- line = ser.readline()
- AddT(line.decode("utf-8"))
- x = line.decode("utf-8").split("|")
- try:
- if x[1]=='1':
- Celkove = x[4]
- Teplota_Zem = x[3]
- Tlak_Zem = x[2]
- if x[1]=='0':
- pt = strftime("%H:%M:%S", localtime())
- tdelta = datetime.strptime(pt, FMT) - datetime.strptime(s1, FMT)
- Celkove = x[12]
- Teplota_Zem = x[3]
- Tlak_Zem = x[2]
- if x[4]!=0 and x[3]!=0:
- GPS0 = x[4]
- GPS1 = x[5]
- Baterie = x[8]
- Teplota_Can = str(float(x[7])/100)
- Tlak_Can = x[6]
- Rychm = x[10]
- VyskaG = x[9]
- except:
- pass
- Vyska2.set((str(round((((1-pow((float(Tlak_Can)/1013.25),0.190284))*145366.45)*0.3048),2))+" m"))
- tdelta2.set((tdelta))
- pt2.set((pt))
- Celkove2.set(Celkove)
- Teplota_Zem2.set((str(Teplota_Zem)+" °C"))
- Tlak_Zem2.set((str(Tlak_Zem)+" mb"))
- GPS02.set((str(float(GPS0)/100000)))
- GPS12.set((str(float(GPS1)/100000)))
- Teplota_Can2.set((str(Teplota_Can)+" °C"))
- Tlak_Can2.set((str(Tlak_Can)+" mb"))
- Baterie2.set((str(float(Baterie)/100)+" V"))
- mainw.after(1, myapp)
- mainw.after(0, myapp)
- mainw.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement