-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsole.py
166 lines (108 loc) · 3.63 KB
/
console.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#without serial commands
#commands:
#r refresh
#a send arbitrary command
#p poll pressure data
#s save pressure data
#q quit
#pgup/pgdn to scroll the pressure window
#import serial
#import time
import curses
def get_MKS_data():
return_data = ""
return_data += "address: \n" #AD?
return_data += "baud: \n" #BR?
return_data += "units: \n" #U?
return_data += "tag: \n" #UT?
return_data += "Firmware Version: \n" #FV?
return_data += "Gas Type: \n" #GT?
return_data += "Setpoint: \n" #EN1?
return_data += "Temperature: \n" #TEM?
return_data += "Pressure: \n" #PR1
return return_data
def get_pressure_data():
return_data = ""
return_data += "Pressure:\t9.00E2\n"
return return_data
send = ""
out = ""
preamble = "@253" #attention + default address, needed even with RS232
command = ""
terminator = ";FF"
#Serial port communication
# port = serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=3.0)
# assemble = preamble + command + terminator
# port.write(assemble)
# time.sleep(1)
# while port.inWaiting() > 0:
# out += port.read(1)
# port.close()
stdscr = curses.initscr()
#initialize screen
curses.noecho()
curses.cbreak()
curses.curs_set(0)
if curses.has_colors():
curses.start_color()
#some color choices
curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK)
curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK)
curses.init_pair(3, curses.COLOR_BLUE, curses.COLOR_BLACK)
#header
stdscr.addstr("MKS INTERFACE", curses.A_REVERSE)
stdscr.chgat(-1, curses.A_REVERSE)
stdscr.addstr(curses.LINES-1, 0, "'r' to refresh, 'p' to poll, 'q' to quit")
# green r, blue p, red q
stdscr.chgat(curses.LINES-1, 1, 1, curses.A_BOLD | curses.color_pair(2))
stdscr.chgat(curses.LINES-1, 17, 1, curses.A_BOLD | curses.color_pair(3))
stdscr.chgat(curses.LINES-1, 30, 1, curses.A_BOLD | curses.color_pair(1))
#window to display gauge setup
data_window = curses.newwin(curses.LINES-2, curses.COLS, 1, 0)
#border windows
data_text_border_window = data_window.subwin(curses.LINES-6, (curses.COLS-4)/2, 3, 2)
data_logging_border_window = data_window.subwin(curses.LINES-6, (curses.COLS-4)/2, 3, (curses.COLS-4)/2 + 2)
#creating subwindow to cleanly display text without touching window's borders
data_text_window = data_text_border_window.subwin(curses.LINES-8, (curses.COLS-6)/2-1, 4, 3)
#subwindow for showing pressure log
data_logging_window = data_logging_border_window.subwin(curses.LINES-8, (curses.COLS-6)/2-1, 4, (curses.COLS-4)/2 + 3)
#data_text_window.addstr("Press 'R' to load data")
#data_logging_window.addstr("Press 'P' to log here")
#draw a box around main window
data_window.box()
data_text_border_window.box()
data_logging_border_window.box()
#data_logging_window.box()
#data_text_window.box()
data_text_window.addstr("Press 'r' to load data")
data_logging_window.addstr("Press 'p' to log pressure data here")
#update internal curses structures
stdscr.noutrefresh()
data_window.noutrefresh()
#redraw screen
curses.doupdate()
while True:
c = data_window.getch()
if c == ord('r') or c == ord('R'):
data_text_window.clear()
data_text_window.addstr("Getting MKS data...", curses.color_pair(3))
data_text_window.refresh()
data_text_window.clear()
data_text_window.addstr(get_MKS_data())
elif c == ord('p') or c == ord('P'):
data_logging_window.clear()
for x in range(0, 10):
data_logging_window.addstr(get_pressure_data())
data_logging_window.refresh()
elif c == ord('q') or c == ord('Q'):
break
#refresh windows
stdscr.noutrefresh()
data_window.noutrefresh()
data_text_window.noutrefresh()
curses.doupdate()
#restore terminal settings
curses.nocbreak()
curses.echo()
curses.curs_set(1)
curses.endwin()