Newer
Older
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# ############################################################################
# license :
# ============================================================================
#
Roberto Borghes
committed
# File : PilatusXM.py
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
#
# Project : Interface class for the Pilatus detectors
#
# This file is part of Tango device class.
#
# Tango is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Tango is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Tango. If not, see <http://www.gnu.org/licenses/>.
#
#
# $Author : sci.comp$
#
# $Revision : $
#
# $Date : $
#
# $HeadUrl : $
# ============================================================================
# This file is generated by POGO
# (Program Obviously used to Generate tango Object)
# ############################################################################
__all__ = ["PilatusXM", "PilatusXMClass", "main"]
__docformat__ = 'restructuredtext'
import PyTango
import sys
# Add additional import
#----- PROTECTED REGION ID(PilatusXM.additionnal_import) ENABLED START -----#
import socket
import traceback
import time
import os
END_MESSAGE = chr(0x18)
DBUG = False
class CommunicationClass():
def __init__(self, ipaddr_in):
self.ipaddr_in = ipaddr_in
self.socket = None
self._stop = False
self.connect()
def disconnect(self):
try:
if self.socket is not None:
self.socket.close()
except:
self.socket = None
def connect(self):
try:
if self.socket is not None:
self.socket.close()
except:
self.socket = None
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
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
port = 41234
host = self.ipaddr_in
try:
self.socket.connect((host,port))
except:
self.socket = None
def send_to_detector(self, msg, wait_reply = True):
# check state, Pilatus won't responde if it's RUNNING
# only STOP command can be sent in this case
self.socket.sendall(msg + END_MESSAGE)
t0 = time.time()
if DBUG:
print ("Sent", msg)
if not wait_reply:
return
if "CamSetup" in msg:
mandatory_code = "2 OK"
else:
mandatory_code = ""
try:
reply = self.get_detector_reply(timeout = 2, wait_string = mandatory_code)
except:
reply = ''
if reply is None:
self.disconnect()
return None
return reply.split(END_MESSAGE)[0]
def get_detector_reply(self, timeout = 2, wait_string = ''):
t0 = time.time()
reply = ''
while (END_MESSAGE not in reply) or (wait_string not in reply):
if (time.time() - t0) > timeout:
break
tmpreply = self.socket.recv(1024).strip()
reply += tmpreply
if DBUG:
print ("Received", reply)
if END_MESSAGE not in reply:
reply = None
return reply
class fakeAttr():
def __init__(self):
self.value = None
def set_value(self,value_in):
self.value = value_in
def get_write_value(self):
return self.value
#----- PROTECTED REGION END -----# // PilatusXM.additionnal_import
# Device States Description
# ON : The detecor is ready to take images.
# DISABLE : The device is disconnected from the camserver.
# RUNNING : An acquisition is running.
# FAULT : An error occured on the detector during an acquisition.
class PilatusXM (PyTango.LatestDeviceImpl):
"""Pilatus detectors are a series pixel detecors build by DECTRIS
<br />
http://www.dectris.com.
<br />
All detectors of this series can talk to the outside world via a socket
connection. An ASCI protocol is used on this sockect connection to
communicate with the detector.
<p>
The server process which handles the socket on the detecor PC is
called camserver. Only one client can commumicate with camserver.
If the native client tvx is connected, the device server cannot connect until
tvx gets disconnected.
</p>"""
# -------- Add you global variables here --------------------------
#----- PROTECTED REGION ID(PilatusXM.global_variables) ENABLED START -----#
#----- PROTECTED REGION END -----# // PilatusXM.global_variables
def __init__(self, cl, name):
PyTango.LatestDeviceImpl.__init__(self,cl,name)
self.debug_stream("In __init__()")
PilatusXM.init_device(self)
#----- PROTECTED REGION ID(PilatusXM.__init__) ENABLED START -----#
#----- PROTECTED REGION END -----# // PilatusXM.__init__
def delete_device(self):
self.debug_stream("In delete_device()")
#----- PROTECTED REGION ID(PilatusXM.delete_device) ENABLED START -----#
#----- PROTECTED REGION END -----# // PilatusXM.delete_device
def init_device(self):
self.debug_stream("In init_device()")
self.get_device_properties(self.get_device_class())
self.attr_ExposureTime_read = 0.0
self.attr_ExposurePeriod_read = 0.0
self.attr_NbFrames_read = 0
self.attr_NbExposures_read = 0
self.attr_DelayTime_read = 0.0
self.attr_ShutterEnable_read = False
self.attr_TriggerMode_read = 0
self.attr_UseRamDisk_read = False
self.attr_FileDir_read = ""
self.attr_FilePrefix_read = ""
self.attr_FileStartNum_read = 0
self.attr_FilePostfix_read = ""
self.attr_LastImageTaken_read = ""
self.attr_Energy_read = 0
self.attr_Threshold_read = 0
self.attr_Gain_read = 0
self.attr_LastImagePath_read = ""
self.attr_MxSettings_read = ""
self.attr_GapFill_read = 0
self.attr_LdBadPixMap_read = ""
#----- PROTECTED REGION ID(PilatusXM.init_device) ENABLED START -----#
self.attr_FilePrefix_read = 'test'
self.attr_FilePostfix_read = '.tif'
self.attr_FileStartNum_read = 0
self.total_exp_time = 0
self.start_time = 0
if not self.Simulation:
self.comm = CommunicationClass(self.ServerAddress)
self.set_state(PyTango.DevState.ON)
self.set_status("The device is in ON state. Ready")
#----- PROTECTED REGION END -----# // PilatusXM.init_device
def always_executed_hook(self):
self.debug_stream("In always_excuted_hook()")
#----- PROTECTED REGION ID(PilatusXM.always_executed_hook) ENABLED START -----#
if self.Simulation:
if self.get_state() == PyTango.DevState.RUNNING:
elapsed_time = time.time() - self.start_time
if elapsed_time > self.total_exp_time:
self.set_state(PyTango.DevState.ON)
self.set_status("The device is in ON state. Ready")
filenum = self.attr_FileStartNum_read + self.attr_NbFrames_read - 1
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
fullname = "%s%05d%s" % (self.attr_FilePrefix_read,filenum,self.attr_FilePostfix_read)
self.attr_LastImagePath_read = os.path.join(self.attr_FileDir_read,fullname)
self.attr_LastImageTaken_read = os.path.join(self.attr_FileDir_read,fullname)
return
if self.get_state() in [PyTango.DevState.RUNNING,PyTango.DevState.INIT]:
try:
det_msg = self.comm.get_detector_reply(timeout=0.1)
except:
# Pilatus does not reply when acquiring
# Let's stay in RUNNING or INIT
return
cmd = "CamSetup"
reply = self.comm.send_to_detector(cmd)
if reply is None:
PyTango.Except.throw_exception("Communication error","Pilatus does not reply","always_executed_hook")
for token in reply.split("\n"):
if "Camera state:" in token:
if 'idle' in token:
self.set_state(PyTango.DevState.ON)
self.set_status("The device is in ON state. Ready")
else:
self.set_state(PyTango.DevState.RUNNING)
self.set_status("The device is in RUNNING state.")
elif "Last image: " in token:
self.attr_LastImageTaken_read = token.split("Last image: ")[-1]
self.attr_LastImagePath_read = os.path.dirname(self.attr_LastImageTaken_read)
#----- PROTECTED REGION END -----# // PilatusXM.always_executed_hook
# -------------------------------------------------------------------------
# PilatusXM read/write attribute methods
# -------------------------------------------------------------------------
def read_ExposureTime(self, attr):
self.debug_stream("In read_ExposureTime()")
#----- PROTECTED REGION ID(PilatusXM.ExposureTime_read) ENABLED START -----#
if not self.Simulation:
cmd = "exptime"
reply_cmd = "Exposure time set to: "
reply = self.comm.send_to_detector(cmd)
if reply is None:
PyTango.Except.throw_exception("Communication error","Pilatus does not reply","read_ExposureTime")
elif reply_cmd in reply:
self.attr_ExposureTime_read = float((reply.split(reply_cmd)[-1]).split(" ")[0])
else:
PyTango.Except.throw_exception("Communication error","Pilatus wrong reply","read_ExposureTime")
attr.set_value(self.attr_ExposureTime_read)
#----- PROTECTED REGION END -----# // PilatusXM.ExposureTime_read
def write_ExposureTime(self, attr):
self.debug_stream("In write_ExposureTime()")
data = attr.get_write_value()
#----- PROTECTED REGION ID(PilatusXM.ExposureTime_write) ENABLED START -----#
if self.Simulation:
self.attr_ExposureTime_read = data
return
cmd = "exptime %g" % data
reply = self.comm.send_to_detector(cmd)
if reply is None:
PyTango.Except.throw_exception("Communication error","Pilatus does not reply","write_ExposureTime")
elif "ERR" in reply:
PyTango.Except.throw_exception("Command error","Pilatus reply: %s" % reply,"write_ExposureTime")
#----- PROTECTED REGION END -----# // PilatusXM.ExposureTime_write
def is_ExposureTime_allowed(self, attr):
self.debug_stream("In is_ExposureTime_allowed()")
if attr==PyTango.AttReqType.READ_REQ:
state_ok = not(self.get_state() in [])
else:
state_ok = not(self.get_state() in [PyTango.DevState.DISABLE,
PyTango.DevState.RUNNING])
#----- PROTECTED REGION ID(PilatusXM.is_ExposureTime_allowed) ENABLED START -----#
#----- PROTECTED REGION END -----# // PilatusXM.is_ExposureTime_allowed
return state_ok
def read_ExposurePeriod(self, attr):
self.debug_stream("In read_ExposurePeriod()")
#----- PROTECTED REGION ID(PilatusXM.ExposurePeriod_read) ENABLED START -----#
if not self.Simulation:
cmd = "expperiod"
reply_cmd = "Exposure period set to: "
reply = self.comm.send_to_detector(cmd)
if reply is None:
PyTango.Except.throw_exception("Communication error","Pilatus does not reply","read_ExposurePeriod")
elif reply_cmd in reply:
self.attr_ExposurePeriod_read = float((reply.split(reply_cmd)[-1]).split(" ")[0])
else:
PyTango.Except.throw_exception("Communication error","Pilatus wrong reply","read_ExposurePeriod")
attr.set_value(self.attr_ExposurePeriod_read)
#----- PROTECTED REGION END -----# // PilatusXM.ExposurePeriod_read
def write_ExposurePeriod(self, attr):
self.debug_stream("In write_ExposurePeriod()")
data = attr.get_write_value()
#----- PROTECTED REGION ID(PilatusXM.ExposurePeriod_write) ENABLED START -----#
if self.Simulation:
self.attr_ExposurePeriod_read = data
return
cmd = "expperiod %g" % data
reply = self.comm.send_to_detector(cmd)
if reply is None:
PyTango.Except.throw_exception("Communication error","Pilatus does not reply","write_ExposurePeriod")
elif "ERR" in reply:
PyTango.Except.throw_exception("Command error","Pilatus reply: %s" % reply,"write_ExposurePeriod")
#----- PROTECTED REGION END -----# // PilatusXM.ExposurePeriod_write
def is_ExposurePeriod_allowed(self, attr):
self.debug_stream("In is_ExposurePeriod_allowed()")
if attr==PyTango.AttReqType.READ_REQ:
state_ok = not(self.get_state() in [])
else:
state_ok = not(self.get_state() in [PyTango.DevState.DISABLE,
PyTango.DevState.RUNNING])
#----- PROTECTED REGION ID(PilatusXM.is_ExposurePeriod_allowed) ENABLED START -----#
#----- PROTECTED REGION END -----# // PilatusXM.is_ExposurePeriod_allowed
return state_ok
def read_NbFrames(self, attr):
self.debug_stream("In read_NbFrames()")
#----- PROTECTED REGION ID(PilatusXM.NbFrames_read) ENABLED START -----#
if not self.Simulation:
cmd = "nimages"
reply_cmd = "N images set to: "
reply = self.comm.send_to_detector(cmd)
if reply is None:
PyTango.Except.throw_exception("Communication error","Pilatus does not reply","read_NbFrames")
elif reply_cmd in reply:
self.attr_NbFrames_read = int((reply.split(reply_cmd)[-1]).split(" ")[0])
else:
PyTango.Except.throw_exception("Communication error","Pilatus wrong reply","read_NbFrames")
attr.set_value(self.attr_NbFrames_read)
#----- PROTECTED REGION END -----# // PilatusXM.NbFrames_read
def write_NbFrames(self, attr):
self.debug_stream("In write_NbFrames()")
data = attr.get_write_value()
#----- PROTECTED REGION ID(PilatusXM.NbFrames_write) ENABLED START -----#
if self.Simulation:
self.attr_NbFrames_read = data
return
cmd = "nimages %d" % data
reply = self.comm.send_to_detector(cmd)
if reply is None:
PyTango.Except.throw_exception("Communication error","Pilatus does not reply","write_NbFrames")
elif "ERR" in reply:
PyTango.Except.throw_exception("Command error","Pilatus reply: %s" % reply,"write_NbFrames")
#----- PROTECTED REGION END -----# // PilatusXM.NbFrames_write
def is_NbFrames_allowed(self, attr):
self.debug_stream("In is_NbFrames_allowed()")
if attr==PyTango.AttReqType.READ_REQ:
state_ok = not(self.get_state() in [])
else:
state_ok = not(self.get_state() in [PyTango.DevState.DISABLE,
PyTango.DevState.RUNNING,
PyTango.DevState.FAULT])
#----- PROTECTED REGION ID(PilatusXM.is_NbFrames_allowed) ENABLED START -----#
#----- PROTECTED REGION END -----# // PilatusXM.is_NbFrames_allowed
return state_ok
def read_NbExposures(self, attr):
self.debug_stream("In read_NbExposures()")
#----- PROTECTED REGION ID(PilatusXM.NbExposures_read) ENABLED START -----#
if not self.Simulation:
cmd = "nexpframe"
reply_cmd = "Exposures per frame set to: "
reply = self.comm.send_to_detector(cmd)
if reply is None:
PyTango.Except.throw_exception("Communication error","Pilatus does not reply","read_NbExposures")
elif reply_cmd in reply:
self.attr_NbExposures_read = int((reply.split(reply_cmd)[-1]).split(" ")[0])
else:
PyTango.Except.throw_exception("Communication error","Pilatus wrong reply","read_NbExposures")
attr.set_value(self.attr_NbExposures_read)
#----- PROTECTED REGION END -----# // PilatusXM.NbExposures_read
def write_NbExposures(self, attr):
self.debug_stream("In write_NbExposures()")
data = attr.get_write_value()
#----- PROTECTED REGION ID(PilatusXM.NbExposures_write) ENABLED START -----#
if self.Simulation:
self.attr_NbExposures_read = data
return
cmd = "nexpframe %d" % data
reply = self.comm.send_to_detector(cmd)
if reply is None:
PyTango.Except.throw_exception("Communication error","Pilatus does not reply","write_NbExposures")
elif "ERR" in reply:
PyTango.Except.throw_exception("Command error","Pilatus reply: %s" % reply,"write_NbExposures")
#----- PROTECTED REGION END -----# // PilatusXM.NbExposures_write
def is_NbExposures_allowed(self, attr):
self.debug_stream("In is_NbExposures_allowed()")
if attr==PyTango.AttReqType.READ_REQ:
state_ok = not(self.get_state() in [])
else:
state_ok = not(self.get_state() in [PyTango.DevState.DISABLE,
PyTango.DevState.RUNNING,
PyTango.DevState.FAULT])
#----- PROTECTED REGION ID(PilatusXM.is_NbExposures_allowed) ENABLED START -----#
#----- PROTECTED REGION END -----# // PilatusXM.is_NbExposures_allowed
return state_ok
def read_DelayTime(self, attr):
self.debug_stream("In read_DelayTime()")
#----- PROTECTED REGION ID(PilatusXM.DelayTime_read) ENABLED START -----#
if not self.Simulation:
cmd = "delay"
reply_cmd = "Delay time set to: "
reply = self.comm.send_to_detector(cmd)
if reply is None:
PyTango.Except.throw_exception("Communication error","Pilatus does not reply","read_DelayTime")
elif reply_cmd in reply:
self.attr_DelayTime_read = float((reply.split(reply_cmd)[-1]).split(" ")[0])
else:
PyTango.Except.throw_exception("Communication error","Pilatus wrong reply","read_DelayTime")
attr.set_value(self.attr_DelayTime_read)
#----- PROTECTED REGION END -----# // PilatusXM.DelayTime_read
def write_DelayTime(self, attr):
self.debug_stream("In write_DelayTime()")
data = attr.get_write_value()
#----- PROTECTED REGION ID(PilatusXM.DelayTime_write) ENABLED START -----#
if self.Simulation:
self.attr_DelayTime_read = data
return
cmd = "delay %g" % data
reply = self.comm.send_to_detector(cmd)
if reply is None:
PyTango.Except.throw_exception("Communication error","Pilatus does not reply","write_DelayTime")
elif "ERR" in reply:
PyTango.Except.throw_exception("Command error","Pilatus reply: %s" % reply,"write_DelayTime")
#----- PROTECTED REGION END -----# // PilatusXM.DelayTime_write
def is_DelayTime_allowed(self, attr):
self.debug_stream("In is_DelayTime_allowed()")
if attr==PyTango.AttReqType.READ_REQ:
state_ok = not(self.get_state() in [])
else:
state_ok = not(self.get_state() in [PyTango.DevState.DISABLE,
PyTango.DevState.RUNNING,
PyTango.DevState.FAULT])
#----- PROTECTED REGION ID(PilatusXM.is_DelayTime_allowed) ENABLED START -----#
#----- PROTECTED REGION END -----# // PilatusXM.is_DelayTime_allowed
return state_ok
def read_ShutterEnable(self, attr):
self.debug_stream("In read_ShutterEnable()")
#----- PROTECTED REGION ID(PilatusXM.ShutterEnable_read) ENABLED START -----#
attr.set_value(self.attr_ShutterEnable_read)
#----- PROTECTED REGION END -----# // PilatusXM.ShutterEnable_read
def write_ShutterEnable(self, attr):
self.debug_stream("In write_ShutterEnable()")
data = attr.get_write_value()
#----- PROTECTED REGION ID(PilatusXM.ShutterEnable_write) ENABLED START -----#
if self.Simulation:
self.attr_ShutterEnable_read = data
return
cmd = "ShutterEnable %g" % int(data)
reply = self.comm.send_to_detector(cmd)
if reply is None:
PyTango.Except.throw_exception("Communication error","Pilatus does not reply","write_ShutterEnable")
elif "ERR" in reply:
PyTango.Except.throw_exception("Command error","Pilatus reply: %s" % reply,"write_ShutterEnable")
self.attr_ShutterEnable_read = data
#----- PROTECTED REGION END -----# // PilatusXM.ShutterEnable_write
def is_ShutterEnable_allowed(self, attr):
self.debug_stream("In is_ShutterEnable_allowed()")
if attr==PyTango.AttReqType.READ_REQ:
state_ok = not(self.get_state() in [])
else:
state_ok = not(self.get_state() in [PyTango.DevState.DISABLE,
PyTango.DevState.RUNNING,
PyTango.DevState.FAULT])
#----- PROTECTED REGION ID(PilatusXM.is_ShutterEnable_allowed) ENABLED START -----#
#----- PROTECTED REGION END -----# // PilatusXM.is_ShutterEnable_allowed
return state_ok
def read_TriggerMode(self, attr):
self.debug_stream("In read_TriggerMode()")
#----- PROTECTED REGION ID(PilatusXM.TriggerMode_read) ENABLED START -----#
attr.set_value(self.attr_TriggerMode_read)
#----- PROTECTED REGION END -----# // PilatusXM.TriggerMode_read
def write_TriggerMode(self, attr):
self.debug_stream("In write_TriggerMode()")
data = attr.get_write_value()
#----- PROTECTED REGION ID(PilatusXM.TriggerMode_write) ENABLED START -----#
self.attr_TriggerMode_read = data
#----- PROTECTED REGION END -----# // PilatusXM.TriggerMode_write
def is_TriggerMode_allowed(self, attr):
self.debug_stream("In is_TriggerMode_allowed()")
if attr==PyTango.AttReqType.READ_REQ:
state_ok = not(self.get_state() in [])
else:
state_ok = not(self.get_state() in [PyTango.DevState.DISABLE,
PyTango.DevState.RUNNING,
PyTango.DevState.FAULT])
#----- PROTECTED REGION ID(PilatusXM.is_TriggerMode_allowed) ENABLED START -----#
#----- PROTECTED REGION END -----# // PilatusXM.is_TriggerMode_allowed
return state_ok
def read_UseRamDisk(self, attr):
self.debug_stream("In read_UseRamDisk()")
#----- PROTECTED REGION ID(PilatusXM.UseRamDisk_read) ENABLED START -----#
attr.set_value(self.attr_UseRamDisk_read)
#----- PROTECTED REGION END -----# // PilatusXM.UseRamDisk_read
def write_UseRamDisk(self, attr):
self.debug_stream("In write_UseRamDisk()")
data = attr.get_write_value()
#----- PROTECTED REGION ID(PilatusXM.UseRamDisk_write) ENABLED START -----#
#----- PROTECTED REGION END -----# // PilatusXM.UseRamDisk_write
def read_FileDir(self, attr):
self.debug_stream("In read_FileDir()")
#----- PROTECTED REGION ID(PilatusXM.FileDir_read) ENABLED START -----#
if not self.Simulation:
cmd = "imgpath"
reply_cmd = "OK "
reply = self.comm.send_to_detector(cmd)
if reply is None:
PyTango.Except.throw_exception("Communication error","Pilatus does not reply","read_FileDir")
elif reply_cmd in reply:
self.attr_FileDir_read = (reply.split(reply_cmd)[-1]).split(" ")[0]
else:
PyTango.Except.throw_exception("Communication error","Pilatus wrong reply","read_FileDir")
attr.set_value(self.attr_FileDir_read)
#----- PROTECTED REGION END -----# // PilatusXM.FileDir_read
def write_FileDir(self, attr):
self.debug_stream("In write_FileDir()")
data = attr.get_write_value()
#----- PROTECTED REGION ID(PilatusXM.FileDir_write) ENABLED START -----#
if self.Simulation:
self.attr_FileDir_read = data
return
cmd = "imgpath %s" % (data)
reply = self.comm.send_to_detector(cmd)
if reply is None:
PyTango.Except.throw_exception("Communication error","Pilatus does not reply","write_FileDir")
tokens = reply.split(" ")
if (len(tokens) < 2) or ("OK" not in tokens[1]):
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
PyTango.Except.throw_exception("Command error","Pilatus reply: %s" % reply,"write_FileDir")
#----- PROTECTED REGION END -----# // PilatusXM.FileDir_write
def is_FileDir_allowed(self, attr):
self.debug_stream("In is_FileDir_allowed()")
if attr==PyTango.AttReqType.READ_REQ:
state_ok = not(self.get_state() in [])
else:
state_ok = not(self.get_state() in [PyTango.DevState.DISABLE,
PyTango.DevState.RUNNING,
PyTango.DevState.FAULT])
#----- PROTECTED REGION ID(PilatusXM.is_FileDir_allowed) ENABLED START -----#
#----- PROTECTED REGION END -----# // PilatusXM.is_FileDir_allowed
return state_ok
def read_FilePrefix(self, attr):
self.debug_stream("In read_FilePrefix()")
#----- PROTECTED REGION ID(PilatusXM.FilePrefix_read) ENABLED START -----#
attr.set_value(self.attr_FilePrefix_read)
#----- PROTECTED REGION END -----# // PilatusXM.FilePrefix_read
def write_FilePrefix(self, attr):
self.debug_stream("In write_FilePrefix()")
data = attr.get_write_value()
#----- PROTECTED REGION ID(PilatusXM.FilePrefix_write) ENABLED START -----#
self.attr_FilePrefix_read = data
if len(data) and not data.endswith("_"):
self.attr_FilePrefix_read += "_"
#----- PROTECTED REGION END -----# // PilatusXM.FilePrefix_write
def is_FilePrefix_allowed(self, attr):
self.debug_stream("In is_FilePrefix_allowed()")
if attr==PyTango.AttReqType.READ_REQ:
state_ok = not(self.get_state() in [])
else:
state_ok = not(self.get_state() in [PyTango.DevState.DISABLE,
PyTango.DevState.RUNNING,
PyTango.DevState.FAULT])
#----- PROTECTED REGION ID(PilatusXM.is_FilePrefix_allowed) ENABLED START -----#
#----- PROTECTED REGION END -----# // PilatusXM.is_FilePrefix_allowed
return state_ok
def read_FileStartNum(self, attr):
self.debug_stream("In read_FileStartNum()")
#----- PROTECTED REGION ID(PilatusXM.FileStartNum_read) ENABLED START -----#
attr.set_value(self.attr_FileStartNum_read)
#----- PROTECTED REGION END -----# // PilatusXM.FileStartNum_read
def write_FileStartNum(self, attr):
self.debug_stream("In write_FileStartNum()")
data = attr.get_write_value()
#----- PROTECTED REGION ID(PilatusXM.FileStartNum_write) ENABLED START -----#
self.attr_FileStartNum_read = data
#----- PROTECTED REGION END -----# // PilatusXM.FileStartNum_write
def is_FileStartNum_allowed(self, attr):
self.debug_stream("In is_FileStartNum_allowed()")
if attr==PyTango.AttReqType.READ_REQ:
state_ok = not(self.get_state() in [])
else:
state_ok = not(self.get_state() in [PyTango.DevState.RUNNING])
#----- PROTECTED REGION ID(PilatusXM.is_FileStartNum_allowed) ENABLED START -----#
#----- PROTECTED REGION END -----# // PilatusXM.is_FileStartNum_allowed
return state_ok
def read_FilePostfix(self, attr):
self.debug_stream("In read_FilePostfix()")
#----- PROTECTED REGION ID(PilatusXM.FilePostfix_read) ENABLED START -----#
attr.set_value(self.attr_FilePostfix_read)
#----- PROTECTED REGION END -----# // PilatusXM.FilePostfix_read
def write_FilePostfix(self, attr):
self.debug_stream("In write_FilePostfix()")
data = attr.get_write_value()
#----- PROTECTED REGION ID(PilatusXM.FilePostfix_write) ENABLED START -----#
allowed_ext = ['tif','edf','img','cbf']
for item in allowed_ext:
if item in data:
self.attr_FilePostfix_read = ".%s" % item
return
PyTango.Except.throw_exception("Command error","Unknown Pilatus postfix (.tif, .edf, .img, .cbf)","write_FilePostfix")
#----- PROTECTED REGION END -----# // PilatusXM.FilePostfix_write
def is_FilePostfix_allowed(self, attr):
self.debug_stream("In is_FilePostfix_allowed()")
if attr==PyTango.AttReqType.READ_REQ:
state_ok = not(self.get_state() in [])
else:
state_ok = not(self.get_state() in [PyTango.DevState.DISABLE,
PyTango.DevState.RUNNING,
PyTango.DevState.FAULT])
#----- PROTECTED REGION ID(PilatusXM.is_FilePostfix_allowed) ENABLED START -----#
#----- PROTECTED REGION END -----# // PilatusXM.is_FilePostfix_allowed
return state_ok
def read_LastImageTaken(self, attr):
self.debug_stream("In read_LastImageTaken()")
#----- PROTECTED REGION ID(PilatusXM.LastImageTaken_read) ENABLED START -----#
attr.set_value(self.attr_LastImageTaken_read)
#----- PROTECTED REGION END -----# // PilatusXM.LastImageTaken_read
def read_Energy(self, attr):
self.debug_stream("In read_Energy()")
#----- PROTECTED REGION ID(PilatusXM.Energy_read) ENABLED START -----#
attr.set_value(self.attr_Energy_read)
#----- PROTECTED REGION END -----# // PilatusXM.Energy_read
def write_Energy(self, attr):
self.debug_stream("In write_Energy()")
data = attr.get_write_value()
#----- PROTECTED REGION ID(PilatusXM.Energy_write) ENABLED START -----#
#----- PROTECTED REGION END -----# // PilatusXM.Energy_write
def is_Energy_allowed(self, attr):
self.debug_stream("In is_Energy_allowed()")
if attr==PyTango.AttReqType.READ_REQ:
state_ok = not(self.get_state() in [])
else:
state_ok = not(self.get_state() in [PyTango.DevState.DISABLE,
PyTango.DevState.RUNNING,
PyTango.DevState.FAULT])
#----- PROTECTED REGION ID(PilatusXM.is_Energy_allowed) ENABLED START -----#
#----- PROTECTED REGION END -----# // PilatusXM.is_Energy_allowed
return state_ok
def read_Threshold(self, attr):
self.debug_stream("In read_Threshold()")
#----- PROTECTED REGION ID(PilatusXM.Threshold_read) ENABLED START -----#
if not self.Simulation:
cmd = "SetThreshold"
reply_cmd = "threshold: "
retries = 5
while (retries > 0):
reply = self.comm.send_to_detector(cmd)
if reply is None:
PyTango.Except.throw_exception("Communication error","Pilatus does not reply","read_Threshold")
elif reply_cmd in reply:
self.attr_Threshold_read = int((reply.split(reply_cmd)[-1]).split(" ")[0])
break
elif "Threshold has not been set" in reply:
PyTango.Except.throw_exception("Pilatus error","Threshold has not been set","read_Threshold")
retries -= 1
time.sleep(0.2)
if retries == 0:
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
PyTango.Except.throw_exception("Communication error","Pilatus wrong reply","read_Threshold")
attr.set_value(self.attr_Threshold_read)
#----- PROTECTED REGION END -----# // PilatusXM.Threshold_read
def write_Threshold(self, attr):
self.debug_stream("In write_Threshold()")
data = attr.get_write_value()
#----- PROTECTED REGION ID(PilatusXM.Threshold_write) ENABLED START -----#
#
# read the actual threshold and send command only if necessary
#
if self.Simulation:
self.attr_Threshold_read = data
return
cmd = "SetThreshold"
reply_cmd = "threshold: "
reply = self.comm.send_to_detector(cmd)
if reply is None:
PyTango.Except.throw_exception("Communication error","Pilatus does not reply","write_Threshold")
elif reply_cmd in reply:
self.attr_Threshold_read = int((reply.split(reply_cmd)[-1]).split(" ")[0])
elif "Threshold has not been set" in reply:
self.attr_Threshold_read = None
else:
PyTango.Except.throw_exception("Communication error","Pilatus wrong reply","write_Threshold")
if self.attr_Threshold_read == data:
return
cmd = "SetThreshold %d" % data
reply = self.comm.send_to_detector(cmd)
if reply is None:
PyTango.Except.throw_exception("Communication error","Pilatus does not reply","write_Threshold")
elif "ERR" in reply:
PyTango.Except.throw_exception("Command error","Pilatus reply: %s" % reply,"write_Threshold")
self.set_state(PyTango.DevState.INIT)
self.set_status("The device is in INIT state.")
#----- PROTECTED REGION END -----# // PilatusXM.Threshold_write
def is_Threshold_allowed(self, attr):
self.debug_stream("In is_Threshold_allowed()")
if attr==PyTango.AttReqType.READ_REQ:
state_ok = not(self.get_state() in [])
else:
state_ok = not(self.get_state() in [PyTango.DevState.DISABLE,
PyTango.DevState.RUNNING,
PyTango.DevState.FAULT])
#----- PROTECTED REGION ID(PilatusXM.is_Threshold_allowed) ENABLED START -----#
#----- PROTECTED REGION END -----# // PilatusXM.is_Threshold_allowed
return state_ok
def read_Gain(self, attr):
self.debug_stream("In read_Gain()")
#----- PROTECTED REGION ID(PilatusXM.Gain_read) ENABLED START -----#
if not self.Simulation:
cmd = "SetThreshold"
reply_cmd = "Settings: "
reply = self.comm.send_to_detector(cmd)
if reply is None:
PyTango.Except.throw_exception("Communication error","Pilatus does not reply","read_Gain")
elif reply_cmd in reply:
gainstr = ((reply.split(reply_cmd)[-1]).split(";")[0])
if "mid gain" in gainstr:
self.attr_Gain_read = 1
elif "low gain" in gainstr:
self.attr_Gain_read = 0
elif "high gain" in gainstr:
self.attr_Gain_read = 2
elif "ultra high gain" in gainstr:
self.attr_Gain_read = 3
else:
PyTango.Except.throw_exception("Communication error","Pilatus wrong reply","read_Gain")
attr.set_value(self.attr_Gain_read)
#----- PROTECTED REGION END -----# // PilatusXM.Gain_read
def write_Gain(self, attr):
self.debug_stream("In write_Gain()")
data = attr.get_write_value()
#----- PROTECTED REGION ID(PilatusXM.Gain_write) ENABLED START -----#
if self.Simulation:
self.attr_Gain_read = data
return
gains = {0:"lowG", 1:"midG", 2:"highG", 3:"uhighG"}
if data not in gains:
PyTango.Except.throw_exception("Command error","Invalid gain value!","write_Gain")
# read the actual gain and send command only if necessary
cmd = "SetThreshold"
reply_cmd = "Settings: "
reply = self.comm.send_to_detector(cmd)
if reply is None:
PyTango.Except.throw_exception("Communication error","Pilatus does not reply","write_Gain")
elif reply_cmd in reply:
gainstr = ((reply.split(reply_cmd)[-1]).split(";")[0])
if "mid gain" in gainstr:
self.attr_Gain_read = 1
elif "low gain" in gainstr:
self.attr_Gain_read = 0
elif "high gain" in gainstr:
self.attr_Gain_read = 2
elif "ultra high gain" in gainstr:
self.attr_Gain_read = 3
else:
PyTango.Except.throw_exception("Communication error","Pilatus wrong reply","write_Gain")
if self.attr_Gain_read == data:
return
# Get actual threshold
reply_cmd = "threshold: "
if reply_cmd in reply:
actual_Threshold_read = int((reply.split(reply_cmd)[-1]).split(" ")[0])
else:
PyTango.Except.throw_exception("Communication error","Pilatus wrong reply","write_Gain")
cmd = "SetThreshold %s %d" % (gains[data],actual_Threshold_read)
reply = self.comm.send_to_detector(cmd)
if reply is None:
PyTango.Except.throw_exception("Communication error","Pilatus does not reply","write_Gain")
elif "ERR" in reply:
PyTango.Except.throw_exception("Command error","Pilatus reply: %s" % reply,"write_Gain")
#----- PROTECTED REGION END -----# // PilatusXM.Gain_write
def is_Gain_allowed(self, attr):
self.debug_stream("In is_Gain_allowed()")
if attr==PyTango.AttReqType.READ_REQ:
state_ok = not(self.get_state() in [])
else:
state_ok = not(self.get_state() in [PyTango.DevState.DISABLE,
PyTango.DevState.RUNNING,
PyTango.DevState.FAULT])
#----- PROTECTED REGION ID(PilatusXM.is_Gain_allowed) ENABLED START -----#
#----- PROTECTED REGION END -----# // PilatusXM.is_Gain_allowed
return state_ok
def read_LastImagePath(self, attr):
self.debug_stream("In read_LastImagePath()")
#----- PROTECTED REGION ID(PilatusXM.LastImagePath_read) ENABLED START -----#
attr.set_value(self.attr_LastImagePath_read)
#----- PROTECTED REGION END -----# // PilatusXM.LastImagePath_read
def read_MxSettings(self, attr):
self.debug_stream("In read_MxSettings()")
#----- PROTECTED REGION ID(PilatusXM.MxSettings_read) ENABLED START -----#
if not self.Simulation:
cmd = "mxsettings"
reply_cmd = "OK "
reply = self.comm.send_to_detector(cmd)
if reply is None:
PyTango.Except.throw_exception("Communication error","Pilatus does not reply","read_MxSettings")
elif reply_cmd in reply:
self.attr_MxSettings_read = (reply.split(reply_cmd)[-1]).strip()
else:
PyTango.Except.throw_exception("Communication error","Pilatus wrong reply","read_MxSettings")
attr.set_value(self.attr_MxSettings_read)
#----- PROTECTED REGION END -----# // PilatusXM.MxSettings_read
def write_MxSettings(self, attr):
self.debug_stream("In write_MxSettings()")
data = attr.get_write_value()
#----- PROTECTED REGION ID(PilatusXM.MxSettings_write) ENABLED START -----#
if self.Simulation:
self.attr_MxSettings_read = data
return
cmd = "mxsettings %s" % (data)
reply = self.comm.send_to_detector(cmd)
if reply is None:
PyTango.Except.throw_exception("Communication error","Pilatus does not reply","write_MxSettings")
elif "ERR" in reply:
PyTango.Except.throw_exception("Command error","Pilatus reply: %s" % reply,"write_MxSettings")
#----- PROTECTED REGION END -----# // PilatusXM.MxSettings_write
def read_GapFill(self, attr):
self.debug_stream("In read_GapFill()")
#----- PROTECTED REGION ID(PilatusXM.GapFill_read) ENABLED START -----#
if not self.Simulation:
cmd = "gapfill"
reply_cmd = "Detector gap-fill is: "
reply = self.comm.send_to_detector(cmd)
if reply is None:
PyTango.Except.throw_exception("Communication error","Pilatus does not reply","read_GapFill")
elif reply_cmd in reply:
self.attr_GapFill_read = int((reply.split(reply_cmd)[-1]).strip())
else:
PyTango.Except.throw_exception("Communication error","Pilatus wrong reply","read_GapFill")
attr.set_value(self.attr_GapFill_read)
#----- PROTECTED REGION END -----# // PilatusXM.GapFill_read
def write_GapFill(self, attr):
self.debug_stream("In write_GapFill()")
data = attr.get_write_value()
#----- PROTECTED REGION ID(PilatusXM.GapFill_write) ENABLED START -----#
if self.Simulation:
self.attr_GapFill_read = data
return
cmd = "gapfill %d" % (data)
reply = self.comm.send_to_detector(cmd)
if reply is None:
PyTango.Except.throw_exception("Communication error","Pilatus does not reply","write_GapFill")
elif "ERR" in reply:
PyTango.Except.throw_exception("Command error","Pilatus reply: %s" % reply,"write_GapFill")
#----- PROTECTED REGION END -----# // PilatusXM.GapFill_write
def read_LdBadPixMap(self, attr):
self.debug_stream("In read_LdBadPixMap()")
#----- PROTECTED REGION ID(PilatusXM.LdBadPixMap_read) ENABLED START -----#
if not self.Simulation:
cmd = "ldbadpixmap"
reply_cmd = "Bad pixels loaded from"
reply = self.comm.send_to_detector(cmd)
if reply is None:
PyTango.Except.throw_exception("Communication error","Pilatus does not reply","read_LdBadPixMap")
elif reply_cmd in reply:
self.attr_LdBadPixMap_read = ((reply.split(reply_cmd)[-1]).strip())
else:
PyTango.Except.throw_exception("Communication error","Pilatus wrong reply","read_LdBadPixMap")
attr.set_value(self.attr_LdBadPixMap_read)
#----- PROTECTED REGION END -----# // PilatusXM.LdBadPixMap_read
def write_LdBadPixMap(self, attr):
self.debug_stream("In write_LdBadPixMap()")
data = attr.get_write_value()
#----- PROTECTED REGION ID(PilatusXM.LdBadPixMap_write) ENABLED START -----#
if self.Simulation:
self.attr_LdBadPixMap_read = data
return
cmd = "ldbadpixmap %s" % (data)
reply = self.comm.send_to_detector(cmd)
if reply is None:
PyTango.Except.throw_exception("Communication error","Pilatus does not reply","write_LdBadPixMap")
elif "ERR" in reply:
PyTango.Except.throw_exception("Command error","Pilatus reply: %s" % reply,"write_LdBadPixMap")
#----- PROTECTED REGION END -----# // PilatusXM.LdBadPixMap_write
def read_attr_hardware(self, data):
self.debug_stream("In read_attr_hardware()")
#----- PROTECTED REGION ID(PilatusXM.read_attr_hardware) ENABLED START -----#
#----- PROTECTED REGION END -----# // PilatusXM.read_attr_hardware
# -------------------------------------------------------------------------
# PilatusXM command methods
# -------------------------------------------------------------------------
def StartStandardAcq(self):
""" Start an acquisition with the propositioned parameters
"""
self.debug_stream("In StartStandardAcq()")
#----- PROTECTED REGION ID(PilatusXM.StartStandardAcq) ENABLED START -----#
if self.Simulation:
self.total_exp_time = self.attr_ExposureTime_read * self.attr_NbFrames_read * self.attr_NbExposures_read
self.start_time = time.time()
self.set_state(PyTango.DevState.RUNNING)
self.set_status("The device is in RUNNING state.")
return
expPeriodAttr = fakeAttr()
self.read_ExposurePeriod(expPeriodAttr)
expTimeAttr = fakeAttr()
self.read_ExposureTime(expTimeAttr)
Roberto Borghes
committed
if (expPeriodAttr.value < (expTimeAttr.value + self.ReadOutTime) ):
expPeriodAttr.set_value(expTimeAttr.value + self.ReadOutTime)
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
self.write_ExposurePeriod(expPeriodAttr)
fullname = "%s%05d%s" % (self.attr_FilePrefix_read,self.attr_FileStartNum_read,self.attr_FilePostfix_read)
trgModes = {0:"exposure", 1:"extenable",2:"exttrigger",3:"extmtrigger"}
#
self.attr_LastImageTaken_read = ''
self.attr_LastImagePath_read = ''
cmd = trgModes[self.attr_TriggerMode_read] +" "+fullname
reply = self.comm.send_to_detector(cmd)
if reply is None:
PyTango.Except.throw_exception("Communication error","Pilatus does not reply","StartStandardAcq")
elif "ERR" in reply:
PyTango.Except.throw_exception("Command error","Pilatus reply: %s" % reply,"StartStandardAcq")
elif "15 OK" in reply and "Starting" in reply:
self.set_state(PyTango.DevState.RUNNING)
self.set_status("The device is in RUNNING state.")
#----- PROTECTED REGION END -----# // PilatusXM.StartStandardAcq
def is_StartStandardAcq_allowed(self):
self.debug_stream("In is_StartStandardAcq_allowed()")
state_ok = not(self.get_state() in [PyTango.DevState.DISABLE,
PyTango.DevState.RUNNING,
PyTango.DevState.FAULT])
#----- PROTECTED REGION ID(PilatusXM.is_StartStandardAcq_allowed) ENABLED START -----#
#----- PROTECTED REGION END -----# // PilatusXM.is_StartStandardAcq_allowed
return state_ok
def StopAcq(self):
""" Stop the acquisition. This works only for multi images acquisitions.
A single image acquisition will always finish.
"""
self.debug_stream("In StopAcq()")
#----- PROTECTED REGION ID(PilatusXM.StopAcq) ENABLED START -----#
if self.Simulation:
self.set_state(PyTango.DevState.ON)
self.set_status("The device is in ON state. Ready")
return
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
cmd = "camcmd k"
reply = self.comm.send_to_detector(cmd, wait_reply = False)
#----- PROTECTED REGION END -----# // PilatusXM.StopAcq
def is_StopAcq_allowed(self):
self.debug_stream("In is_StopAcq_allowed()")
state_ok = not(self.get_state() in [PyTango.DevState.DISABLE,
PyTango.DevState.FAULT])
#----- PROTECTED REGION ID(PilatusXM.is_StopAcq_allowed) ENABLED START -----#
#----- PROTECTED REGION END -----# // PilatusXM.is_StopAcq_allowed
return state_ok
def Reset(self):
""" Reset a state
"""
self.debug_stream("In Reset()")
#----- PROTECTED REGION ID(PilatusXM.Reset) ENABLED START -----#
if self.Simulation:
self.set_state(PyTango.DevState.ON)
self.set_status("The device is in ON state. Ready")
return
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
cmd = "camcmd ResetCam"
reply = self.comm.send_to_detector(cmd, wait_reply = False)
#----- PROTECTED REGION END -----# // PilatusXM.Reset
#----- PROTECTED REGION ID(PilatusXM.programmer_methods) ENABLED START -----#
#----- PROTECTED REGION END -----# // PilatusXM.programmer_methods
class PilatusXMClass(PyTango.DeviceClass):
# -------- Add you global class variables here --------------------------
#----- PROTECTED REGION ID(PilatusXM.global_class_variables) ENABLED START -----#
#----- PROTECTED REGION END -----# // PilatusXM.global_class_variables
# Class Properties
class_property_list = {
}
# Device Properties
device_property_list = {
'ServerAddress':
[PyTango.DevString,
"The IP address of the PilatusXM camserver.",
Roberto Borghes
committed
True,
[] ],
'Simulation':
[PyTango.DevBoolean,
'',
[False]],
Roberto Borghes
committed
'ReadOutTime':
[PyTango.DevFloat,
"Minimum ReadOUt influences the minimum difference between ExposurePeriod and ExposureTime.",
[0.003]],
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
}
# Command definitions
cmd_list = {
'StartStandardAcq':
[[PyTango.DevVoid, "none"],
[PyTango.DevVoid, "none"]],
'StopAcq':
[[PyTango.DevVoid, "none"],
[PyTango.DevVoid, "none"]],
'Reset':
[[PyTango.DevVoid, "none"],
[PyTango.DevVoid, "none"]],
}
# Attribute definitions
attr_list = {
'ExposureTime':
[[PyTango.DevDouble,
PyTango.SCALAR,
PyTango.READ_WRITE],
{
'label': "Exposure Time",
'unit': "s",
'format': "%10.8f",
'min value': "0",
'description': "The exposure time for the detector.\nIn the External Enable mode this value is not used by camserver.",
'Memorized':"true"
} ],
'ExposurePeriod':
[[PyTango.DevDouble,
PyTango.SCALAR,
PyTango.READ_WRITE],
{
'label': "Exposure Period",
'unit': "s",
'format': "%10.8f",
'min value': "0",
'description': "Controls the exposure period between to images in seconds. \nIt applies only in Internal or External Trigger modes when NbFrames > 1.",
'Memorized':"true"
} ],
'NbFrames':
[[PyTango.DevLong,
PyTango.SCALAR,
PyTango.READ_WRITE],
{
'label': "Number of Frames",
'unit': " ",
'format': "%6d",
'min value': "1",
'description': "The number of images to acquire when starting the detector",
'Memorized':"true"
} ],
'NbExposures':
[[PyTango.DevLong,
PyTango.SCALAR,
PyTango.READ_WRITE],
{
'label': "Number of Exposures",
'unit': " ",
'format': "%6d",
'min value': "1",
'description': "The number of exposures per images.\nIt applies only in External Enable mode.",
'Memorized':"true"
} ],
'DelayTime':
[[PyTango.DevDouble,
PyTango.SCALAR,
PyTango.READ_WRITE],
{
'label': "Delay Time",
'unit': "s",
'format': "%6.4f",
'min value': "0",
'description': "Delay in seconds between the external trigger and the start of image acquisition. \nIt only applies in External Trigger mode",
'Memorized':"true"
} ],
'ShutterEnable':
[[PyTango.DevBoolean,
PyTango.SCALAR,
PyTango.READ_WRITE],
{
'label': "Enable Shutter Control",
'description': "Enable the shutter control by the detector.",
'Memorized':"true"
} ],
'TriggerMode':
[[PyTango.DevShort,
PyTango.SCALAR,
PyTango.READ_WRITE],
{
'label': "Trigger Mode",
'format': "%1d",
'max value': "3",
'min value': "0",
'description': "The possible trigger modes for the Pilatus detector are:\n<p>\n 0 = Internal (external signal not used)\n<br />\n 1 = External Enable (count while external trigger line is high, readout on high to low transition)\n <br /> \n 2 = External Trigger (begin acquisition sequence on high to low transition of external trigger line)\n <br /> \n 3 = Multiple External Trigger (high to low transition on external signal triggers a single acquisition for the programmed exposure time)\n</p><p>\nThe 4 modes correspond directly to the camserver \ncommands Exposure, ExtEnable, ExtTrigger, and ExtMTrigger respectively.\n</p></Font>",
'Memorized':"true"
} ],
'UseRamDisk':
[[PyTango.DevBoolean,
PyTango.SCALAR,
PyTango.READ_WRITE],
{
'label': "Use RAM Disk",
'description': "When true, will force image file to be written to /ramdisk.\nTherefore, attribute FileDir will be ignored.",
'Memorized':"true"
} ],
'FileDir':
[[PyTango.DevString,
PyTango.SCALAR,
PyTango.READ_WRITE],
{
'label': "Image File Path",
'unit': " ",
'description': "Path to the dector image files.",
'Memorized':"true"
} ],
'FilePrefix':
[[PyTango.DevString,
PyTango.SCALAR,
PyTango.READ_WRITE],
{
'label': "Image File Prefix",
'unit': " ",
'description': "The prefix of the image files to be created.\nThe full image file name will be composed as\n<br />\n<b>prefix_number.postfix </b>\n<br />\nwhen acquiring images.",
'Memorized':"true"
} ],
'FileStartNum':
[[PyTango.DevLong,
PyTango.SCALAR,
PyTango.READ_WRITE],
{
'label': "Image File Number",
'unit': " ",
'format': "%5d",
'description': "The file number used when taking an image.\n<br />\nWhen taking more than one frame, the detector creates\nthe file numbers automatically from this number onwards.\n<p>\nWhen saving multiple images (NImages>1) camserver has its own rules for \ncreating the names of the individual files.\nThe following examples shows the interpretation of the basename.\n</p><p>\nBasename - Files produced\n<br />\ntest6.tif - test6_00000.tif, test6_00001.tif, ...\n<br />\ntest6_.tif - test6_00000.tif, test6_00001.tif, ...\n<br />\ntest6_00008.tif - test6_00008.tif, test6_00009.tif, ...\n<br />\ntest6_2_00035.tif - test6_2_00035.tif, test6_2_00036.tif, ...\n</p>\nThe numbers following the last '_' are taken as a format template, \nand as a start value. \nThe format is also constrained by the requested number of images.",
'Memorized':"true"
} ],
'FilePostfix':
[[PyTango.DevString,
PyTango.SCALAR,
PyTango.READ_WRITE],
{
'label': "Image File Postfix",
'unit': " ",
'description': "The Pilatus detector allows the following postfix:\n<br />\n<b>.tif, .edf, .img, .cbf</b>\n<br />\nThe postfix determines the image format for the saved\nimage files.\n<p>\nThe camserver uses the file extension to determine what format to save \nthe files in.\n</p>",
'Memorized':"true"
} ],
'LastImageTaken':
[[PyTango.DevString,
PyTango.SCALAR,
PyTango.READ],
{
'label': "Last Image File Name",
'unit': " ",
'description': "The name of the last image file written.",
} ],
'Energy':
[[PyTango.DevLong,
PyTango.SCALAR,
PyTango.READ_WRITE],
{
'label': "Photon Energy",
'unit': "eV",
'format': "%5d",
'description': "Simplified method to set gain and threshold for the\ndetector.\nThe threshold will be set to half the photon energy.\nThe detecor loads the corresponding trim files\nwhen changing the energy.\nModifying the detector setting will take several\nseconds.",
'Memorized':"true_without_hard_applied"
} ],
'Threshold':
[[PyTango.DevLong,
PyTango.SCALAR,
PyTango.READ_WRITE],
{
'label': "Threshold Energy",
'unit': "eV",
'format': "%5d",
'max value': "14337",
'min value': "2113",
'description': "The threshold energy for the detector.\nThe detecor loads the corresponding trim files\nwhen changing the energy threshold.\nThe threshold energy will always be set together with the gain.\nModifying the detector setting will take several\nseconds.",
'Memorized':"true_without_hard_applied"
} ],
'Gain':
[[PyTango.DevShort,
PyTango.SCALAR,
PyTango.READ_WRITE],
{
'label': "Gain (Energy Range)",
'unit': " ",
'format': "%1d",
'max value': "3",
'min value': "0",
'description': "The gain controls the value of Vrf, which determines the shaping time and gain of\nthe input amplifiers.\nThe allowed gain values for the Pilatus detector are:\n\n 0 = lowG = Fastest shaping time (~125ns) and lowest gain.\n\n 1 = midG = Medium shaping time (~200ns) and medium gain.\n \n 2 = highG = Slow shaping time (~400ns) and high gain.\n \n 3 = uhighG = Slowest peaking time and highest gain.\nThe gain will always be set together with the threshold energy.\nModifying the detector setting will take several\nseconds.",
'Memorized':"true_without_hard_applied"
} ],
'LastImagePath':
[[PyTango.DevString,
PyTango.SCALAR,
PyTango.READ],
{
'label': "Last Image Path",
'description': "The last path where an image was written.",
} ],
'MxSettings':
[[PyTango.DevString,
PyTango.SCALAR,
PyTango.READ_WRITE],
{
'description': "Set crystallographic parameters in the image header.\nPossible parameter names are: Wavelength, Energy_range, Detector_distance, ...\n(see Pilatus manual for a complete list).",
} ],
'GapFill':
[[PyTango.DevShort,
PyTango.SCALAR,
PyTango.READ_WRITE]],
'LdBadPixMap':
[[PyTango.DevString,
PyTango.SCALAR,
PyTango.READ_WRITE]],
}
def main():
try:
py = PyTango.Util(sys.argv)
py.add_class(PilatusXMClass, PilatusXM, 'PilatusXM')
#----- PROTECTED REGION ID(PilatusXM.add_classes) ENABLED START -----#
#----- PROTECTED REGION END -----# // PilatusXM.add_classes
U = PyTango.Util.instance()
U.server_init()
U.server_run()
except PyTango.DevFailed as e:
print ('-------> Received a DevFailed exception:', e)
except Exception as e:
print ('-------> An unforeseen exception occured....', e)
if __name__ == '__main__':
main()