-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinterrupt_test.py
More file actions
90 lines (81 loc) · 2.34 KB
/
interrupt_test.py
File metadata and controls
90 lines (81 loc) · 2.34 KB
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
'''
This is for testing the ADR interrupt code.
'''
from __future__ import print_function
from ADRinterrupt import InterruptClient, InterruptServer
import threading
import time
def server_thread():
server = InterruptServer(temprange=(-1, 1))
server.open()
while True:
temp = server.poll()
if temp is None:
print('Server: No Packet or Invalid Packet')
else:
if temp == 0:
break
else:
print('Server: Temperature: {}'.format(temp))
time.sleep(1)
print ('Server: Closing')
server.close()
def client_thread():
client = InterruptClient()
client.open()
tosend = [ 1.3, 0.05, 18, 'trash', '14', True ]
for data in tosend:
client.send(data)
client.wait()
print('Last client data: ({}) {}'.format(client.lastResult[0], client.lastResult[1]))
time.sleep(2)
client.close()
client.open()
tosend.reverse()
for data in tosend:
client.send(data)
client.wait()
print('Last client data: ({}) {}'.format(client.lastResult[0], client.lastResult[1]))
time.sleep(2)
client.send(0)
client.close()
print('Client: Closing')
def local_test():
s_task = threading.Thread(target=server_thread)
c_task = threading.Thread(target=client_thread)
s_task.start()
c_task.start()
s_task.join()
c_task.join()
def real_test():
client = InterruptClient()
if not client.open():
return
while True:
entry = raw_input('Please enter the new cryostat temp as a float, or "quit" > ')
if entry == 'quit':
break
try:
new_temp = float(entry)
except ValueError:
print('Please enter a valid floating point number')
continue
client.send(new_temp)
client.close()
if __name__ == '__main__':
option = 0
while True:
try:
entry = raw_input('Please enter 1 for local test, or 2 for real test > ')
if entry != 'quit':
option = int(entry)
break
except ValueError:
print('Please enter a valid integer')
else:
if option not in [1, 2]:
print('Please enter either 1 or 2')
if option == 1:
local_test()
elif option == 2:
real_test()