-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlimascan.mac
322 lines (270 loc) · 10.7 KB
/
limascan.mac
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
def limamulttrigsetup '{
local lima_name lima_n trig_gen trig_dev msg
lima_name = ($# > 0) ? "$1" : getval("Lima camera name", "")
lima_name = _lima_checkccdname(lima_name)
lima_n = list_check(LIMA_DEV, lima_name)
trig_gen = list_getpar(LIMA_DEV, lima_n, "mult_trig_gen")
if (!trig_gen)
trig_gen = "SPEC"
trig_gen = ($# > 1) ? "$2" : getval("Trigger generator [SPEC|CT2|OPIOM]", \
trig_gen)
if ((trig_gen != "SPEC") && (trig_gen != "CT2") && (trig_gen != "OPIOM")) {
_lima_error lima_name
printf("Invalid trigger generator: %s. Can be SPEC|CT2|OPIOM\n", \
trig_gen)
exit
}
list_setpar(LIMA_DEV, lima_n, "mult_trig_gen", trig_gen)
if (trig_gen != "SPEC") {
trig_dev = list_getpar(LIMA_DEV, lima_n, "mult_trig_dev")
msg = (trig_gen == "CT2") ? "P201 CT2 counter name" : "OPIOM name"
trig_dev = ($# > 2) ? "$3" : getval(msg, trig_dev)
if (trig_dev == "") {
_lima_error lima_name
printf("Invalid %s: %s\n", msg, trig_dev)
exit
}
list_setpar(LIMA_DEV, lima_n, "mult_trig_dev", trig_dev)
}
if (trig_gen == "CT2")
lima_mult_trig_ct2_default(lima_name)
else if (trig_gen == "OPIOM")
lima_mult_trig_opiom_default(lima_name)
if (list_getpar(LIMA_DEV, lima_n, "mult_trig"))
limamulttrigscanon_func(lima_name)
else
limamulttrigscanoff_func(lima_name)
}'
def limamulttrigscan '{
local i state lima_name
for (i = 1; i <= list_n(LIMA_DEV); i++) {
lima_name = list_item(LIMA_DEV, i)
state = (list_getpar(LIMA_DEV, i, "mult_trig") > 0) ? "ON" : "OFF"
_lima_trace lima_name
printf("Multi-Trigger scan is %s\n", state)
}
}'
def limamulttrigscanon '{
local lima_name
lima_name = ($# > 0) ? "$1" : getval("Lima camera name", "")
limamulttrigscanon_func(lima_name)
}'
def limamulttrigscanon_func(lima_name) '{
local lima_n ccd_u taco_dev
lima_name = _lima_checkccdname(lima_name)
lima_n = list_check(LIMA_DEV, lima_name)
ccd_u = list_getpar(LIMA_DEV, lima_n, "unit")
taco_dev = image_par(ccd_u, "device_id")
taco_io(taco_dev, "DevCcdResetMultTrigNbFrames")
list_setpar(LIMA_DEV, lima_n, "prev_mult_trig", 0)
list_setpar(LIMA_DEV, lima_n, "mult_trig", 1)
cdef("user_prescan_head", "lima_mult_trig_head(); ", "lima_mult_trig")
cdef("user_scan_tail", "lima_mult_trig_tail(0); ", "lima_mult_trig")
}'
def limamulttrigscanoff '{
local lima_name
lima_name = ($# > 0) ? "$1" : getval("Lima camera name", "")
limamulttrigscanoff_func(lima_name)
}'
def limamulttrigscanoff_func(lima_name) '{
local lima_n i all_off
lima_name = _lima_checkccdname(lima_name)
lima_n = list_check(LIMA_DEV, lima_name)
list_setpar(LIMA_DEV, lima_n, "mult_trig", 0)
all_off = 1
for (i = 1; i <= list_n(LIMA_DEV); i++) {
if (list_getpar(LIMA_DEV, i, "mult_trig") > 0)
all_off = 0
}
if (all_off) {
cdef("user_prescan_head", "", "lima_mult_trig", "delete")
cdef("user_scan_tail", "", "lima_mult_trig", "delete")
}
}'
def lima_mult_trig_head() '{
local lima_name i nb_points
nb_points = (_stype & scanType_MeshScan) ? (_n1 * _n2) : _n1
#nb_points = array_op("rows", SCAN_POINTS)
for (i = 1; i <= list_n(LIMA_DEV); i++) {
if (list_getpar(LIMA_DEV, i, "mult_trig") > 0) {
lima_name = list_item(LIMA_DEV, i)
_lima_trace lima_name
printf("Multi-Trigger scan for %d points\n", nb_points)
msg_printed = 1
lima_mult_trig_on(lima_name, nb_points)
}
}
cdef("cleanup_once", "lima_mult_trig_tail(1); ", "lima_mult_trig")
}'
def lima_mult_trig_tail(from_cleanup) '{
local lima_name i
if (!from_cleanup)
cdef("cleanup_once", "", "lima_mult_trig", "delete")
for (i = 1; i <= list_n(LIMA_DEV); i++) {
if (list_getpar(LIMA_DEV, i, "mult_trig") > 0) {
lima_name = list_item(LIMA_DEV, i)
lima_mult_trig_off(lima_name)
}
}
}'
def lima_mult_trig_on(lima_name, nb_points) '{
local lima_n ccd_u taco_dev tango_dev trig_gen is_spec
local lima_acq_mode lima_trig_mode ccd_trig_mode
local det_exp det_dtime det_pulses skip_frame_freq
lima_n = list_check(LIMA_DEV, lima_name)
if (list_getpar(LIMA_DEV, lima_n, "prev_mult_trig") > 0)
return
trig_gen = list_getpar(LIMA_DEV, lima_n, "mult_trig_gen")
ccd_u = list_getpar(LIMA_DEV, lima_n, "unit")
ccd_trig_mode = image_par(ccd_u, "ext_trig")
is_spec = (trig_gen == "SPEC")
if (is_spec) {
if (ccd_trig_mode == 0) {
lima_trig_mode = "INTERNAL_TRIGGER_MULTI"
} else {
if (image_par(ccd_u, "soft_preset")) {
lima_trig_mode = "EXTERNAL_TRIGGER_MULTI"
ccd_trig_mode = 2
} else {
lima_trig_mode = "EXTERNAL_GATE"
ccd_trig_mode = 1
}
}
} else {
lima_trig_mode = "EXTERNAL_TRIGGER_MULTI"
ccd_trig_mode = 2
}
image_par(ccd_u, "ext_trig", ccd_trig_mode)
CCD_TRIG[ccd_u] = ccd_trig_mode
if (!_limapar_set(lima_name, "acq_trigger_mode", lima_trig_mode))
exit
_lima_trace lima_name
printf("Using %s trigger mode\n", lima_trig_mode)
taco_dev = image_par(ccd_u, "device_id")
taco_io(taco_dev, "DevCcdSetMultTrigNbFrames", nb_points)
list_setpar(LIMA_DEV, lima_n, "prev_mult_trig", 1)
det_exp = _ctime
det_dtime = _limapar_get(lima_name, "latency_time")
det_pulses = 1
lima_acq_mode = _limapar_get(lima_name, "acq_mode")
if (lima_acq_mode == "ACCUMULATION") {
if (is_spec) {
_lima_error lima_name
printf("%s acq_mode/trig_mode is %s/%s. %s\n", \
lima_name, lima_acq_mode, lima_trig_mode, \
"Mult-trig scan not supported")
exit
}
det_exp = _limapar_get(lima_name, "acq_expo_time")
if (fabs(det_exp - _ctime) > 10e-6) {
_limapar_set(lima_name, "acq_expo_time", _ctime)
tango_dev = list_getpar(LIMA_DEV, lima_n, "control")
tango_io(tango_dev, "prepareAcq")
}
det_pulses = _limapar_get(lima_name, "acc_nb_frames")
det_exp = _limapar_get(lima_name, "acc_live_time") / det_pulses
det_dtime = _limapar_get(lima_name, "acc_dead_time") / (det_pulses - 1)
_lima_trace lima_name
printf("accumulation with %s: up=%s, down=%s, pulses=%s\n", trig_gen, \
det_exp, det_dtime, det_pulses)
}
skip_frame_freq = 0
if (_limapar_get(lima_name, "camera_type") == "SlsDetector")
skip_frame_freq = det_pulses++
if (skip_frame_freq) {
if (is_spec) {
_lima_error lima_name
printf("Error: %s mult-trig scan needs CT2/OPIOM\n", lima_name)
exit
}
_limapar_set(lima_name, "skip_frame_freq", skip_frame_freq)
}
list_setpar(LIMA_DEV, lima_n, "skip_frame_freq", skip_frame_freq)
if (trig_gen == "CT2")
lima_mult_trig_ct2_set(lima_name, det_exp, det_dtime, det_pulses)
else if (trig_gen == "OPIOM")
lima_mult_trig_opiom_set(lima_name, det_exp, det_dtime, det_pulses)
}'
def lima_mult_trig_off(lima_name) '{
local lima_n trig_gen ccd_u taco_dev tango_dev
local lima_trig_mode ccd_trig_mode ccd_preset
lima_n = list_check(LIMA_DEV, lima_name)
if (list_getpar(LIMA_DEV, lima_n, "prev_mult_trig") <= 0)
return
if (_limapar_get(lima_name, "acq_status") == "Running") {
tango_dev = list_getpar(LIMA_DEV, lima_n, "control")
tango_io(tango_dev, "stopAcq")
}
while (_limapar_get(lima_name, "acq_status") != "Ready")
sleep(COUNTERSPOLLTIME)
ccd_u = list_getpar(LIMA_DEV, lima_n, "unit")
taco_dev = image_par(ccd_u, "device_id")
taco_io(taco_dev, "DevCcdResetMultTrigNbFrames")
list_setpar(LIMA_DEV, lima_n, "prev_mult_trig", 0)
lima_trig_mode = _limapar_get(lima_name, "acq_trigger_mode")
if (lima_trig_mode == "INTERNAL_TRIGGER_MULTI") {
lima_trig_mode = "INTERNAL_TRIGGER"
ccd_trig_mode = 0
ccd_preset = 1
} else if (lima_trig_mode == "EXTERNAL_TRIGGER_MULTI") {
lima_trig_mode = "EXTERNAL_TRIGGER"
ccd_trig_mode = 1
ccd_preset = 1
} else if (lima_trig_mode == "EXTERNAL_GATE") {
lima_trig_mode = "EXTERNAL_TRIGGER"
ccd_trig_mode = 1
ccd_preset = 0
}
_limapar_set(lima_name, "acq_trigger_mode", lima_trig_mode)
image_par(ccd_u, "ext_trig", ccd_trig_mode)
CCD_TRIG[ccd_u] = ccd_trig_mode
image_par(ccd_u, "soft_preset", ccd_preset)
CCD_SOFT_PRESET[ccd_u] = ccd_preset
trig_gen = list_getpar(LIMA_DEV, lima_n, "mult_trig_gen")
if (trig_gen == "CT2")
lima_mult_trig_ct2_default(lima_name)
else if (trig_gen == "OPIOM")
lima_mult_trig_opiom_default(lima_name)
if (list_getpar(LIMA_DEV, lima_n, "skip_frame_freq")) {
_limapar_set(lima_name, "skip_frame_freq", 0)
list_setpar(LIMA_DEV, lima_n, "skip_frame_freq", 0)
}
}'
def lima_mult_trig_ct2_default(lima_name) '{
lima_mult_trig_ct2_set(lima_name, 1, 0, 1)
}'
def lima_mult_trig_ct2_set(lima_name, det_exp, det_dtime, det_pulses) '{
local lima_n ct2_mne ct2_cnum ct2_acq_mode ct2_period
lima_n = list_check(LIMA_DEV, lima_name)
ct2_mne = list_getpar(LIMA_DEV, lima_n, "mult_trig_dev")
ct2_cnum = cnt_num(ct2_mne)
ct2_acq_mode = (det_pulses > 1) ? 2 : 0 # IntTrigSingle/IntTrigReadout
ct2_period = (det_pulses > 1) ? (det_exp + det_dtime) : 0
counter_par(ct2_cnum, "acq_mode", ct2_acq_mode)
counter_par(ct2_cnum, "acq_nb_points", det_pulses)
counter_par(ct2_cnum, "acq_expo_time", det_exp)
counter_par(ct2_cnum, "acq_point_period", ct2_period)
}'
def lima_mult_trig_opiom_default(lima_name) '{
lima_mult_trig_opiom_set(lima_name, 500e-6, 500e-6, 1)
}'
def lima_mult_trig_opiom_set(lima_name, det_exp, det_dtime, det_pulses) '{
local lima_n opiom_name opiom_cmd opiom_cnt opiom_clock opiom_trig_input
local opiom_up opiom_down opiom_res
lima_n = list_check(LIMA_DEV, lima_name)
opiom_name = list_getpar(LIMA_DEV, lima_n, "mult_trig_dev")
opiom_cnt = 1
opiom_trig_input = "I8"
opiom_clock = 16
opiom_up = int(max2(det_exp, 500e-6) * opiom_clock * 1e6)
opiom_down = int(max2(det_dtime, 500e-6) * opiom_clock * 1e6)
opiom_cmd = sprintf("CNT %d CLK%d START RISE %s PULSE %d %d %d", \
opiom_cnt, opiom_clock, opiom_trig_input, \
opiom_up, opiom_down, det_pulses)
opiom_res = isgdevice_comm_ack(opiom_name, opiom_cmd)
if (opiom_res != "OK") {
_lima_error lima_name
printf("ERROR: lima_mult_trig_opiom_set: opiom response: \"%s\"\n", \
opiom_res)
}
}'