# --------------------------------------------------------------------------
# Initialization script for DMC at SINQ, SICS server.
#
# Dr. Mark Koennecke March 1997
#---------------------------------------------------------------------------
#                        O P T I O N S

set auto_path "/data/koenneck/src/sics/tcl"
source $auto_path/dmccom.tcl


# first all the server options are set

ServerOption ReadTimeOut  100 
# 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  100 
# 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 ServerLogBaseName  /data/koenneck/src/sics/server
# the path and base name of the internal server logfile to which all
# activity will be logged.

ServerOption ServerPort 2910 
# 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 2913
# The UDP port where the server will wait for Interrupts from clients.
# Obviously, clients wishing to interrupt need to know this number.

ServerOption DefaultCommandFile dmccom.tcl
# The path to the file containing common Tcl-commands and procedures.
# Every connection is initialized with this

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

# than the SICS users are specified
# Syntax: SicsUser name password userRightsCode
SicsUser Mugger Diethelm  1
SicsUser User   Rosy      2
SicsUser Spy    007       3


#--------------------------------------------------------------------------
#                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 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 

# Monochromator motors
Motor  OmegaM    SIM    20. 120. 5. 2.0
Motor  TwoThetaM SIM 20. 120. 5. 0.5
Motor  MonoX     SIM -20. 20. 5. 5.0
Motor  MonoY     SIM -20. 20. 5. 5.0
Motor  CurveM    SIM 0. 1000.  10. 5.0
Motor  MonoPhi   SIM -20. 20. 5. 5.0
Motor  MonoChi   SIM -20. 20. 5. 5.0

# sample Table
Motor  Table     SIM  -180. 180. 5. 7.0
Motor  TwoThetaD SIM  10.   330.  5. 1.0
#--------------------------------------------------------------------------
#                          Configure Detector
# needs a EL737 or simualation for count control
MakeCounter xxxNo SIM

#MakeHM banana SINQHM        
MakeHM banana  SIM
banana configure HistMode Normal
banana configure OverFlowMode    Ceil
banana configure Rank     1
banana configure Length   400
banana configure BinWidth 4
banana configure Time 10. 12. 14 16. 17.
banana preset 100.
banana CountMode Timer
#banana configure HMComputer psds02.psi.ch
#banana configure HMport 2400
#banana configure Counter xxxNo
banana init
#--------------------------------------------------------------------------
#     C O N F I G U R E     D E V I C E S     T O    H A L T  I N
#                        I N T E R R U P T 
AddHalt  OmegaM TwoThetaM MonoX MonoY MonoChi MonoPhi CurveM Table TwoThetaD
#--------------------------------------------------------------------------
#                        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 "DMC at SINQ,PSI" 
#initialisation

VarMake Title Text User
VarMake User  Text User
VarMake Collimation Text User
VarMake Sample Text User
VarMake comment1 Text User
VarMake comment2 Text User
VarMake Comment3 Text User

VarMake SicsDataPath Text Internal
SicsDataPath "/data/koenneck/src/sics/"
VarMake SicsDataPrefix Text Internal
SicsDataPrefix DMC
VarMake SicsDataNumber Int Internal
SicsDataNumber 0
VarMake SicsDataPostFix Text Internal
SicsDataPostFix ".hdf"
VarMake Adress Text User
VarMake phone  Text User
VarMake fax    Text User
VarMake email  Text User
VarMake sample_mur Float User
VarMake DetStepWidth Float Internal
DetStepWidth 0.02

  

# Monochromator variables 
# Syntax MakeMono name type  OmegaMotor 2ThetaMotor CurveMotor1 CurveMotor2
MakeMono Mono "Ge-111" OmegaM TwoThetaM CurveM
# Syntax MakeWaveLength name MonochromatorToUse
MakeWaveLength lambda  Mono
 
             
#--------------------------------------------------------------------------
#                           P R O C E D U R E S

# create the drive command
MakeDrive
#start RuenBuffer system
MakeRuenBuffer

if { 0 } {

DMCInit 5 2.0 1
# end --------  of ------------- file -------------------------------------
# test code for powder diagrams, merging etc.

set id1 [DMCShot set 1 2  2 2 2 2 2]
set id2 [DMCShot set 2 3  3 3 3 3 3]
set id3 [DMCShot set 6 1  1 1 1 1 1]
set id4 [DMCShot set 7 5  5 5 5 5 5]
set p1 [DMCPowder merge $id1 $id2 $id3 $id4]
ClientPut [DMCPowder info $p1]
ClientPut [DMCPowder list $p1 0 17]
ClientPut [DMCPowder Start $p1]
ClientPut [DMCPowder Step  $p1]
ClientPut [DMCPowder Stop   $p1] 
DMCReset
}
# test of alias
SicsAlias OmegaM    A1
SicsAlias TwoThetaM A2
SicsAlias Table     A3
SicsAlias TwoThetaD A4
InitDMC
