Files
sics/test/testini.tcl
2007-12-19 09:56:30 +00:00

340 lines
11 KiB
Tcl

# --------------------------------------------------------------------------
# Initialization script for testing SICS
#
# Started: Dr. Mark Koennecke, July 2006
#---------------------------------------------------------------------------
# O P T I O N S
# --------------- Initialize Tcl internals --------------------------------
# first all the server options are set
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 ServerPort 2911
# 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.
#---------------------------------------------------------------------------
# U S E R S
# than the SICS users are specified
# Syntax: SicsUser name password userRightsCode
SicsUser Mugger Mugger 1
SicsUser User User 2
SicsUser Spy Spy 3
#SicsUser Spy 007 1
#----------------- SICS Variable
VarMake lotte Text User
#----------------- Motors ---------------------------------------------------
Motor brumm regress
MakeDrive
#----------------- Alias ----------------------------------------------------
SicsAlias brumm miau
#----------------- Counters -------------------------------------------------
MakeCounter aba regress
MakeCounter hugo SIM -1.
MakeCounter lieselotte SIM -1.
#------------------------------
proc SICSValue {command} {
set txt [eval $command]
set l [split $txt =]
return [string trim [lindex $l 1]]
}
#-----------------------------
proc multitransfer {} {
append res [SICSValue "aba gettime"] " "
for {set i 0} {$i < 7} {incr i} {
append res [SICSValue "aba getmonitor $i"] " "
}
return $res
}
#-----------------------------------
MakeMultiCounter multi aba hugo lieselotte
multi transferscript multitransfer
#------------- For Scanning ---------------------------------------------
# This is with the tricky bit set: we use a multicounter and use the
# scantransfer function to return values of a gaussian for a4 positions.
# This gives nice scan data which can be used to test all sorts of things.
#-------------------------------------------------------------------------
MakeDataNumber SicsDataNumber ./DataNumber
VarMake SicsDataPath Text Mugger
SicsDataPath ./
SicsDataPath lock
VarMake SicsDataPrefix Text Mugger
SicsDataPrefix regression
SicsDataPrefix lock
VarMake SicsDataPostFix Text Mugger
SicsDataPostFix .dat
SicsDataPostFix lock
Motor a1 SIM -2 180 -.1 10
Motor a2 SIM 30 150 -.1 10
Motor a3 SIM -360 360 -.1 10
Motor a4 SIM -180 180 -.1 10
Motor a5 SIM -180 180 -.1 10
Motor a6 SIM -180 180 -.1 10
Motor sgu SIM -20 20 -.1 10
Motor sgl SIM -20 20 -.1 10
MakeMultiCounter scanCter aba
proc scantransfer {} {
set FWHM 1.5
set pos 5.33
set height 700
set stddev [expr $FWHM/2.354]
set ftmp [expr ([SICSValue a4] - $pos)/$stddev]
set count [expr 10 + $height*0.4*exp(-.5*$ftmp*$ftmp)]
set counti [expr int($count)]
append res [SICSValue "lieselotte gettime"] " "
append res $counti " "
for {set i 1} {$i < 7} {incr i} {
append res [SICSValue "lieselotte getmonitor $i"] " "
}
return $res
}
scancter transferscript scantransfer
MakeScanCommand xxxscan scancter test.hdd recover.bin
MakePeakCenter xxxscan
source scancommand.tcl
MakeOptimise opti scancter
MakeMaximize scancter
#-------------------------------------------------------------------------
# Histogram Memory
#------------------------------------------------------------------------
MakeHM hm regress
hm configure rank 1
hm configure dim0 23
hm configure testval 1
hm configure errortype 0
hm configure recover 1
hm configure init 1
hm init
MakeHM tof regress
tof configure rank 1
tof configure HistMode TOF
tof configure dim0 23
tof configure testval 1
tof configure errortype 0
tof configure recover 1
tof genbin 10 12 100
tof configure init 1
tof init
#-------------------------------------------------------------------------
# NXscript
#-------------------------------------------------------------------------
MakeNXScript
#-------------------------------------------------------------------------
proc makearray {} {
global ar
for { set i 10} {$i < 20} {incr i} {
set ar([expr $i - 10]) [expr $i*1.0]
}
}
#------------------------------------------------------------------------
proc makeintarray {} {
global ar
for { set i 10} {$i < 20} {incr i} {
set ar([expr $i - 10]) $i
}
}
Publish makearray User
Publish makeintarray User
Publish parray User
#------------------------------------------------------------------------
# SicsData
#------------------------------------------------------------------------
sicsdatafactory new data
sicsdatafactory new duta
#-----------------------------------------------------------------------
# tasub
#-----------------------------------------------------------------------
MakeTasUB tasub
#-----------------------------------------------------------------------
# MultiMotors
#----------------------------------------------------------------------
MakeMulti sa
sa alias a3 om
sa alias a4 stt
sa pos noeff a3 24 a4 48
sa endconfig
#-----------------------------------------------------------------------
# Hipadaba
#----------------------------------------------------------------------
InstallHdb
hmake /instrument spy none
hmake /instrument/sample spy none
hattach /instrument/sample a3 omega
hattach /instrument/sample qh qh
hmake /instrument/detector spy none
hattach /instrument/detector hm data
hattach /instrument lotte title
restore
#-------------------------------------------------
proc farmFormat {par num} {
hsetprop /sics/farm/$par lastError none
return [format "$par %d" [string trim $num]]
}
#-----------------------------------------------
proc farmRead {par } {
hsetprop /sics/farm/$par lastError none
hsetprop /sics/farm/$par replyCommand "farmReply $par"
return $par
}
#-----------------------------------------------
proc farmReply {par reply} {
set action [string trim [hgetpropval /sics/farm/$par status]]
hsetprop /sics/farm/$par status idle
if {[string first OK $reply] >= 0} {
if {[string first get $action] >= 0} {
set idx [string first : $reply]
if {$idx > 0} {
set val [string trim [string range $reply [expr $idx +1] end]]
hupdate /sics/farm/$par $val
}
} else {
hget /sics/farm/$par
}
} else {
if {[string first ERROR $reply] < 0} {
set reply "ERROR: $reply"
}
clientPut $reply
error $reply
}
}
#=============================================
proc schconset {val} {
set com [farmFormat schnegge $val]
hsetprop /sics/farm/schneggecon replyCommand schreply
return $com
}
#----------------------------------------------
proc schreply {reply} {
clientput "schreply $reply"
if {[string first OK $reply] >= 0} {
hsetprop /sics/farm/schneggerunning readCommand schrunget
hget /sics/farm/schneggerunning
hsetprop /sics/farm/schneggerunning readCommand \
"farmReply schneggerunning"
} else {
hsetprop /sics/farm/schneggecon status idle
hsetprop /sics/farm/schneggecon lastError $reply
clientput "ERROR: $reply on schnegge"
}
}
#-----------------------------------------------
proc schrun {reply} {
clientput "schrun $reply"
hsetprop /sics/farm/schneggerunning status idle
if {[string first OK $reply] >= 0} {
set idx [string first : $reply]
if {$idx > 0} {
set val [string trim [string range $reply [expr $idx +1] end]]
hupdate /sics/farm/schneggerunning $val
if {$val == 1} {
clientput "schnegge creeping"
hsetprop /sics/farm/schneggerunning readCommand schrunget
hget /sics/farm/schneggerunning
hsetprop /sics/farm/schneggerunning readCommand \
"farmReply schneggerunning"
} else {
clientput "schnegge finished"
hsetprop /sics/farm/schneggerunning readCommand \
"farmRead schneggerunning"
hsetprop /sics/farm/schneggecon status idle
}
}
} else {
clientput "schnegge has error: $reply"
hsetprop /sics/farm/schneggerunning readCommand \
"farmRead schneggerunning"
hsetprop /sics/farm/schneggecon status idle
hsetprop /sics/farm/schneggecon lastError $reply
hsetprop /sics/farm/schneggerunning lastError $reply
}
}
#----------------------------------------------
proc schget {} {
hsetprop /sics/farm/schneggecon lastError none
hsetprop /sics/farm/schneggecon replyCommand "farmReply schneggecon"
return schnegge
}
#----------------------------------------------
proc schrunget {} {
hsetprop /sics/farm/schneggerunning lastError none
hsetprop /sics/farm/schneggerunning replyCommand schrun
return schneggerunning
}
#-----------------------------------------------
set farm 0
if {$farm == 1} {
# Generic Controller
#-------------------------------------------------------------------
MakeAsyncProtocol norma
MakeAsyncQueue farmQueue norma localhost 9090
MakeGenController farm
genconfigure asynconnect farm farmQueue
#------------------------------------------------
genconfigure makepar farm hase int
hsetprop /sics/farm/hase priv user
hsetprop /sics/farm/hase writeCommand "farmFormat hase"
hsetprop /sics/farm/hase readCommand "farmRead hase"
hsetprop /sics/farm/hase replyCommand "farmReply hase"
genconfigure makepar farm schnegge int
hsetprop /sics/farm/schnegge priv user
hsetprop /sics/farm/schnegge writeCommand "farmFormat schnegge"
hsetprop /sics/farm/schnegge readCommand "farmRead schnegge"
hsetprop /sics/farm/schnegge replyCommand "farmReply schnegge"
genconfigure makepar farm schneggerunning int
hsetprop /sics/farm/schneggerunning priv internal
hsetprop /sics/farm/schneggerunning readCommand "farmRead schneggerunning"
hsetprop /sics/farm/schneggerunning replyCommand "farmReply schneggerunning"
genconfigure makepar farm schneggecon int
hsetprop /sics/farm/schneggecon priv user
hsetprop /sics/farm/schneggecon writeCommand schconset
hsetprop /sics/farm/schneggecon readCommand schget
hsetprop /sics/farm/schneggecon replyCommand schreply
}
#source sansdruck.tcl
#MakeRS232Controller sadu pc4639 4168
#MakeRS232Controller sadu localhost 4168
#sadu replyterminator 0x04
#sadu sendterminator 0x04
#sadu timeout 1000