The following client (mythen_client.py) can be used to setup the detector and acquire data. See 20.1.6 for an example of the necessary steps.
#!/usr/bin/env python
from PyTango import *
import sys
import time
def usage():
print "Usage:"
print " 'mythen_client.py' -> to get information and status"
print " 'mythen_client.py help' -> prints this help"
print " 'mythen_client.py status' -> Gets the detector status"
print " 'mythen_client.py trimdir <dirname>' -> Sets the directory containing"
print " trimbit files"
print " 'mythen_client.py caldir <dirname>' -> Sets the directory containig"
print " calibration files"
print " 'mythen_client.py outdir <dirname>' -> Sets the directory to which data"
print " files will be written"
print " 'mythen_client.py fname <filename>' -> Sets the root for output file names"
print " 'mythen_client.py index <index>' -> Sets the index of the output file"
print " 'mythen_client.py settings <standard|fast|highgain>' -> Detector settings"
print " 'mythen_client.py threshold <threshold>' -> Sets the detector thresholds (eV)"
print " 'mythen_client.py exptime <exptime>' -> Sets the exposure time (s)"
print " 'mythen_client.py frames <framenumber>' -> Sets the number of frames to be"
print " acquired"
print " 'mythen_client.py start' -> Starts the acquisition"
print " 'mythen_client.py frame' -> Downloads a single frame from the detector"
print " 'mythen_client.py data' -> Downloads all available data from the detector"
print " 'mythen_client.py flatfield [filename]' -> Sets flatfield corrections"
print " (use empty filename to disable corrections)"
print " 'mythen_client.py ratecorr <deadtime>' -> Sets rate corrections (ns)"
print " (use -1 for defaule corrections, 0 to disable corrections)"
def refresh(mythendet):
"""The refresh function is used to refresh all the attributs"""
mythendet.Refresh()
def get_hostname(mythendet):
"""The get_hostname function is used to read the hostname."""
print mythendet.get_property("hostname")
def get_port(mythendet):
"""The get_port function is used to read the port."""
print mythendet.get_property("port")
def get_det_id(mythendet):
"""The get_det_id function is used to read the detector ID."""
print mythendet.get_property("detectorId")
def get_trimdir(mythendet):
"""The get_trimdir function is used to read the trimbit file directory."""
print "Trimdir: " + mythendet.read_attribute("TrimDir").value
def set_trimdir(mythendet, trimdir):
"""The set_trimdir function is used to set the trimbit file directory."""
mythendet.write_attribute("TrimDir", trimdir)
get_trimdir(mythendet)
def get_caldir(mythendet):
"""The get_caldir function is used to read the calibration file directory."""
print "Caldir: " + mythendet.read_attribute("CalibrationDir").value
def set_caldir(mythendet, caldir):
"""The set_caldir function is used to set the calibration file directory."""
mythendet.write_attribute("CalibrationDir", caldir)
get_caldir(mythendet)
def get_outdir(mythendet):
"""The get_outdir function is used to read the output file directory."""
print "Outdir: " + mythendet.read_attribute("OutDir").value
def set_outdir(mythendet, outdir):
"""The set_outdir function is used to set the output file directory."""
mythendet.write_attribute("OutDir", outdir)
get_outdir(mythendet)
def get_outfile(mythendet):
"""The get_outfile function is used to read the output file name."""
print "Fname: " + mythendet.read_attribute("OutFileName").value
def set_outfile(mythendet, outfile):
"""The set_outfile function is used to set the output file name."""
mythendet.write_attribute("OutFileName", outfile)
get_outfile(mythendet)
def get_outfileidx(mythendet):
"""The get_outfileidx function is used to read the output file index."""
print "Index: %d" % mythendet.read_attribute("OutFileIndex").value
def set_outfileidx(mythendet, index):
"""The set_outfile function is used to set the output file name."""
mythendet.write_attribute("OutFileIndex", int(index))
get_outfileidx(mythendet)
def get_settings(mythendet):
"""The get_settings function is used to read the detector settings."""
print "Settings: %s" % mythendet.read_attribute("Settings").value
def set_settings(mythendet, settings):
"""The set_settings function is used to set the detector settings."""
mythendet.write_attribute("Settings", settings)
get_settings(mythendet)
def get_threshold(mythendet):
"""The get_threshold function is used to read the detector thresholds."""
print "Threshold: %d (eV)" % mythendet.read_attribute("Threshold").value
def set_threshold(mythendet, thr):
"""The set_threshold function is used to set the detector thresholds."""
mythendet.write_attribute("Threshold", int(thr))
get_threshold(mythendet)
def get_exptime(mythendet):
"""The get_exptime function is used to read the exposure time."""
print "ExpTime: %f (s)" % mythendet.read_attribute("ExposureTime").value
def set_exptime(mythendet, exptime):
"""The set_exptime function is used to set the exposure time."""
mythendet.write_attribute("ExposureTime", float(exptime))
get_exptime(mythendet)
def get_frames(mythendet):
"""The get_frames function is used to read the number of frames."""
print "Frames: %d" % mythendet.read_attribute("FramesPerCycle").value
def set_frames(mythendet, frames):
"""The set_frames function is used to set the number of frames."""
mythendet.write_attribute("FramesPerCycle", int(frames))
get_frames(mythendet)
def start_acquisition(mythendet):
"""The start_acquisition function is used to start the acquisition."""
mythendet.StartAcquisition()
print "Acquisition started"
def get_frame(mythendet):
"""The get_frame function is used to download a single frame from the detector."""
mythendet.GetFrame()
print "Got one frame from detector"
def get_data(mythendet):
"""The get_data function is used to download data from the detector."""
mythendet.GetData()
print "Got data from detector"
def get_flatfield(mythendet):
"""The get_flatfield function is used to get flatfield corrections."""
if (mythendet.read_attribute("FlatFieldEnabled").value):
print "Flatfield: " + mythendet.read_attribute("FlatFieldFileName").value
else:
print "Flatfield: (disabled)"
def set_flatfield(mythendet, fname):
"""The set_flatfield function is used to set flatfield corrections."""
if (fname==""):
mythendet.write_attribute("FlatFieldEnabled", False)
else:
mythendet.write_attribute("FlatFieldEnabled", True)
mythendet.write_attribute("FlatFieldFileName", fname)
get_flatfield(mythendet)
def get_ratecorr(mythendet):
"""The get_ratecorr function is used to get rate corrections (ns)."""
if (not mythendet.read_attribute("RateCorrEnabled").value):
print "Ratecorr: (disabled)"
elif (mythendet.read_attribute("RateCorrDefault").value):
print "Ratecorr: %f (default)" % float(mythendet.read_attribute("RateCorrDeadTime").value)
else:
print "Ratecorr: %f (ns)" % float(mythendet.read_attribute("RateCorrDeadTime").value)
def set_ratecorr(mythendet, deadtime):
"""The set_ratecorr function is used to set rate corrections (ns)."""
dtime = float(deadtime)
if (dtime==-1):
mythendet.write_attribute("RateCorrEnabled", True)
mythendet.write_attribute("RateCorrDefault", True)
elif (dtime==0):
mythendet.write_attribute("RateCorrEnabled", False)
else:
mythendet.write_attribute("RateCorrEnabled", True)
mythendet.write_attribute("RateCorrDefault", False)
mythendet.write_attribute("RateCorrDeadTime", dtime)
get_ratecorr(mythendet)
def get_status(mythendet):
"""The get_state function is used to read the status."""
print mythendet.Status()
#
# main
#
try :
mythendet = DeviceProxy( "//haspp0xtdot:10000/test/mythen/exp.01")
if (len(sys.argv)==1):
refresh(mythendet)
get_hostname(mythendet)
get_port(mythendet)
get_det_id(mythendet)
get_trimdir(mythendet)
get_caldir(mythendet)
get_outdir(mythendet)
get_outfile(mythendet)
get_outfileidx(mythendet)
get_settings(mythendet)
get_threshold(mythendet)
get_exptime(mythendet)
get_frames(mythendet)
get_flatfield(mythendet)
get_ratecorr(mythendet)
get_status(mythendet)
print " "
print "Run 'mythen_client.py help' to see program options"
print " "
else:
if (sys.argv[1]=="help"):
usage()
elif (sys.argv[1] == "trimdir" and len(sys.argv)>2):
set_trimdir(mythendet, sys.argv[2])
elif (sys.argv[1] == "caldir" and len(sys.argv)>2):
set_caldir(mythendet, sys.argv[2])
elif (sys.argv[1] == "outdir" and len(sys.argv)>2):
set_outdir(mythendet, sys.argv[2])
elif (sys.argv[1] == "fname" and len(sys.argv)>2):
set_outfile(mythendet, sys.argv[2])
elif (sys.argv[1] == "index" and len(sys.argv)>2):
set_outfileidx(mythendet, sys.argv[2])
elif (sys.argv[1] == "settings" and len(sys.argv)>2):
set_settings(mythendet, sys.argv[2])
elif (sys.argv[1] == "threshold" and len(sys.argv)>2):
set_threshold(mythendet, sys.argv[2])
elif (sys.argv[1] == "exptime" and len(sys.argv)>2):
set_exptime(mythendet, sys.argv[2])
elif (sys.argv[1] == "frames" and len(sys.argv)>2):
set_frames(mythendet, sys.argv[2])
elif (sys.argv[1] == "start"):
start_acquisition(mythendet)
elif (sys.argv[1] == "frame"):
get_frame(mythendet)
elif (sys.argv[1] == "data"):
get_data(mythendet)
elif (sys.argv[1] == "flatfield"):
if (len(sys.argv)>2):
set_flatfield(mythendet, sys.argv[2])
else:
set_flatfield(mythendet, "")
elif (sys.argv[1] == "ratecorr" and len(sys.argv)>2):
set_ratecorr(mythendet, sys.argv[2])
elif (sys.argv[1] == "status"):
get_status(mythendet)
else:
usage()
except Exception, inst :
print "Failed with exception !"
print sys.exc_info()[0]
print type(inst) # the exception instance
print inst.args # arguments stored in .args