Advertisement
kellogg76

Untitled

Aug 8th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. from Tkinter import *
  4.  
  5. root = Tk()
  6. root.title("Elentirmo Observatory Controller v0.3")
  7. root.minsize(468, 85)
  8. root.maxsize(960, 85)
  9.  
  10. dust_cover_text = StringVar()
  11. dust_cover_text.set('Cover Closed')
  12.  
  13. usbport = 'COM9'
  14.  
  15. import sys
  16. import time
  17.  
  18. def dust_cover_open():
  19. print "Opening"
  20. ## Open a serial connection with Arduino.
  21. import time
  22. import serial
  23. ser = serial.Serial(usbport, 9600) # Open serial port that Arduino is using
  24. time.sleep(3) # Wait 3 seconds for Arduino to reset
  25. print ser # Print serial config
  26. print "Sending serial command to OPEN the dust cover to 180d."
  27. ser.write("O")
  28. print "Opening serial connection."
  29. ser.close()
  30. # Reminder to close the connection when finished
  31. if(ser.isOpen()):
  32. print "Serial connection is still open."
  33. dust_cover_label.config(bg="Green")
  34. dust_cover_text.set('Cover is Open')
  35. ##Tweet status
  36. tweet_text = "Dust cover opening."
  37. import os
  38. api.update_status(status=time.strftime("%Y.%m.%d-%H:%M:%S") + " - " + tweet_text)
  39.  
  40. def dust_cover_close():
  41. print "Closing"
  42. ## Open a serial connection with Arduino.
  43. import time
  44. import serial
  45. ser = serial.Serial(usbport, 9600) # Open serial port that Arduino is using
  46. time.sleep(3) # Wait 3 seconds for Arduino to reset
  47. print ser # Print serial config
  48. print "Sending serial command to CLOSE the dust cover."
  49. ser.write("C")
  50. print "Closing serial connection."
  51. ser.close()
  52. # Reminder to close the connection when finished
  53. if(ser.isOpen()):
  54. print "Serial connection is still open."
  55. dust_cover_label.config(bg="red")
  56. dust_cover_text.set('Cover is closed')
  57. ##Tweet status
  58. tweet_text = "Dust cover closing."
  59. import os
  60. api.update_status(status=time.strftime("%Y.%m.%d-%H:%M:%S") + " - " + tweet_text)
  61.  
  62. #Dust Cover Button
  63. open_dust_cover_btn = Button(text=" Open Cover ", width=15, command=dust_cover_open)
  64. open_dust_cover_btn.grid(row=0, column=0)
  65. close_dust_cover_btn = Button(text=" Close Cover ", width=15, command=dust_cover_close)
  66. close_dust_cover_btn.grid(row=1, column=0)
  67. #Dust Cover Label
  68. dust_cover_label = Label(root, textvariable=dust_cover_text, width=15, fg="Black", bg="Red")
  69. dust_cover_label.grid(row=2, column=0)
  70.  
  71. #Current Status Label
  72. status_label = Label(root, text=("Current Status"), width=15, fg="Black")
  73. status_label.grid(row=2, column=1)
  74.  
  75. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement