Advertisement
nicx321

CanSat

Jan 28th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.05 KB | None | 0 0
  1. import serial
  2. from tkinter import *
  3. from time import gmtime, strftime, localtime, sleep
  4. from datetime import datetime
  5. import webbrowser
  6. import serial.tools.list_ports
  7.  
  8. listp = serial.tools.list_ports.comports()
  9. connected = []
  10.  
  11. for element in listp:
  12.     connected.append(element.device)
  13.  
  14. with open("CanSatConf.Conf","r+") as f:
  15.     lines = f.readlines()
  16.    
  17. lines[0] = lines[0].replace("\n", "")
  18.  
  19. def opport():
  20.     global ser, PortS, e, s1
  21.     with open("CanSatConf.Conf","w") as f:
  22.         f.write(e.get())
  23.         f.write('\n')
  24.         f.write(e2.get())
  25.     s1 = e2.get()
  26.     ser = serial.Serial(e.get())
  27.     PortS.destroy()
  28.  
  29. def AddT(INP):
  30.     x = open("Log.txt", "a")
  31.     x.write(strftime("%H:%M:%S", localtime())+INP)
  32.     x.close()
  33.  
  34. PortS = Tk()
  35. PortS.title("CanSat-Configurator")
  36. Label(PortS, text="COM ports: "+str(connected)).grid(row=0, column=0)
  37. e = Entry(PortS)
  38. e.grid(row=0, column=1)
  39. e.insert(END, lines[0])
  40. Label(PortS, text="Start time: ").grid(row=1, column=0)
  41. e2 = Entry(PortS)
  42. e2.grid(row=1, column=1)
  43. e2.insert(END, lines[1])
  44. Button(PortS, text="SET", command=opport, width = 10).grid(row=2, column=0, sticky=N+S, columnspan=2)
  45. PortS.mainloop()
  46.  
  47. mainw = Tk()
  48. mainw.title("CanSat")
  49. mainw.iconbitmap('download.ico')
  50. mainw.minsize(width=222, height=0)
  51.  
  52. FMT = "%H:%M:%S"
  53. tdelta = 0
  54. pt = ""
  55. Celkove = 0
  56. Teplota_Zem = 0
  57. Tlak_Zem = 0
  58. GPS0 = 0
  59. GPS1 = 0
  60. Teplota_Can = 0
  61. Tlak_Can = 0
  62. Baterie = 0
  63. Vyska = 0
  64. VyskaG = 0
  65. Rychm = 0
  66.  
  67. tdelta2 = StringVar()
  68. pt2 = StringVar()
  69. Celkove2 = StringVar()
  70. Teplota_Zem2 = StringVar()
  71. Tlak_Zem2 = StringVar()
  72. GPS02 = StringVar()
  73. GPS12 = StringVar()
  74. Teplota_Can2 = StringVar()
  75. Tlak_Can2 = StringVar()
  76. Baterie2 = StringVar()
  77. Vyska2 = StringVar()
  78. VyskaG2 = StringVar()
  79. Rychm2 = StringVar()
  80.  
  81. Vyska2.set("")
  82. tdelta2.set("")
  83. pt2.set("")
  84. Celkove2.set("")
  85. Teplota_Zem2.set("")
  86. Tlak_Zem2.set("")
  87. GPS02.set("")
  88. GPS12.set("")
  89. Teplota_Can2.set("")
  90. Tlak_Can2.set("")
  91. Baterie2.set("")
  92. VyskaG2.set("")
  93. Rychm2.set("")
  94.  
  95. def GPSS():
  96.     url = "https://www.google.cz/maps/search/"+(str(float(GPS0)/100000))+"+"+(str(float(GPS1)/100000))
  97.     webbrowser.open(url)
  98.     pass
  99.  
  100. Label(mainw, text="            ").grid(row=0, column=0)
  101. Label(mainw, text="Celkove prenosy: ").grid(row=0, column=1)
  102. Label(mainw, textvariable=Celkove2).grid(row=0, column=2)
  103. Label(mainw, text="Teplota zem: ").grid(row=1, column=1)
  104. Label(mainw, textvariable=Teplota_Zem2).grid(row=1, column=2)
  105. Label(mainw, text="Tlak Zem: ").grid(row=2, column=1)
  106. Label(mainw, textvariable=Tlak_Zem2).grid(row=2, column=2)
  107. Label(mainw, text="GPS0: ").grid(row=3, column=1)
  108. Label(mainw, textvariable=GPS02).grid(row=3, column=2)
  109. Label(mainw, text="GPS1: ").grid(row=4, column=1)
  110. Label(mainw, textvariable=GPS12).grid(row=4, column=2)
  111. Label(mainw, text="Teplota Can: ").grid(row=5, column=1)
  112. Label(mainw, textvariable=Teplota_Can2).grid(row=5, column=2)
  113. Label(mainw, text="Tlak Can: ").grid(row=6, column=1)
  114. Label(mainw, textvariable=Tlak_Can2).grid(row=6, column=2)
  115. Label(mainw, text="Napeti baterie: ").grid(row=7, column=1)
  116. Label(mainw, textvariable=Baterie2).grid(row=7, column=2)
  117. Label(mainw, text="Odhadovana vyska: ").grid(row=8, column=1)
  118. Label(mainw, textvariable=Vyska2).grid(row=8, column=2)
  119. Label(mainw, text="Posledni prijem: ").grid(row=9, column=1)
  120. Label(mainw, textvariable=pt2).grid(row=9, column=2)
  121. Label(mainw, text="Funguje: ").grid(row=10, column=1)
  122. Label(mainw, textvariable=tdelta2).grid(row=10, column=2)
  123. Button(mainw, text="Open Location", command=GPSS).grid(row=11, column=2)
  124.  
  125. def myapp():
  126.     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
  127.     line = ser.readline()
  128.     AddT(line.decode("utf-8"))
  129.     x = line.decode("utf-8").split("|")
  130.     try:
  131.         if x[1]=='1':
  132.             Celkove = x[4]
  133.             Teplota_Zem = x[3]
  134.             Tlak_Zem = x[2]
  135.         if x[1]=='0':        
  136.             pt = strftime("%H:%M:%S", localtime())
  137.             tdelta = datetime.strptime(pt, FMT) - datetime.strptime(s1, FMT)
  138.             Celkove = x[12]
  139.             Teplota_Zem = x[3]
  140.             Tlak_Zem = x[2]
  141.             if x[4]!=0 and x[3]!=0:
  142.                 GPS0 = x[4]
  143.                 GPS1 = x[5]
  144.             Baterie = x[8]
  145.             Teplota_Can = str(float(x[7])/100)
  146.             Tlak_Can = x[6]
  147.             Rychm = x[10]
  148.             VyskaG = x[9]
  149.     except:
  150.         pass
  151.    
  152.     Vyska2.set((str(round((((1-pow((float(Tlak_Can)/1013.25),0.190284))*145366.45)*0.3048),2))+" m"))
  153.     tdelta2.set((tdelta))
  154.     pt2.set((pt))
  155.     Celkove2.set(Celkove)
  156.     Teplota_Zem2.set((str(Teplota_Zem)+" °C"))
  157.     Tlak_Zem2.set((str(Tlak_Zem)+" mb"))
  158.     GPS02.set((str(float(GPS0)/100000)))
  159.     GPS12.set((str(float(GPS1)/100000)))
  160.     Teplota_Can2.set((str(Teplota_Can)+" °C"))
  161.     Tlak_Can2.set((str(Tlak_Can)+" mb"))
  162.     Baterie2.set((str(float(Baterie)/100)+" V"))
  163.     mainw.after(1, myapp)
  164.        
  165. mainw.after(0, myapp)
  166. mainw.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement