1525 lines
46 KiB
Python
1525 lines
46 KiB
Python
#==============================================================================
|
|
# Macroname: pixel.mac
|
|
# =========
|
|
#+
|
|
# $Date: 2009/05/28 10:10:56 $
|
|
# $Author: schlepuetz $
|
|
# $Source: /cvs/G/SPEC/local/X04SA/ES3/pixel.mac,v $
|
|
# $Revision: 1.11 $
|
|
# $Tag: $
|
|
#
|
|
# Description: Macro definitions to control a PILATUS pixel detector from
|
|
# SPEC.
|
|
#
|
|
# Note: This macro is based on the original ccd.mac, Rev. 1.16, by
|
|
# D. Maden and has been adapted to serve the pixel detector
|
|
# exclusively.
|
|
#
|
|
# Authors(s): D. Maden (DM), C. M. Schlepuetz (CS)
|
|
# Co-author(s): R. Herger (RH), P. R. Willmott (PW)
|
|
# Address: Surface Diffraction Station
|
|
# Materials Science Beamline X04SA
|
|
# Swiss Light Source (SLS)
|
|
# Paul Scherrer Institute
|
|
# CH - 5232 Villigen PSI
|
|
# Created: 2005/07/13
|
|
#
|
|
#-
|
|
# Chained macro definitions affected by this macro:
|
|
# -------------------------------------------------
|
|
# - user_precount
|
|
# - user_waitcount
|
|
# - user_ct
|
|
# - user_pre_recount
|
|
# - user_prescan_head
|
|
#
|
|
# Change Log:
|
|
# -----------
|
|
#
|
|
# 13.07.2005 (CS):
|
|
# - modified D. Maden's ccd.mac, removed all code related to the Hystar
|
|
# CCD camera, added pixon, pixoff & pixconnected().
|
|
# - All EPICS channels used in this macro are still the same as in ccd.mac
|
|
# This will have to be changed for the new EPICS interface of the
|
|
# PILATUS II pixel detector.
|
|
#
|
|
# 2005/11/07 (CS):
|
|
# - reduced sleep time in pixwait to 0.05 seconds.
|
|
#
|
|
# 2005/11/30 (CS):
|
|
# - fixed timing problem with pixlogwrite (now executed in user_count_end)
|
|
# - resolved issues with pixwait running into timeouts for long exposures.
|
|
#
|
|
# 2006/06/14 (CS):
|
|
# - fixed bug in pixUserCountEnd: COUNT_ID was set to value in EPICS channel
|
|
# PIX_FNUM_CHN, which is incremented immediately after an exposure such that
|
|
# COUNT_ID always reflected the image number of the next image to be taken.
|
|
# Now this value is decremented by 1 to give the number of the image taken
|
|
# last.
|
|
#
|
|
# 2006/12/13 (CS):
|
|
# - removed requirement that exposuretime must be an integer multiple of 0.001
|
|
# seconds in 'pixsetexpose'. This has become obsolete with PilatusII.
|
|
#
|
|
# 2009/05/28 (CS):
|
|
# - removed PilatusI support.
|
|
# Macro now only works with Pilatus 100k single modules.
|
|
# - added macro 'pixgetfilefmt' to check for the requested image file type
|
|
# (img,edf,tif), and set PIX_FILE_HEADER_LENGTH accordingly (0,1024,4096).
|
|
# - added call to 'pixgetfilefmt' in 'pixUserPrecount' and 'pixsetfmt'
|
|
#------------------------------------------------------------------------------
|
|
# Version for X04SA ISSD (ES3) at SLS
|
|
#
|
|
global PIXEL_MAC
|
|
#
|
|
PIXEL_MAC = DOFILE # Save the name of this macro file.
|
|
# (Used for the help function).
|
|
#
|
|
#+
|
|
#==============================================================================
|
|
# This macro file contains the following commands:
|
|
#-
|
|
#
|
|
#+
|
|
#------------------------------------------------------------------------------
|
|
# pixhelp - generate help text. This is obtained by displaying
|
|
# the file pix.txt, which should sit in the same
|
|
# directory as this file.
|
|
#-
|
|
|
|
# allow for misspelled help commands:
|
|
def helpPIX 'pixhelp'
|
|
def helpPix 'pixhelp'
|
|
def helppix 'pixhelp'
|
|
def pixHelp 'pixhelp'
|
|
|
|
def pixhelp '{
|
|
# =======
|
|
|
|
local file, ll
|
|
|
|
unix (sprintf ("dirname %s", PIXEL_MAC), _1)
|
|
ll = length (_1)
|
|
if (substr (_1, ll, 1) == "\n") _1 = substr (_1, 1, (ll - 1))
|
|
file = sprintf ("%s/pixel.txt", _1)
|
|
if (file_info (file, "-e")) {
|
|
unix (sprintf ("cat %s | less", file))
|
|
} else {
|
|
printf ("\n Macros available in file pix.mac ($$Revision: 1.11 $$):\n")
|
|
print " ======="
|
|
print ""
|
|
print " pixon - "
|
|
print " pixoff - "
|
|
print " pixconnected() - "
|
|
print " pixsetup - interactively configure the pixel"
|
|
print " detector package."
|
|
print " pixsetpath - interactively set directory for file storage."
|
|
print " pixsetfmt - interactively set file name template."
|
|
print " pixsetexpose <sec> - set exposure time."
|
|
print " pixshow - show the PIX settings."
|
|
print " pixsnap [<filename>] - take an image and write it to disk."
|
|
print " pixresnap - take an image and overwrite file."
|
|
print " pixwait - wait for the PIX sub-system to become \"Ready\"."
|
|
print " pixsw [<filename>] - call pixsnap and then pixwait."
|
|
print " pixlogon [<dirname>] - turn on the pix log."
|
|
print " pixlogoff - turn off the pix log."
|
|
print " pixlogshow - show info about the pix log."
|
|
print " pixlogwrite - write a pix log file."
|
|
}
|
|
}'
|
|
|
|
#+
|
|
#------------------------------------------------------------------------------
|
|
# pixon - turns on counting using the pixel detector instead
|
|
# of the point detector.
|
|
#-
|
|
|
|
def pixon '{
|
|
# =====
|
|
|
|
global BEAMLINE, ENDSTATION
|
|
|
|
global IMAGE_DEVICE, IMAGE_IS_ON
|
|
|
|
global PIX_IS_ON
|
|
|
|
global PIX_PATHA_CHN, PIX_PATHB_CHN
|
|
global PIX_FNAM_FMT_CHN, PIX_FNUM_CHN, PIX_FNAM_CHN
|
|
global PIX_EXPOSE_CHN
|
|
global PIX_STATUS_CHN, PIX_TRIG_CHN
|
|
|
|
global PIX_PATH, PIX_FILE_FMT, PIX_FNUM, PIX_EXPOSE, PIX_EXP_START_TIME
|
|
global PIX_LOG, PIX_LOG_CMND
|
|
global PIX_COLOR_DEPTH, PIX_FILE_HEADER_LENGTH
|
|
global PIX_THRESH1, PIX_THRESH2, PIX_THRESH3, PIX_THRESH4
|
|
global PIX_XDIM, PIX_YDIM
|
|
|
|
|
|
#--------------------------------
|
|
# set the global status variables
|
|
# and report status to the user
|
|
|
|
if(IMAGE_DEVICE!=""){
|
|
if(IMAGE_DEVICE=="PILATUS"){
|
|
if(PIX_IS_ON==1){
|
|
printf("The PILATUS pixel detector was and still is enabled.\n")
|
|
} else{
|
|
printf("The PILATUS pixel detector has been enabled.\n")
|
|
PIX_IS_ON = 1
|
|
}
|
|
} else{
|
|
printf("The following image device is currently connected: %s\n",\\
|
|
IMAGE_DEVICE)
|
|
printf("Please disable this device before calling \'pixon\' again.\n")
|
|
exit
|
|
}
|
|
} else{
|
|
if(PIX_IS_ON==1){
|
|
IMAGE_DEVICE="PILATUS"
|
|
printf("The PILATUS pixel detector has been enabled.\n")
|
|
} else{
|
|
IMAGE_DEVICE="PILATUS"
|
|
PIX_IS_ON = 1
|
|
printf("The PILATUS pixel detector has been enabled.\n")
|
|
}
|
|
}
|
|
|
|
#----------------------------------------
|
|
# deactivate the Cyberstar point detector
|
|
|
|
cyberOff
|
|
|
|
#-------------------------------------------
|
|
# run the setup macro for the pixel detector
|
|
# if it has not been executed
|
|
|
|
if (PIX_STATUS_CHN == 0){
|
|
pixsetup
|
|
}
|
|
|
|
#-------------------------------------------
|
|
# define necessary chained macro definitions
|
|
# and add them to their respective
|
|
# destination macros.
|
|
|
|
#------------------
|
|
def pixUserPrecount \'
|
|
# ===============
|
|
|
|
global PIX_IS_ON
|
|
|
|
if ((PIX_IS_ON) && (pixconnected())) {
|
|
pixsetexpose COUNT_TIME
|
|
pixgetfilefmt
|
|
pixsnap
|
|
}
|
|
\'
|
|
# add pixUserPrecount to the end of user_precount
|
|
cdef("user_precount","pixUserPrecount; ","pix_user_precount_key",0x20)
|
|
|
|
#-------------------
|
|
def pixUserWaitcount \'
|
|
# ================
|
|
|
|
global PIX_IS_ON
|
|
|
|
if (PIX_IS_ON) {
|
|
pixwait
|
|
}
|
|
\'
|
|
# add to user_waitcount
|
|
cdef("user_waitcount","pixUserWaitcount; ","pix_user_waitcount_key")
|
|
|
|
|
|
#------------
|
|
def pixUserCt \'
|
|
# =========
|
|
|
|
global PIX_IS_ON
|
|
|
|
if ((PIX_IS_ON) && (pixconnected())) {
|
|
printf("image written to: /sls/X04SA/data/x04sa/ES3/pixel/images/%s%s%s\n",\\
|
|
epics_get(PIX_PATHA_CHN),\\
|
|
epics_get(PIX_PATHB_CHN),\\
|
|
epics_get(PIX_FNAM_CHN))
|
|
}
|
|
\'
|
|
# add to user_ct
|
|
cdef("user_ct","pixUserCt; ","pix_user_ct_key",0x20)
|
|
|
|
#------------------
|
|
def pixUserCountEnd \'
|
|
# ===============
|
|
|
|
global PIX_IS_ON, PIX_LOG, IMAGE_FILENAME, COUNT_ID
|
|
|
|
# update the IMAGE_FILENAME and COUNT_ID variables
|
|
if ((PIX_IS_ON) && (pixconnected())) {
|
|
IMAGE_FILENAME = sprintf("/sls/X04SA/data/x04sa/ES3/pixel/images/%s%s%s",\\
|
|
epics_get(PIX_PATHA_CHN),\\
|
|
epics_get(PIX_PATHB_CHN),\\
|
|
epics_get(PIX_FNAM_CHN))
|
|
COUNT_ID = epics_get(PIX_FNUM_CHN)-1
|
|
}
|
|
|
|
# write the image log if logging is enabled
|
|
if (PIX_IS_ON && (PIX_LOG != "")){
|
|
pixlogwrite
|
|
}
|
|
\'
|
|
# add to user_count_end
|
|
cdef("user_count_end","pixUserCountEnd; ","pix_user_count_end_key")
|
|
|
|
#--------------------
|
|
def pixUserPreRecount \'
|
|
# =================
|
|
|
|
pixUndo
|
|
|
|
\'
|
|
# add pixUserPreRecount to user_pre_recount
|
|
cdef("user_pre_recount","pixUserPreRecount; ","pix_user_pre_recount_key")
|
|
|
|
#-----------------
|
|
def pixPrescanHead \'
|
|
# ==============
|
|
|
|
if (PIX_IS_ON) {
|
|
printf("\nfirst image will be: /sls/X04SA/data/x04sa/ES3/pixel/images/%s%s%s\n\n",\\
|
|
epics_get(PIX_PATHA_CHN),\\
|
|
epics_get(PIX_PATHB_CHN),\\
|
|
sprintf(epics_get("X04SA-ES3-CCD:FNAM_FMT"),\\
|
|
epics_get("X04SA-ES3-CCD:FNUM")+1))
|
|
}
|
|
\'
|
|
# add to user_prescan_head
|
|
cdef("user_prescan_head","pixPrescanHead; ","pix_prescan_head_key",0x20)
|
|
|
|
#-----------------------------------
|
|
# Enable the image analysis routines
|
|
|
|
imageInit # make sure all global variables are defined
|
|
IMAGE_THRESH1 = PIX_THRESH1
|
|
IMAGE_THRESH2 = PIX_THRESH2
|
|
IMAGE_THRESH3 = PIX_THRESH3
|
|
IMAGE_THRESH4 = PIX_THRESH4
|
|
IMAGE_HEADER_LENGTH = PIX_FILE_HEADER_LENGTH
|
|
IMAGE_COLOR_DEPTH = PIX_COLOR_DEPTH
|
|
IMAGE_XDIM = PIX_XDIM
|
|
IMAGE_YDIM = PIX_YDIM
|
|
imageOn # turn on image analysis support
|
|
|
|
}'
|
|
|
|
#+
|
|
# -----------------------------------------------------------------------------
|
|
# pixoff - turns off the pixel detector as counting device and
|
|
# enables the point detector again.
|
|
#-
|
|
|
|
def pixoff '{
|
|
# ======
|
|
global BEAMLINE, ENDSTATION
|
|
|
|
global PIX_IS_ON
|
|
|
|
global PIX_PATHA_CHN, PIX_PATHB_CHN
|
|
global PIX_FNAM_FMT_CHN, PIX_FNUM_CHN, PIX_FNAM_CHN
|
|
global PIX_EXPOSE_CHN
|
|
global PIX_STATUS_CHN, PIX_TRIG_CHN
|
|
|
|
global PIX_PATH, PIX_FILE_FMT, PIX_FNUM, PIX_EXPOSE, PIX_EXP_START_TIME
|
|
global PIX_LOG, PIX_LOG_CMND
|
|
global PIX_COLOR_DEPTH, PIX_FILE_HEADER_LENGTH
|
|
global PIX_THRESH1, PIX_THRESH2, PIX_THRESH3, PIX_THRESH4
|
|
global PIX_XDIM, PIX_YDIM
|
|
|
|
# remove from user_precount
|
|
cdef("user_precount","","pix_user_precount_key","delete")
|
|
|
|
# remove from user_waitcount
|
|
cdef("user_waitcount","","pix_user_waitcount_key","delete")
|
|
|
|
# remove from user_prescan_head
|
|
cdef("user_prescan_head","","pix_prescan_head_key","delete")
|
|
|
|
# remove pixUserCountEnd from user_count_end
|
|
cdef("user_count_end","","pix_user_count_end_key","delete")
|
|
|
|
# remove from user_ct
|
|
cdef("user_ct","","pix_user_ct_key","delete")
|
|
|
|
# remove pixUserPreRecount from user_pre_recount
|
|
cdef("user_pre_recount","","pix_user_pre_recount_key",\\
|
|
"delete")
|
|
|
|
#-----------------------
|
|
# turn off imaging tools
|
|
imageOff
|
|
|
|
#-----------------------
|
|
# activate cyberstar point detector
|
|
cyberOn
|
|
|
|
#--------------------------------
|
|
# set the global status variables
|
|
# and report status to the user
|
|
|
|
if (PIX_IS_ON != 0) {
|
|
PIX_IS_ON = 0
|
|
printf("The pixel detector has been disbled.\n")
|
|
} else {
|
|
printf("The pixel detector was and still is disabled.\n")
|
|
}
|
|
|
|
}'
|
|
|
|
#+
|
|
# -----------------------------------------------------------------------------
|
|
# pixconnected() - checks whether pixel detector is properly connected
|
|
# with SPEC via EPICS.
|
|
# Returns 1 if the pixel is connected, 0 otherwise.
|
|
#-
|
|
|
|
def pixconnected() '{
|
|
# ==============
|
|
global BEAMLINE, ENDSTATION
|
|
|
|
global PIX_IS_ON
|
|
|
|
global PIX_PATHA_CHN, PIX_PATHB_CHN
|
|
global PIX_FNAM_FMT_CHN, PIX_FNUM_CHN, PIX_FNAM_CHN
|
|
global PIX_EXPOSE_CHN
|
|
global PIX_STATUS_CHN, PIX_TRIG_CHN
|
|
|
|
global PIX_PATH, PIX_FILE_FMT, PIX_FNUM, PIX_EXPOSE, PIX_EXP_START_TIME
|
|
global PIX_LOG, PIX_LOG_CMND
|
|
global PIX_COLOR_DEPTH, PIX_FILE_HEADER_LENGTH
|
|
global PIX_THRESH1, PIX_THRESH2, PIX_THRESH3, PIX_THRESH4
|
|
global PIX_XDIM, PIX_YDIM
|
|
|
|
local isConnected
|
|
|
|
isConnected = 1
|
|
if (epics_get("X04SA-ES3-CCD:STAT1") != "Connected") {
|
|
eprint "The Pixel detector is not connected to Epics/Spec."
|
|
eprint "Please disconnect in tvx and connect via the CCD/Pixel Epics widget."
|
|
isConnected = 0
|
|
} else {
|
|
if (epics_get("X04SA-ES3-CCD:ERRCODE") != 0) {
|
|
eprint "The pixel detector returned an error. It may not be properly"
|
|
eprint "connected. Please disconnect in tvx and disconnect and"
|
|
eprint "re-connect with the CCD/Pixel Epics widget."
|
|
isConnected = 0
|
|
}
|
|
}
|
|
return (isConnected)
|
|
}'
|
|
|
|
#+
|
|
#------------------------------------------------------------------------------
|
|
# pixsetup - setup the pixel detector.
|
|
#
|
|
# Usage : pixsetup [<pathname>]
|
|
# then answer the questions.
|
|
# The optional <pathname> specifies the directory where
|
|
# the pixel detector images will be stored. If <pathname>
|
|
# is not supplied, the user will be prompted for a path.
|
|
#-
|
|
|
|
def pixsetup '{
|
|
# ========
|
|
|
|
global BEAMLINE, ENDSTATION
|
|
|
|
global PIX_IS_ON, PIX_TYPE
|
|
|
|
global PIX_PATHA_CHN, PIX_PATHB_CHN
|
|
global PIX_FNAM_FMT_CHN, PIX_FNUM_CHN, PIX_FNAM_CHN
|
|
global PIX_EXPOSE_CHN
|
|
global PIX_STATUS_CHN, PIX_TRIG_CHN
|
|
|
|
global PIX_PATH, PIX_FILE_FMT, PIX_FNUM, PIX_EXPOSE, PIX_EXP_START_TIME
|
|
global PIX_LOG, PIX_LOG_CMND
|
|
global PIX_COLOR_DEPTH, PIX_FILE_HEADER_LENGTH
|
|
global PIX_THRESH1, PIX_THRESH2, PIX_THRESH3, PIX_THRESH4
|
|
global PIX_XDIM, PIX_YDIM
|
|
|
|
local idx, my_type, my_file_path, my_file_fmt, my_path, my_pathA, my_pathB
|
|
local my_fnum, my_exp, my_gain
|
|
|
|
PIX_PATHA_CHN = sprintf ("%s-%s-CCD:PATHa", BEAMLINE, ENDSTATION)
|
|
PIX_PATHB_CHN = sprintf ("%s-%s-CCD:PATHb", BEAMLINE, ENDSTATION)
|
|
PIX_FNAM_FMT_CHN = sprintf ("%s-%s-CCD:FNAM_FMT", BEAMLINE, ENDSTATION)
|
|
PIX_FNUM_CHN = sprintf ("%s-%s-CCD:FNUM", BEAMLINE, ENDSTATION)
|
|
PIX_FNAM_CHN = sprintf ("%s-%s-CCD:FNAM", BEAMLINE, ENDSTATION)
|
|
PIX_EXPOSE_CHN = sprintf ("%s-%s-CCD:EXPOSE", BEAMLINE, ENDSTATION)
|
|
PIX_STATUS_CHN = sprintf ("%s-%s-CCD:STATUS", BEAMLINE, ENDSTATION)
|
|
PIX_TRIG_CHN = sprintf ("%s-%s-CCD:TRIG", BEAMLINE, ENDSTATION)
|
|
|
|
if(!(($#==1) || ($#==0))){
|
|
eprint "Wrong number or illegal arguments in \'pixsetup\'"
|
|
eprint "Usage:"
|
|
eprint " pixsetup [<pathname>]"
|
|
eprint ""
|
|
eprint "The <pathname> argument specifies the directory where the pixel"
|
|
eprint "detector images are stored and is optional. If none is supplied,"
|
|
eprint "the user will be prompted for the path."
|
|
exit
|
|
}
|
|
|
|
#-------------------------------------------------------------------
|
|
# set the four threshold values for the acceptable, good, optimum,
|
|
# and maximum number of counts according to the pixel detector model.
|
|
# If Used in combination with automatic filter and exposure time settings,
|
|
# (auto-level > 0, see auto.mac), these threshold values are used to deter-
|
|
# mine the action taken after a count command.
|
|
# The four threshold levels are used in the following way (MaxCount
|
|
# represents the highest count value within the defined region of interest,
|
|
# see image.mac):
|
|
# 0 <= MaxCount < Thresh1 : counts are very low -> increase intensity
|
|
# if possible by increasing the filter
|
|
# transmission or the exposure time, give up
|
|
# otherwise.
|
|
# Thresh1 <= MaxCount < Thresh2 : counts are acceptable -> increase filter
|
|
# transmission if possible but keep current
|
|
# exposure time, accept otherwise.
|
|
# Thresh2 <= MaxCount < Thresh3 : counts are good -> try to decrease exposure
|
|
# time first, then increase filter
|
|
# transmission if possible, accept otherwise.
|
|
# Thresh3 <= MaxCount < Thresh4 : optimal counts -> no action taken.
|
|
# Thresh4 <= MaxCount : counts are too high -> intensity is reduced
|
|
|
|
# set global variables for the Pilatus 100k single module device
|
|
PIX_TYPE = "PilatusII"
|
|
PIX_FILE_HEADER_LENGTH = 0
|
|
PIX_COLOR_DEPTH = 32
|
|
PIX_XDIM = 487
|
|
PIX_YDIM = 195
|
|
PIX_THRESH1 = 40
|
|
PIX_THRESH2 = 500
|
|
PIX_THRESH3 = 8000
|
|
PIX_THRESH4 = 100000
|
|
|
|
|
|
#----------------------------------------------
|
|
# set up the pixel detector file and path names
|
|
|
|
if($#==1){
|
|
pixsetpath $1
|
|
} else{
|
|
pixsetpath
|
|
}
|
|
|
|
pixsetfmt
|
|
# Get the user to check the frame number.
|
|
#
|
|
my_fnum = epics_get (PIX_FNUM_CHN)
|
|
my_fnum = getval ("Next frame number", (my_fnum + 1))
|
|
my_fnum = (my_fnum >= 1) ? (my_fnum - 1) : 0
|
|
# Get the user to check the exposure time.
|
|
#
|
|
my_exp = (epics_get(PIX_EXPOSE_CHN))/1000
|
|
epics_put (PIX_FNUM_CHN, my_fnum)
|
|
|
|
#---------------------------------
|
|
# define the initial exposure time
|
|
|
|
my_exp = getval ("Exposure time in sec", my_exp)
|
|
my_exp = (my_exp < 0.000005) ? 0.000005 : my_exp
|
|
epics_put (PIX_EXPOSE_CHN, my_exp*1000)
|
|
|
|
PIX_EXP_START_TIME = time() - 100000 # initialize PIX_EXP_START_TIME (to a
|
|
# long time ago!)
|
|
|
|
pixshow # display pixel detector information
|
|
}'
|
|
|
|
#+
|
|
#------------------------------------------------------------------------------
|
|
# pixsetpath - specify the path for pixel detector image files.
|
|
#
|
|
# Usage : pixsetpath [<pathname>]
|
|
# if the optional <pathname> is not specified the user is
|
|
# prompted for the path.
|
|
#-
|
|
|
|
def pixsetpath '{
|
|
# ==========
|
|
|
|
global BEAMLINE, ENDSTATION
|
|
|
|
global PIX_IS_ON
|
|
|
|
global PIX_PATHA_CHN, PIX_PATHB_CHN
|
|
global PIX_FNAM_FMT_CHN, PIX_FNUM_CHN, PIX_FNAM_CHN
|
|
global PIX_EXPOSE_CHN
|
|
global PIX_STATUS_CHN, PIX_TRIG_CHN
|
|
|
|
global PIX_PATH, PIX_FILE_FMT, PIX_FNUM, PIX_EXPOSE, PIX_EXP_START_TIME
|
|
global PIX_LOG, PIX_LOG_CMND
|
|
global PIX_COLOR_DEPTH, PIX_FILE_HEADER_LENGTH
|
|
global PIX_THRESH1, PIX_THRESH2, PIX_THRESH3, PIX_THRESH4
|
|
global PIX_XDIM, PIX_YDIM
|
|
|
|
local my_file_path, my_pathA, my_pathB, ll, i
|
|
|
|
if ((whatis ("PIX_TYPE") & 0x08000000) != 0) {
|
|
printf ("\n\aThe pixel detector software has not been initialised!\n")
|
|
printf ( "Use the \"pixsetup\" command.\n")
|
|
exit
|
|
}
|
|
if($# == 1){
|
|
my_file_path = "$1"
|
|
_1 = my_file_path
|
|
_2 = ""
|
|
} else if ($# == 0){
|
|
# Get the bits of the file name
|
|
# from the EPICS channels
|
|
_1 = epics_get (PIX_PATHA_CHN)
|
|
_2 = epics_get (PIX_PATHB_CHN)
|
|
my_file_path = sprintf ("%s%s", _1, _2)
|
|
} else{
|
|
eprint "\n\aWrong number or illegal arguments in \'pixsetpath\'\n"
|
|
eprint "Usage:"
|
|
eprint " pixsetpath [<pathname>]"
|
|
eprint ""
|
|
eprint "The <pathname> argument is optional, if none is supplied the user"
|
|
eprint "will be prompted for the path."
|
|
exit
|
|
}
|
|
|
|
if (index (my_file_path, "\\") != 0) {
|
|
# There is a backslash in the path, so it is probably
|
|
# a windows filename. Switch to default linux path.
|
|
my_file_path = "/home/pixel/sls8x2/images/"
|
|
epics_put (PIX_FNAM_FMT_CHN, "px%05d.img")
|
|
} else {
|
|
ll = length (_1)
|
|
if ((ll > 0) && (substr (_1, ll, 1) != "/")) {
|
|
_1 = sprintf ("%s%s", _1, "/")
|
|
}
|
|
_1 = sprintf ("%s%s", _1, _2)
|
|
ll = length (_1)
|
|
if ((ll > 0) && (substr (_1, ll, 1) != "/")) {
|
|
_1 = sprintf ("%s%s", _1, "/")
|
|
}
|
|
my_file_path = _1
|
|
}
|
|
|
|
printf ("Image file directory is: \"%s\"\n", my_file_path)
|
|
while (!yesno ("Is this OK", 1)) {
|
|
_1 = input ("Specify directory> ")
|
|
if (length (_1) > 70) {
|
|
print "\aToo long."
|
|
continue
|
|
}
|
|
ll = length (_1)
|
|
if ((ll > 0) && (substr (_1, ll, 1) != "/")) {
|
|
_1 = sprintf ("%s%s", _1, "/")
|
|
}
|
|
|
|
my_file_path = _1
|
|
printf ("Image file directory is: \"%s\"\n", my_file_path)
|
|
}
|
|
if (length (my_file_path) > 37) {
|
|
# The string must be split. Split it
|
|
# at a "/" or "\"
|
|
splitChar = "/"
|
|
i = length (my_file_path)
|
|
while (i >= 0) {
|
|
if ((substr (my_file_path, i, 1) == splitChar) && \
|
|
(i <= 37)) {
|
|
break
|
|
}
|
|
i--
|
|
}
|
|
my_pathA = substr (my_file_path, 1, i)
|
|
my_pathB = substr (my_file_path, (i + 1))
|
|
if ((length (my_pathA) > 37) || \
|
|
(length (my_pathB) > 37)) {
|
|
print "Sorry, path is too long and cannot be legally split."
|
|
unglobal PIX_IS_ON
|
|
exit
|
|
}
|
|
} else {
|
|
my_pathA = my_file_path
|
|
my_pathB = ""
|
|
}
|
|
|
|
epics_put (PIX_PATHA_CHN, my_pathA)
|
|
epics_put (PIX_PATHB_CHN, my_pathB)
|
|
}'
|
|
|
|
#+
|
|
#------------------------------------------------------------------------------
|
|
# pixsetfmt - specify the name template for image files.
|
|
#
|
|
# Usage : pixsetfmt
|
|
# then answer the questions.
|
|
#-
|
|
|
|
def pixsetfmt '{
|
|
# =========
|
|
|
|
global BEAMLINE, ENDSTATION
|
|
|
|
global PIX_IS_ON
|
|
|
|
global PIX_PATHA_CHN, PIX_PATHB_CHN
|
|
global PIX_FNAM_FMT_CHN, PIX_FNUM_CHN, PIX_FNAM_CHN
|
|
global PIX_EXPOSE_CHN
|
|
global PIX_STATUS_CHN, PIX_TRIG_CHN
|
|
|
|
global PIX_PATH, PIX_FILE_FMT, PIX_FNUM, PIX_EXPOSE, PIX_EXP_START_TIME
|
|
global PIX_LOG, PIX_LOG_CMND
|
|
global PIX_COLOR_DEPTH, PIX_FILE_HEADER_LENGTH
|
|
global PIX_THRESH1, PIX_THRESH2, PIX_THRESH3, PIX_THRESH4
|
|
global PIX_XDIM, PIX_YDIM
|
|
|
|
local ll, my_fmt
|
|
|
|
if ((whatis ("PIX_TYPE") & 0x08000000) != 0) {
|
|
printf ("\n\aThe pixel detector software has not been initialised!\n")
|
|
printf ( "Use the \"pixsetup\" command.\n")
|
|
exit
|
|
}
|
|
# Get the current file name template
|
|
#
|
|
_1 = epics_get (PIX_FNAM_FMT_CHN)
|
|
ll = length (_1)
|
|
if (ll == 0) {
|
|
_1 = "px%05d.img"
|
|
ll = length (_1)
|
|
}
|
|
my_fmt = _1
|
|
if (pixCheckFileFmt (my_fmt, 0) != 0) {
|
|
my_fmt = "px%05d.img"
|
|
}
|
|
|
|
printf ("File name template is: \"%s\"\n", my_fmt)
|
|
while (!yesno ("Is this OK", 1)) {
|
|
my_fmt = input ("Specify file name template> ")
|
|
if (length (my_fmt) > 30) {
|
|
print "\aToo long."
|
|
continue
|
|
}
|
|
if (pixCheckFileFmt (my_fmt, 1) != 0) {
|
|
my_fmt = "px%05d.img"
|
|
print "Template has been set to", my_fmt
|
|
}
|
|
printf ("File name template is: \"%s\"\n", my_fmt)
|
|
}
|
|
|
|
epics_put (PIX_FNAM_FMT_CHN, my_fmt)
|
|
|
|
# retrieve the image file format from the name template
|
|
pixgetfilefmt
|
|
|
|
}'
|
|
|
|
|
|
#+
|
|
#------------------------------------------------------------------------------
|
|
# pixsetexpose - specify the exposure time in secons [s].
|
|
#
|
|
# Usage : pixsetexpose <sec>
|
|
#-
|
|
|
|
def pixsetexpose '{
|
|
# ============
|
|
|
|
global BEAMLINE, ENDSTATION
|
|
|
|
global COUNT_TIME
|
|
|
|
global PIX_IS_ON
|
|
|
|
global PIX_PATHA_CHN, PIX_PATHB_CHN
|
|
global PIX_FNAM_FMT_CHN, PIX_FNUM_CHN, PIX_FNAM_CHN
|
|
global PIX_EXPOSE_CHN
|
|
global PIX_STATUS_CHN, PIX_TRIG_CHN
|
|
|
|
global PIX_PATH, PIX_FILE_FMT, PIX_FNUM, PIX_EXPOSE, PIX_EXP_START_TIME
|
|
global PIX_LOG, PIX_LOG_CMND
|
|
global PIX_COLOR_DEPTH, PIX_FILE_HEADER_LENGTH
|
|
global PIX_THRESH1, PIX_THRESH2, PIX_THRESH3, PIX_THRESH4
|
|
global PIX_XDIM, PIX_YDIM
|
|
|
|
local ll, my_fmt
|
|
|
|
if ((whatis ("PIX_TYPE") & 0x08000000) != 0) {
|
|
printf ("\n\aThe pixel detector software has not been initialised!\n")
|
|
printf ( "Use the \"pixsetup\" command.\n")
|
|
exit
|
|
}
|
|
if ($# != 1) {
|
|
printf ("\aUsage: pixsetexpose <sec>\n")
|
|
exit
|
|
}
|
|
|
|
if ($1 <= 0) {
|
|
printf ("\aExposure time must be greater than zero! Aborting...\n")
|
|
exit
|
|
}
|
|
|
|
# convert to ms for the EPICS Pixel widget.
|
|
_1 = $1*1000
|
|
|
|
epics_put (PIX_EXPOSE_CHN, _1)
|
|
COUNT_TIME = $1
|
|
|
|
}'
|
|
|
|
#+
|
|
#------------------------------------------------------------------------------
|
|
# pixshow - show the current pixel detector settings
|
|
#
|
|
# Usage : pixshow
|
|
#-
|
|
|
|
def pixShow 'pixshow'
|
|
|
|
def pixshow '{
|
|
# =======
|
|
|
|
global BEAMLINE, ENDSTATION
|
|
|
|
global PIX_IS_ON
|
|
|
|
global PIX_PATHA_CHN, PIX_PATHB_CHN
|
|
global PIX_FNAM_FMT_CHN, PIX_FNUM_CHN, PIX_FNAM_CHN
|
|
global PIX_EXPOSE_CHN
|
|
global PIX_STATUS_CHN, PIX_TRIG_CHN
|
|
|
|
global PIX_PATH, PIX_FILE_FMT, PIX_FNUM, PIX_EXPOSE, PIX_EXP_START_TIME
|
|
global PIX_LOG, PIX_LOG_CMND
|
|
global PIX_COLOR_DEPTH, PIX_FILE_HEADER_LENGTH
|
|
global PIX_THRESH1, PIX_THRESH2, PIX_THRESH3, PIX_THRESH4
|
|
global PIX_XDIM, PIX_YDIM
|
|
|
|
local fnam, pathA, pathB, idx, i
|
|
|
|
if ((whatis ("PIX_TYPE") & 0x08000000) != 0) {
|
|
printf ("\n\aThe pixel detector software has not been initialised!\n")
|
|
printf ( "Use the \"pixsetup\" command.\n")
|
|
exit
|
|
}
|
|
|
|
if(PIX_IS_ON==1){
|
|
printf("\nThe PILATUS pixel detector is currently enabled.\n")
|
|
printf("To disable it type \'pixoff\'.\n")
|
|
} else{
|
|
printf("\nThe PILATUS pixel detector is currently disabled.\n")
|
|
printf("To enable it type\'pixon\'.\n")
|
|
}
|
|
|
|
pathA = epics_get (PIX_PATHA_CHN)
|
|
pathB = epics_get (PIX_PATHB_CHN)
|
|
PIX_PATH = sprintf ("%s%s", pathA, pathB)
|
|
|
|
PIX_FILE_FMT = epics_get (PIX_FNAM_FMT_CHN)
|
|
|
|
printf("\nThe current pixel detector settings are:\n")
|
|
|
|
if (index (PIX_FILE_FMT, "%") != 0) {
|
|
PIX_FNUM = epics_get (PIX_FNUM_CHN)
|
|
printf (" The frame number = %d\n", PIX_FNUM)
|
|
printf (" The file path is: %s\n", PIX_PATH)
|
|
printf (" The file template is: %s\n", PIX_FILE_FMT)
|
|
fnam = epics_get (PIX_FNAM_CHN)
|
|
printf (" The last file name was: %s\n", fnam)
|
|
fnam = sprintf (PIX_FILE_FMT, (PIX_FNUM + 1))
|
|
printf (" The next file name will be: %s\n", fnam)
|
|
} else{
|
|
fnam = epics_get (PIX_FNAM_CHN)
|
|
printf (" The last file name was: %s\n", fnam)
|
|
printf (" The next file name will be: %s\n", PIX_FILE_FMT)
|
|
}
|
|
pixCheckFileFmt (PIX_FILE_FMT, 1)
|
|
|
|
PIX_EXPOSE = epics_get (PIX_EXPOSE_CHN)
|
|
printf(" Exposure time = %5d sec\n", PIX_EXPOSE/1000)
|
|
|
|
printf(" Image dimensions: %d x %d pixels (total = %d)\n", \\
|
|
PIX_XDIM, PIX_YDIM, PIX_XDIM*PIX_YDIM)
|
|
printf(" Threshold values: Thresh1 = %d, Thresh2 = %d, Thresh3 = %d, Thresh4 = %d\n",\\
|
|
PIX_THRESH1,PIX_THRESH2,PIX_THRESH3,PIX_THRESH4)
|
|
|
|
if(PIX_IS_ON==1){
|
|
if(IMAGE_DEVICE==""){
|
|
printf("No imaging device is active.\n")
|
|
printf("Type \'pixon\' to make the PILATUS pixel detector the active ")
|
|
printf("imaging device.\n")
|
|
} else if(IMAGE_DEVICE!="PILATUS"){
|
|
printf("\nThe current imaging device is %s\n", IMAGE_DEVICE)
|
|
printf("To make the PILATUS pixel detector the active imaging device, ")
|
|
printf("disable the %s",IMAGE_DEVICE)
|
|
printf("imaging device and type \'pixon\'.\n")
|
|
}
|
|
}
|
|
|
|
if(IMAGE_IS_ON==1){
|
|
imageShow
|
|
} else{
|
|
printf("\nImage analysis support is currently disabled.\n")
|
|
printf("To enable it type \'imageOn\'.\n")
|
|
}
|
|
|
|
}'
|
|
|
|
#+
|
|
#------------------------------------------------------------------------------
|
|
# pixsnap - get the PIX to take an image and write it to disk.
|
|
#
|
|
# Usage : pixsnap [<filename>]
|
|
#
|
|
# If a filename is specified, this will be used to specify the
|
|
# file which is to be written. Otherwise, the frame number will
|
|
# be incremented and a filename will be generated from the
|
|
# file-name template.
|
|
#
|
|
# If <filename> is specified, it is assumed to be relative to
|
|
# the file-name path which has been defined via pixsetpath.
|
|
#-
|
|
|
|
def pixsnap '{
|
|
# =======
|
|
|
|
global BEAMLINE, ENDSTATION
|
|
|
|
global PIX_IS_ON
|
|
|
|
global PIX_PATHA_CHN, PIX_PATHB_CHN
|
|
global PIX_FNAM_FMT_CHN, PIX_FNUM_CHN, PIX_FNAM_CHN
|
|
global PIX_EXPOSE_CHN
|
|
global PIX_STATUS_CHN, PIX_TRIG_CHN
|
|
|
|
global PIX_PATH, PIX_FILE_FMT, PIX_FNUM, PIX_EXPOSE, PIX_EXP_START_TIME
|
|
global PIX_LOG, PIX_LOG_CMND
|
|
global PIX_COLOR_DEPTH, PIX_FILE_HEADER_LENGTH
|
|
global PIX_THRESH1, PIX_THRESH2, PIX_THRESH3, PIX_THRESH4
|
|
global PIX_XDIM, PIX_YDIM
|
|
|
|
local stat
|
|
|
|
if (($# != 0) && ($# != 1)) {
|
|
print "\n\a Usage:"
|
|
print " pixsnap [<filename>]"
|
|
exit
|
|
}
|
|
|
|
if ((whatis ("PIX_IS_ON") & 0x08000000) != 0) {
|
|
printf ("\n\aThe pixel detector software has not been initialised!\n")
|
|
printf ( "Use the \"pixsetup\" command.\n")
|
|
exit
|
|
} else if (!PIX_IS_ON){
|
|
printf ("\aThe pixel detector is currently not enabled. Use the \"pixon\"")
|
|
printf ("command to enable it. Aborting...")
|
|
exit
|
|
} else{
|
|
|
|
pixwait # Wait until pixel detector is ready
|
|
|
|
if ($# == 0) {
|
|
PIX_EXPOSE = epics_get(PIX_EXPOSE_CHN)
|
|
epics_put (PIX_TRIG_CHN, "Inc+Sn+Wr")
|
|
PIX_EXP_START_TIME = time()
|
|
} else {
|
|
PIX_EXPOSE = epics_get(PIX_EXPOSE_CHN)
|
|
epics_put (PIX_FNAM_CHN, "$1")
|
|
epics_put (PIX_TRIG_CHN, "Snap")
|
|
PIX_EXP_START_TIME = time()
|
|
pixwait
|
|
epics_put (PIX_TRIG_CHN, "Write")
|
|
cmnd = sprintf ("pixlogwrite %s.pxl", fnam)
|
|
eval (cmnd)
|
|
}
|
|
}
|
|
}'
|
|
|
|
#+
|
|
#------------------------------------------------------------------------------
|
|
# pixUndo - decrement the pixel detector image number by 1 to repeat
|
|
# the exposure and overwrite the last file.
|
|
#
|
|
# Usage : pixUndo
|
|
#-
|
|
|
|
def pixUndo '{
|
|
# =======
|
|
|
|
global BEAMLINE, ENDSTATION
|
|
|
|
global PIX_IS_ON
|
|
|
|
global PIX_PATHA_CHN, PIX_PATHB_CHN
|
|
global PIX_FNAM_FMT_CHN, PIX_FNUM_CHN, PIX_FNAM_CHN
|
|
global PIX_EXPOSE_CHN
|
|
global PIX_STATUS_CHN, PIX_TRIG_CHN
|
|
|
|
global PIX_PATH, PIX_FILE_FMT, PIX_FNUM, PIX_EXPOSE, PIX_EXP_START_TIME
|
|
global PIX_LOG, PIX_LOG_CMND
|
|
global PIX_COLOR_DEPTH, PIX_FILE_HEADER_LENGTH
|
|
global PIX_THRESH1, PIX_THRESH2, PIX_THRESH3, PIX_THRESH4
|
|
global PIX_XDIM, PIX_YDIM
|
|
|
|
local imageFileNumber
|
|
|
|
if ($# != 0) {
|
|
printf ("\aThere should be no arguments.\n")
|
|
exit
|
|
}
|
|
|
|
if ((whatis ("PIX_TYPE") & 0x08000000) != 0) {
|
|
printf ("\n\aThe pixel detector software has not been initialised!\n")
|
|
printf ( "Use the \"pixsetup\" command.\n")
|
|
exit
|
|
} else if (!PIX_IS_ON){
|
|
printf ("\aThe pixel detector is currently not enabled. Use the \"pixon\"")
|
|
printf ("command to enable it. Aborting...")
|
|
exit
|
|
} else{
|
|
# get the file number of the next file and decrease it by 1
|
|
imageFileNumber = epics_get(PIX_FNUM_CHN)
|
|
imageFileNumber = imageFileNumber-1
|
|
epics_put(PIX_FNUM_CHN,imageFileNumber)
|
|
printf("File number decreased.\n")
|
|
}
|
|
}'
|
|
|
|
#+
|
|
#------------------------------------------------------------------------------
|
|
# pixresnap - get the pixel detector to take an image and overwrite the
|
|
# previous disk file.
|
|
#
|
|
# Usage : pixresnap
|
|
#-
|
|
|
|
def pixresnap '{
|
|
# =========
|
|
|
|
global BEAMLINE, ENDSTATION
|
|
|
|
global PIX_IS_ON
|
|
|
|
global PIX_PATHA_CHN, PIX_PATHB_CHN
|
|
global PIX_FNAM_FMT_CHN, PIX_FNUM_CHN, PIX_FNAM_CHN
|
|
global PIX_EXPOSE_CHN
|
|
global PIX_STATUS_CHN, PIX_TRIG_CHN
|
|
|
|
global PIX_PATH, PIX_FILE_FMT, PIX_FNUM, PIX_EXPOSE, PIX_EXP_START_TIME
|
|
global PIX_LOG, PIX_LOG_CMND
|
|
global PIX_COLOR_DEPTH, PIX_FILE_HEADER_LENGTH
|
|
global PIX_THRESH1, PIX_THRESH2, PIX_THRESH3, PIX_THRESH4
|
|
global PIX_XDIM, PIX_YDIM
|
|
|
|
local fnam, cmnd
|
|
|
|
if ($# != 0) {
|
|
printf ("\aThere should be no arguments.\n")
|
|
exit
|
|
}
|
|
|
|
if ((whatis ("PIX_TYPE") & 0x08000000) != 0) {
|
|
printf ("\n\aThe pixel detector software has not been initialised!\n")
|
|
printf ( "Use the \"pixsetup\" command.\n")
|
|
exit
|
|
} else if (!PIX_IS_ON){
|
|
printf ("\aThe pixel detector is currently not enabled. Use the \"pixon\"")
|
|
printf ("command to enable it. Aborting...")
|
|
exit
|
|
} else{
|
|
# Get the name of the last file
|
|
fnam = epics_get (PIX_FNAM_CHN)
|
|
# Compose a command to use it. Maybe there is a
|
|
# better way of doing this, but I do not know how!
|
|
cmnd = sprintf ("pixsnap %s", fnam)
|
|
# And execute it.
|
|
eval (cmnd)
|
|
}
|
|
}'
|
|
|
|
#+
|
|
#------------------------------------------------------------------------------
|
|
# pixwait - wait for the pixel detector sub-system to become "Ready".
|
|
#-
|
|
|
|
def pixwait '{
|
|
# =======
|
|
|
|
global BEAMLINE, ENDSTATION
|
|
|
|
global PIX_IS_ON
|
|
|
|
global PIX_PATHA_CHN, PIX_PATHB_CHN
|
|
global PIX_FNAM_FMT_CHN, PIX_FNUM_CHN, PIX_FNAM_CHN
|
|
global PIX_EXPOSE_CHN
|
|
global PIX_STATUS_CHN, PIX_TRIG_CHN
|
|
|
|
global PIX_PATH, PIX_FILE_FMT, PIX_FNUM, PIX_EXPOSE, PIX_EXP_START_TIME
|
|
global PIX_LOG, PIX_LOG_CMND
|
|
global PIX_COLOR_DEPTH, PIX_FILE_HEADER_LENGTH
|
|
global PIX_THRESH1, PIX_THRESH2, PIX_THRESH3, PIX_THRESH4
|
|
global PIX_XDIM, PIX_YDIM
|
|
|
|
local cnt, trig, stat, smsFlag
|
|
|
|
if ((whatis ("PIX_TYPE") & 0x08000000) != 0) {
|
|
printf ("\n\aThe pixel detector software has not been initialised!\n")
|
|
printf ( "Use the \"pixsetup\" command.\n")
|
|
exit
|
|
} else if (!PIX_IS_ON){
|
|
printf ("\aThe pixel detector is currently not enabled. Use the \"pixon\"")
|
|
printf ("command to enable it. Aborting...")
|
|
exit
|
|
}
|
|
|
|
cnt = 0
|
|
#
|
|
# First wait for "TRIG" to go back to idle. This should
|
|
# ensure that execution of the command has started.
|
|
#
|
|
trig = epics_get (PIX_TRIG_CHN, "long")
|
|
while (trig != 0) {
|
|
cnt = cnt + 1
|
|
if (cnt > 1000) {
|
|
printf("Triger signal still busy, pixwait timed-out!\n")
|
|
exit
|
|
}
|
|
sleep (0.05)
|
|
trig = epics_get (PIX_TRIG_CHN, "long")
|
|
}
|
|
|
|
#
|
|
# Then wait for exposure time to elapse.
|
|
# (PIX_EXPOSE is in milliseconds!)
|
|
#
|
|
while (time() <= PIX_EXP_START_TIME+(PIX_EXPOSE/1000)){
|
|
sleep(0.05)
|
|
}
|
|
|
|
#
|
|
# Then wait for the pixel detector to become ready.
|
|
# Wait time is 1000 x 0.05 sec = 50 sec.
|
|
#
|
|
smsFlag = 0
|
|
stat = epics_get (PIX_STATUS_CHN, "string")
|
|
while ((stat != "Ready0") && (stat != "Ready1")) {
|
|
cnt = cnt + 1
|
|
if (cnt > 1000) {
|
|
printf("%s %s", "pixwait: Pixel status did not return to \"Ready\" within 50", \\
|
|
"seconds.\n")
|
|
beep; beep; beep; beep; beep;
|
|
if (smsFlag == 0) {
|
|
smsSendMessage ("Pixel detector problem in pixwait.")
|
|
}
|
|
smsFlag = 1
|
|
printf ("\n")
|
|
secs=15
|
|
while (secs > 0) {
|
|
printf ("\r\aHit any keyboard character within %3d secs to abort.", secs)
|
|
sleep (1.0)
|
|
_9 = input (-1)
|
|
if (length (_9) > 0) {
|
|
beep; printf ("\nAborted.\n")
|
|
exit
|
|
}
|
|
secs--
|
|
}
|
|
printf ("Trying for another 50 secs\n")
|
|
}
|
|
if ((stat == "Undefined") || \
|
|
(stat == "Time-out") || \
|
|
(stat == "Error")) {
|
|
print "\aInvalid PIX status:", stat
|
|
exit
|
|
}
|
|
sleep (0.05)
|
|
stat = epics_get (PIX_STATUS_CHN, "string")
|
|
}
|
|
if (smsFlag == 1) {
|
|
smsSendMessage ("Pixel detector seems to have recovered from error.")
|
|
}
|
|
}'
|
|
|
|
#+
|
|
#------------------------------------------------------------------------------
|
|
# pixsw - call pixsnap and then pixwait.
|
|
#
|
|
# Usage : pixsw [<filename>]
|
|
#
|
|
# See pixsnap and pixwait for a description.
|
|
#-
|
|
|
|
def pixsw '{
|
|
# =====
|
|
|
|
global BEAMLINE, ENDSTATION
|
|
|
|
global PIX_IS_ON
|
|
|
|
global PIX_PATHA_CHN, PIX_PATHB_CHN
|
|
global PIX_FNAM_FMT_CHN, PIX_FNUM_CHN, PIX_FNAM_CHN
|
|
global PIX_EXPOSE_CHN
|
|
global PIX_STATUS_CHN, PIX_TRIG_CHN
|
|
|
|
global PIX_PATH, PIX_FILE_FMT, PIX_FNUM, PIX_EXPOSE, PIX_EXP_START_TIME
|
|
global PIX_LOG, PIX_LOG_CMND
|
|
global PIX_COLOR_DEPTH, PIX_FILE_HEADER_LENGTH
|
|
global PIX_THRESH1, PIX_THRESH2, PIX_THRESH3, PIX_THRESH4
|
|
global PIX_XDIM, PIX_YDIM
|
|
|
|
pixsnap $*
|
|
pixwait
|
|
}'
|
|
|
|
#+
|
|
#------------------------------------------------------------------------------
|
|
# pixlogon - turn on logging of EPICS stuff on each snap
|
|
#
|
|
# Usage : pixlogon [<dirname>]
|
|
#
|
|
# Turn on logging. If an argument is supplied, it specifies a directory
|
|
# for holding the log files. If it is not specified, the user will
|
|
# be prompted.
|
|
#-
|
|
|
|
def pixlogon '{
|
|
# ========
|
|
|
|
global BEAMLINE, ENDSTATION
|
|
|
|
global PIX_IS_ON
|
|
|
|
global PIX_PATHA_CHN, PIX_PATHB_CHN
|
|
global PIX_FNAM_FMT_CHN, PIX_FNUM_CHN, PIX_FNAM_CHN
|
|
global PIX_EXPOSE_CHN
|
|
global PIX_STATUS_CHN, PIX_TRIG_CHN
|
|
|
|
global PIX_PATH, PIX_FILE_FMT, PIX_FNUM, PIX_EXPOSE, PIX_EXP_START_TIME
|
|
global PIX_LOG, PIX_LOG_CMND
|
|
global PIX_COLOR_DEPTH, PIX_FILE_HEADER_LENGTH
|
|
global PIX_THRESH1, PIX_THRESH2, PIX_THRESH3, PIX_THRESH4
|
|
global PIX_XDIM, PIX_YDIM
|
|
|
|
local myPathA, myPathB, myPath, myDir, myFile
|
|
|
|
PIX_LOG = "" # Disable logging in case of errors.
|
|
|
|
if (($# != 0) && ($# != 1)) {
|
|
print "Usage: pixlogon [<dirname>]"
|
|
exit
|
|
}
|
|
if ($# != 1) {
|
|
myPathA = epics_get (PIX_PATHA_CHN)
|
|
myPathB = epics_get (PIX_PATHB_CHN)
|
|
myPath = sprintf ("%s%s", myPathA, myPathB)
|
|
myDir = getsval ("Specify a directory", myPath)
|
|
} else {
|
|
myDir = "$1"
|
|
}
|
|
if (substr (myDir, length (myDir)) != "/") {
|
|
myDir = sprintf ("%s/", myDir)
|
|
}
|
|
if (!file_info (myDir, "-e")) {
|
|
printf ("\aSorry, %s does not exist.\n", myDir)
|
|
exit
|
|
}
|
|
if (!file_info (myDir, "isdir")) {
|
|
printf ("\aSorry, %s is not a directory.\n", myDir)
|
|
exit
|
|
}
|
|
myFile = sprintf ("%s/%s", myDir, "spec.test")
|
|
if (file_info (myFile, "-e")) {
|
|
unix (sprintf ("rm %s", myFile))
|
|
if (file_info (myFile, "-e")) {
|
|
printf ("\aCannot delete a test file in this directory.\n")
|
|
exit
|
|
}
|
|
}
|
|
fprintf (myFile, "This is a test record\n")
|
|
close (myFile)
|
|
if (!file_info (myFile, "-e")) {
|
|
printf ("\aSorry, %s is not a writable directory.\n")
|
|
exit
|
|
}
|
|
unix (sprintf ("rm %s", myFile))
|
|
|
|
unix (sprintf ("dirname %s", PIXEL_MAC), _1)
|
|
ll = length (_1)
|
|
if (substr (_1, ll, 1) == "\n") _1 = substr (_1, 1, (ll - 1))
|
|
myFile = sprintf ("%s/ccd-log.req", _1)
|
|
###PIX_LOG_CMND = sprintf ("casave -asciiin %s -asciiout %%s", myFile)
|
|
PIX_LOG_CMND = sprintf ("X_X04SA_do_casave.py -- -asciiin %s -asciiout %%s", myFile)
|
|
|
|
PIX_LOG = myDir
|
|
printf ("logging of image-related info to %s has been turned on.\n", myDir)
|
|
|
|
}'
|
|
|
|
#+
|
|
#------------------------------------------------------------------------------
|
|
# pixlogoff - turn off logging on each pixel detector snap
|
|
#
|
|
# Usage : pixlogoff
|
|
#-
|
|
|
|
def pixlogoff '{
|
|
# =========
|
|
|
|
global BEAMLINE, ENDSTATION
|
|
|
|
global PIX_IS_ON
|
|
|
|
global PIX_PATHA_CHN, PIX_PATHB_CHN
|
|
global PIX_FNAM_FMT_CHN, PIX_FNUM_CHN, PIX_FNAM_CHN
|
|
global PIX_EXPOSE_CHN
|
|
global PIX_STATUS_CHN, PIX_TRIG_CHN
|
|
|
|
global PIX_PATH, PIX_FILE_FMT, PIX_FNUM, PIX_EXPOSE, PIX_EXP_START_TIME
|
|
global PIX_LOG, PIX_LOG_CMND
|
|
global PIX_COLOR_DEPTH, PIX_FILE_HEADER_LENGTH
|
|
global PIX_THRESH1, PIX_THRESH2, PIX_THRESH3, PIX_THRESH4
|
|
global PIX_XDIM, PIX_YDIM
|
|
|
|
PIX_LOG = "" # Disable logging.
|
|
printf ("logging of image-related info has been turned off.\n")
|
|
}'
|
|
|
|
#+
|
|
#------------------------------------------------------------------------------
|
|
# pixlogshow - display the snap logging status.
|
|
#
|
|
# Usage : pixlogshow
|
|
#-
|
|
|
|
def pixlogshow '{
|
|
# ==========
|
|
|
|
global BEAMLINE, ENDSTATION
|
|
|
|
global PIX_PATHA_CHN, PIX_PATHB_CHN
|
|
global PIX_FNAM_FMT_CHN, PIX_FNUM_CHN, PIX_FNAM_CHN
|
|
global PIX_EXPOSE_CHN
|
|
global PIX_STATUS_CHN, PIX_TRIG_CHN
|
|
|
|
global PIX_PATH, PIX_FILE_FMT, PIX_FNUM, PIX_EXPOSE, PIX_EXP_START_TIME
|
|
global PIX_LOG, PIX_LOG_CMND
|
|
global PIX_COLOR_DEPTH, PIX_FILE_HEADER_LENGTH
|
|
global PIX_THRESH1, PIX_THRESH2, PIX_THRESH3, PIX_THRESH4
|
|
global PIX_XDIM, PIX_YDIM
|
|
|
|
if (PIX_LOG == "") {
|
|
printf ("\nPIX snap logging is off.\n")
|
|
} else {
|
|
printf ("\nPIX snap logging is on. The log directory is:\n")
|
|
printf ("\n %s\n", PIX_LOG)
|
|
printf ("\nThe log command is:\n")
|
|
printf ("\n %s\n", PIX_LOG_CMND)
|
|
}
|
|
}'
|
|
|
|
#+
|
|
#------------------------------------------------------------------------------
|
|
# pixlogwrite - write a pixel detector snap log file.
|
|
#
|
|
# Usage : pixlogwrite [<filename>]
|
|
#
|
|
# Write a PIX snap log file. The file name is either derived from the
|
|
# name of the snap file or is the specified argument.
|
|
#-
|
|
|
|
def pixlogwrite '{
|
|
# ===========
|
|
|
|
global BEAMLINE, ENDSTATION
|
|
|
|
global PIX_IS_ON
|
|
|
|
global PIX_PATHA_CHN, PIX_PATHB_CHN
|
|
global PIX_FNAM_FMT_CHN, PIX_FNUM_CHN, PIX_FNAM_CHN
|
|
global PIX_EXPOSE_CHN
|
|
global PIX_STATUS_CHN, PIX_TRIG_CHN
|
|
|
|
global PIX_PATH, PIX_FILE_FMT, PIX_FNUM, PIX_EXPOSE, PIX_EXP_START_TIME
|
|
global PIX_LOG, PIX_LOG_CMND
|
|
global PIX_COLOR_DEPTH, PIX_FILE_HEADER_LENGTH
|
|
global PIX_THRESH1, PIX_THRESH2, PIX_THRESH3, PIX_THRESH4
|
|
global PIX_XDIM, PIX_YDIM
|
|
|
|
local myFile, myCmnd
|
|
|
|
if (PIX_LOG != "") {
|
|
# Put our local variables into EPICS to allow fast writing
|
|
epics_put ("X04SA-ES3-MOT:phi", A[motor_num(phi)])
|
|
epics_put ("X04SA-ES3-MOT:omegaH", A[motor_num(oh)])
|
|
epics_put ("X04SA-ES3-MOT:nu", A[motor_num(nu)])
|
|
epics_put ("X04SA-ES3-MOT:omegaV", A[motor_num(ov)])
|
|
epics_put ("X04SA-ES3-MOT:alpha", A[motor_num(alp)])
|
|
epics_put ("X04SA-ES3-MOT:delta", A[motor_num(del)])
|
|
epics_put ("X04SA-ES3-MOT:gamma", A[motor_num(gam)])
|
|
#epics_put ("X04SA-ES3-MOT:2-thetaA", A[motor_num(ttha)])
|
|
#epics_put ("X04SA-ES3-MOT:omegaA", A[motor_num(oa)])
|
|
epics_put ("X04SA-ES3-MOT:xV", A[motor_num(xv)])
|
|
epics_put ("X04SA-ES3-MOT:y1", A[motor_num(y1)])
|
|
epics_put ("X04SA-ES3-MOT:y2", A[motor_num(y2)])
|
|
epics_put ("X04SA-ES3-MOT:y3", A[motor_num(y3)])
|
|
epics_put ("X04SA-ES3-MOT:TRx", A[motor_num(trx)])
|
|
epics_put ("X04SA-ES3-MOT:thetaY", A[motor_num(thy)])
|
|
#epics_put ("X04SA-ES3-MOT:Slit1", A[motor_num(s1)])
|
|
#epics_put ("X04SA-ES3-MOT:Slit2", A[motor_num(s2)])
|
|
#epics_put ("X04SA-ES3-MOT:Slit3", A[motor_num(s3)])
|
|
#epics_put ("X04SA-ES3-MOT:Slit4", A[motor_num(s4)])
|
|
#epics_put ("X04SA-ES3-MOT:Slit5", A[motor_num(s5)])
|
|
#epics_put ("X04SA-ES3-MOT:Slit6", A[motor_num(s6)])
|
|
#epics_put ("X04SA-ES3-MOT:Slit7", A[motor_num(s7)])
|
|
#epics_put ("X04SA-ES3-MOT:Slit8", A[motor_num(s8)])
|
|
|
|
epics_put ("X04SA-ES3-SPEC:H", Q[0])
|
|
epics_put ("X04SA-ES3-SPEC:K", Q[1])
|
|
epics_put ("X04SA-ES3-SPEC:L", Q[2])
|
|
epics_put ("X04SA-ES3-SPEC:LAMBDA", Q[4])
|
|
# Then dump the EPICS channels
|
|
if ($# < 1) {
|
|
myFile = epics_get ("X04SA-ES3-CCD:FNAM")
|
|
myFile = substr (myFile, 0, index (myFile, "."))
|
|
myFile = sprintf ("%s%s%s", PIX_LOG, myFile, "pxl")
|
|
} else {
|
|
myFile = sprintf ("%s%s", PIX_LOG, "$1")
|
|
}
|
|
myCmnd = sprintf (PIX_LOG_CMND, myFile)
|
|
unix (myCmnd)
|
|
}
|
|
}'
|
|
|
|
#+
|
|
#------------------------------------------------------------------------------
|
|
# Controling the shutter on the detector arm
|
|
# ------------------------------------------
|
|
#
|
|
# pshop - open the shutter on the detector arm
|
|
# pshcl - close the shutter on the detector arm
|
|
#
|
|
#-
|
|
|
|
def pshop 'epics_put ("X04SA-ES3-PINO:PS-SET", "Out")'
|
|
def pshcl 'epics_put ("X04SA-ES3-PINO:PS-SET", "In")'
|
|
|
|
#+
|
|
#------------------------------------------------------------------------------
|
|
# Internal routines
|
|
# -----------------
|
|
#
|
|
# pixCheckFileFmt - check that file format contains a string
|
|
# of the form "%0...d" or "%0...i".
|
|
#-
|
|
|
|
def pixCheckFileFmt (fmt, verbose) '{
|
|
# ===============
|
|
|
|
idx = index (fmt, "%")
|
|
if (idx <= 0) {
|
|
if (verbose) {
|
|
print "\aWarning -- file template does not contain a \"%0...d\" string."
|
|
}
|
|
return 1
|
|
} else {
|
|
idx = idx + 1
|
|
if (substr (fmt, idx, 1) == "i") return 0
|
|
if (substr (fmt, idx, 1) == "d") return 0
|
|
if (substr (fmt, idx, 1) != "0") {
|
|
if (verbose) {
|
|
print "\aWarning -- the character after \"%\" should be \"0\", \"i\" or \"d\"."
|
|
}
|
|
return 1
|
|
}
|
|
i = sscanf (substr (fmt, idx), "%d%c", _1, _2)
|
|
if ((i != 2) || ((_2 != "i") && (_2 != "d"))) {
|
|
if (verbose) {
|
|
print "\aWarning -- file template does not contain a valid \"%0...d\" string."
|
|
}
|
|
return 1
|
|
}
|
|
}
|
|
return 0
|
|
}'
|
|
|
|
#+
|
|
#------------------------------------------------------------------------------
|
|
# pixgetfilefmt - retrieve the image file format from the name template.
|
|
# set global variable PIX_FILE_HEADER_LENGTH accordingly.
|
|
#-
|
|
|
|
def pixgetfilefmt '{
|
|
# =============
|
|
|
|
# get the file name extension and set the file type dependent parameters
|
|
my_fmt = epics_get(PIX_FNAM_FMT_CHN)
|
|
nitem = split(my_fmt,my_fileparts,".")
|
|
my_ext = my_fileparts[nitem-1]
|
|
|
|
if (my_ext == "tif"){
|
|
PIX_FILE_HEADER_LENGTH = 4096
|
|
} else if (my_ext == "edf") {
|
|
PIX_FILE_HEADER_LENGTH = 1024
|
|
} else {
|
|
PIX_FILE_HEADER_LENGTH = 0
|
|
}
|
|
|
|
# update corresponding variables for the image analysis
|
|
IMAGE_HEADER_LENGTH = PIX_FILE_HEADER_LENGTH
|
|
}'
|
|
|
|
|
|
#+
|
|
#------------------------------------------------------------------------------
|
|
#-
|
|
#==============================================================================
|
|
#
|
|
#####################################################
|
|
# emacs setup: force text mode to get no help with #
|
|
# indentation and force use of spaces #
|
|
# when tabbing. #
|
|
# Local Variables: #
|
|
# mode:text #
|
|
# indent-tabs-mode:nil #
|
|
# End: #
|
|
#####################################################
|
|
#
|
|
# $Log: pixel.mac,v $
|
|
# Revision 1.11 2009/05/28 10:10:56 schlepuetz
|
|
# removed Pilatus1 support, check image file format during count command to allow for img,edf,tif files
|
|
#
|
|
# Revision 1.10 2009/05/27 15:00:41 bjorck
|
|
# Adding changes for EPICS implementation of motors and fixes for the hexapod
|
|
#
|
|
# Revision 1.9 2007/02/21 09:06:28 maden
|
|
# Remove references to s1, ..., s8
|
|
#
|
|
# Revision 1.8 2007/02/21 08:56:57 maden
|
|
# Send sms message if status time-out
|
|
#
|
|
# Revision 1.7 2006/12/13 15:04:11 schlepuetz
|
|
# removed requirement that exposuretime must be an integer multiple of 0.001 seconds in pixsetexpose
|
|
#
|
|
# Revision 1.6 2006/07/07 11:49:56 maden
|
|
# Modify PIX_LOG_CMND command
|
|
#
|
|
# Revision 1.5 2006/06/16 08:48:33 schlepuetz
|
|
# fixed typo on pixhelp
|
|
#
|
|
# Revision 1.4 2006/06/14 11:44:28 schlepuetz
|
|
# fixed bug in pixUserCountEnd returning the wrong COUNT_ID value (1 too high).
|
|
#
|
|
# Revision 1.3 2006/03/01 13:02:47 maden
|
|
# Check-in newer version from /work ...
|
|
#
|
|
# Revision 1.2 2005/11/30 15:34:19 schlepuetz
|
|
# fixed timing problem with pixlogwrite; resolved issues with pixwait running into timeouts for long exposures
|
|
#
|
|
# Revision 1.1 2005/11/10 11:15:20 schlepuetz
|
|
# first tested version of this file
|
|
#
|
|
#
|
|
#============================== End of $RCSfile: pixel.mac,v $=== |