# --------------------------------------------------------------------------
# Initialization script the instrument SANS at SINQ
#
# Dr. Mark Koennecke, June 1997
#---------------------------------------------------------------------------
#                        O P T I O N S
set root "/data/koenneck/src/sics"
# first all the server options are set

ServerOption SaveFile $root/bin/sansstat.tcl
# File to save the status of the instrument too

ServerOption ReadTimeOut  10
# timeout when checking for commands. In the main loop SICS checks for
# pending commands on each connection with the above timeout, has 
# PERFORMANCE impact!

ServerOption AcceptTimeOut  10
# timeout when checking for connection req.
# Similar to above, but for connections

ServerOption ReadUserPasswdTimeout  500000 
# time to wiat for a user/passwd to be sent from a client. Increase this
# if there is a problem connecting to a server due to network overload\

ServerOption LogFileBaseName  $root/log/sanslog
# the path and base name of the internal server logfile to which all
# activity will be logged.

ServerOption ServerPort 2915
# the port number the server is going to listen at. The client MUST know
# this number in order to connect. It is in client.ini

ServerOption InterruptPort 2917
# The UDP port where the server will wait for Interrupts from clients.
# Obviously, clients wishing to interrupt need to know this number.

# Telnet Options
ServerOption TelnetPort 1301
ServerOption TelWord sicslogin

# The token system
TokenInit connan

#---------------------------------------------------------------------------
#                        U S E R S

# than the SICS users are specified
# Syntax: SicsUser name password userRightsCode
SicsUser Manager Joachim   1
SicsUser User    Kohl      2
SicsUser Spy     007       3

#--------------------------------------------------------------------------
#               S I M P L E     V A R I A B L E S

# now a few general variables are created
# Syntax: VarMake name type access
# type can be one of: Text, Int, Float
#access can be one of: Internal, Mugger, user, Spy

VarMake Instrument Text Internal 
Instrument "SANS at SINQ,PSI" 
#initialisation
Instrument lock

VarMake title Text User
VarMake User  Text User
User "Albert von Villigen"
VarMake SubTitle Text User
VarMake environment Text User
VarMake comment Text User
VarMake SampleName Text User
SampleName  KohlSulfid
#----------- Initialize data storage stuff
VarMake SicsDataPath Text Mugger
SicsDataPath $root/data/
SicsDataPath lock
VarMake SicsDataPrefix Text Mugger
SicsDataPrefix sans
SicsDataPrefix lock
VarMake SicsDataPostFix Text Mugger
SicsDataPostFix ".hdf"
SicsDataPostFix lock
MakeDataNumber SicsDataNumber $root/data/DataNumber
InitSANS  $root/data/sansdict.dic


#--------------------------------------------------------------------------
#                D E V I C E S :  M O T O R S

#Motor a4 EL734 LNSP22 4000 5 6
# EL734 motor with parameters: hostname PortNumber Channel MotorID

#Motor a4 EL734DC LNSP22 4000 5 6
# EL734DC motor with parameters: hostname PortNumber Channel MotorID

# Motor nam SIM -20. 20. 5. 1.0
# Simulated motor with name nam, lower limit -20, upper limit +20,
# error ratio 5% and speed 1.0. Speed may be omitted 

# Motors for sample movement
Motor schi SIM -22.0 +22. 10. 
Motor sphi SIM -22.0 +22.0 10.
Motor som EL734 lnsp25.psi.ch 4000 2 8
Motor sax EL734 lnsp25.psi.ch 4000 2 6
Motor say EL734 lnsp25.psi.ch 4000 2 7
Motor saz EL734 lnsp25.psi.ch 4000 2 1
Motor spos EL734 lnsp25.psi.ch 4000 2 5

#Motors for detector movement
Motor DetectorX EL734DC lnsp25.psi.ch 4000 3 1
DetectorX Precision 0.5 
Motor DetectorY EL734DC lnsp25.psi.ch 4000 3 2
DetectorY Precision 0.2
Motor DetectorRotation EL734DC lnsp25.psi.ch 4000 3 3
DetectorRotation Precision 0.1

#Motors for beamstop
Motor BeamStopX EL734 lnsp25.psi.ch 4000 2 3
BeamStopX Precision 0.2
Motor BeamStopY EL734 lnsp25.psi.ch 4000 2 4
BeamStopY Precision 0.2


#------------------------------------------------------------------------
#               Velocity selector 
Motor tilt EL734 lnsp25.psi.ch 4000 2 2
set dornen(Host) lnsp25.psi.ch
set dornen(Port) 4000
set dornen(Channel) 6
set dornen(Timeout) 3000
VelocitySelector nvs tilt DORNIER dornen
nvs add -20 28800
nvs add 3800 4500
nvs add 5900 6700
nvs add 8100 9600
unset dornen

#--------------------------------------------------------------------------
#                           P R O C E D U R E S

# create the drive command
MakeDrive
#--------------------------------------------------------------------------
# MultiMotor is an object which groups several motors together.

#--------------------------------- sample position
MakeMulti sample
# creates a MultiMotor with name sample
sample alias schi chi
# alias creates an internal name (chi) for motor schi
sample alias sphi phi
sample alias som omega
sample alias sax x
sample alias say y
sample alias saz z
sample pos Jo schi  0.  sphi  0. som  45. sax  2. say  3. saz  10.
# define Jo as a named position. This means with sample Jo you'll reach
# the positions specified
sample pos Mo schi  0.  sphi  0. som 180. sax  2. say  3. saz  10.
sample endconfig
# ends configuration of sample and install the command. This is REQUIRED

#---------------------------------- detector position
MakeMulti detector
detector alias DetectorX X
detector alias DetectorY Y
detector alias DetectorRotation phi
detector endconfig

#----------------------------------- beamstop 
MakeMulti BeamStop
BeamStop alias BeamStopX X
BeamStop alias BeamStopY Y
BeamStop pos out BeamStopX  817.
BeamStop endconfig
#------------------------------------ Shortcuts
SicsAlias BeamStop bs
SicsAlias detector dt
#------------------------------------ Histogram Memory
MakeCounter counter EL737 lnsp25.psi.ch 4000 4
counter SetExponent 6

MakeHM banana SINQHM
banana configure HistMode Normal
banana configure OverFlowMode    Ceil
banana configure Rank     1
banana configure Length   16384
banana configure BinWidth 4
banana preset 100.
banana CountMode Timer
banana configure HMComputer lnse02.psi.ch
banana configure HMPort 2400
banana configure Counter counter
banana init
banana exponent 6
#-----------------------------------------------------------------------------
#                    R U E N B U F F E R
MakeRuenBuffer

#---------------------- some special Tcl commands 
source $root/bin/log.tcl
Publish LogBook User

source $root/bin/count.tcl
Publish count User
Publish Repeat User
