-
Notifications
You must be signed in to change notification settings - Fork 0
/
skychop.py
133 lines (110 loc) · 3.08 KB
/
skychop.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
import chopper
import syncbox
import switchbox
import syncuino
import subprocess
import threading
from glob import glob
from mce_control import mce_control
#import time
#this script is going to be a mess
def chopper_setup():
global chop_control
chop_control = chopper.Chopper()
chop_control.setup_chopper(1, 6 + 3) # 1 Hz 6 sec (plus some for the road)
chop_control.run_chopper()
def syncbox_setup():
global sync_control
sync_control = syncbox.Syncbox()
sync_control.use_dv()
sync_control.go()
def switchbox_setup():
global switch_control
switch_control = switchbox.SwitchBox()
switch_control.set_labchop()
def arduino_setup():
global arduino
arduino = syncuino.Syncuino()
arduino.set_period(2508)
arduino.set_frames(99)
arduino.set_n_blanks(12)
arduino.set_n_delays(0)
def mce_setup():
global mce
mce = mce_control()
mce.write("cc", "use_sync", 2)
mce.write("cc", "use_dv", 2)
mce.write("cc", "select_clk", 1)
def do_skychop():
print("set up chopper")
chop_thread = threading.Thread(target=chopper_setup)
chop_thread.start()
print("set up sync box")
sync_thread = threading.Thread(target=syncbox_setup)
sync_thread.start()
print("set up switch box")
switch_thread = threading.Thread(target=switchbox_setup)
switch_thread.start()
print("set up arduino")
arduino_thread = threading.Thread(target=arduino_setup)
arduino_thread.start()
print("set up MCE")
mce_thread = threading.Thread(target=mce_setup)
mce_thread.start()
filename = "skychop_{num}"
path = "/data/cryo/current_data/"
files=glob( path + filename.format(num="????"))
if len(files)==0:
no=0
print("no files found, starting at 0")
else:
lastfile = sorted(files)[-1]
no = lastfile.replace(path+filename.format(num=""),"")
no = int(no)+1
filename = filename.format(num="{:04d}".format(no))
print(f"filename is {filename}")
for thread in [
chop_thread,
sync_thread,
switch_thread,
arduino_thread,
mce_thread
]:
thread.join()
zframetimes = subprocess.Popen([
"/usr/bin/zframetimes",
"-c",
f"/data/cryo/current_data/{filename}",
"1188",
"99",
"0"
])
print("all systems go")
print("MCE_RUN!")
mce_run = subprocess.Popen([
"/usr/mce/mce_script/script/mce_run",
filename,
"1188",
"s",
"--no-locking"],
stdout = subprocess.PIPE
)
text = ""
while "acq_go" not in text:
outs = mce_run.stdout.readline()
text = outs.decode()
print(text)
print("arduino go")
arduino.go() # start after mce run is "ready"
# ready is defined as having said acq_go
print(mce_run.communicate())
chop_control.stop()
chop_control.open_chopper()
zframetimes.wait()
chopfile = subprocess.Popen([
'/usr/local/bin/mcechopfile',
f'/data/cryo/current_data/{filename}'
])
chopfile.wait()
if __name__ == "__main__":
do_skychop()