Newer
Older
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()