188 lines
5.0 KiB
Tcl
188 lines
5.0 KiB
Tcl
##
|
|
# @file He3 controller
|
|
#
|
|
# Author: Jing Chen (jgn@ansto.gov.au) June 2010
|
|
#
|
|
# The He3 controller can be installed with the following command,
|
|
# ::scobj::he3::mkHe3 {
|
|
# name "he3"
|
|
# IP localhost
|
|
# PORT 6290
|
|
# tuning 1
|
|
# interval 2
|
|
# }
|
|
#
|
|
# NOTE:
|
|
# If tuning=1 this will generate gom/set_gom, gchi/set_gchi and gphi/set_gphi
|
|
# nodes for the instrument scientists.
|
|
# The tuning parameter should be set to 0 for the users.
|
|
#
|
|
|
|
namespace eval ::scobj::he3 {
|
|
}
|
|
|
|
##
|
|
# @brief Request a state from the He3 controller by sending a get command
|
|
proc ::scobj::he3::rqStatFunc {} {
|
|
set comm "get\n"
|
|
sct send $comm
|
|
return rdState
|
|
}
|
|
|
|
##
|
|
# @brief Read and record the state report from the He3 server
|
|
proc ::scobj::he3::rdStatFunc {basePath} {
|
|
set replyStr [sct result]
|
|
hset $basePath/msg $replyStr
|
|
if {[string first "Error" $replyStr] != -1} {
|
|
broadcast "ERROR: Wrong Command to the He3 server, check again!"
|
|
} else {
|
|
set s1 [string trimright $replyStr "\n"]
|
|
set s2 [split $s1 ";:"]
|
|
|
|
array set stateArr $s2
|
|
|
|
hset $basePath/Amplitude $stateArr(amp)
|
|
hset $basePath/Frequence $stateArr(fre)
|
|
hset $basePath/NaN $stateArr(nan)
|
|
hset $basePath/T2 $stateArr(t2)
|
|
|
|
broadcast "Amp:$stateArr(amp); Fre:$stateArr(fre); NaN:$stateArr(nan); T2:$stateArr(t2)\n"
|
|
}
|
|
|
|
if {$replyStr != [sct oldval]} {
|
|
sct oldval $replyStr
|
|
sct update $replyStr
|
|
sct utime readtime
|
|
}
|
|
|
|
return idle
|
|
}
|
|
|
|
# send trigger signal and get repsponse from SICS
|
|
proc ::scobj::he3::sendTrigger {} {
|
|
set newPara [sct target]
|
|
if {[string equal [string toupper $newPara] "OK"]!=1} {
|
|
error "ERROR: please enter 'ok' to send a trigger signal to He3 device"
|
|
return idle
|
|
} else {
|
|
set cmd "trigger\r\n"
|
|
sct send $cmd
|
|
return checkReply
|
|
}
|
|
}
|
|
|
|
proc ::scobj::he3::checkReplyFunc {basePath} {
|
|
set replyStr [sct result]
|
|
hset $basePath/msg $replyStr
|
|
return idle
|
|
}
|
|
|
|
|
|
##
|
|
# @brief Make a He3 controller
|
|
#
|
|
# @param argList, {name "he3" IP localhost PORT 62900 tuning 1 interval 2}
|
|
#
|
|
# name: name of he3 controller object
|
|
# IP: IP address of RF generator moxa box
|
|
# PORT: Port number assigned to the generator on the moxa-box
|
|
# tuning: boolean, set tuning=1 to allow instrument scientists to set the axe positions
|
|
# interval: polling and ramping interval in seconds.
|
|
proc ::scobj::he3::mkHe3 {argList} {
|
|
# Generate parameter array from the argument list
|
|
foreach {k v} $argList {
|
|
set KEY [string toupper $k]
|
|
set pa($KEY) $v
|
|
}
|
|
|
|
set hPath /sics/$pa(NAME)
|
|
|
|
MakeSICSObj $pa(NAME) SCT_OBJECT
|
|
sicslist setatt $pa(NAME) klass environment
|
|
sicslist setatt $pa(NAME) long_name $pa(NAME)
|
|
|
|
hsetprop $hPath oldval UNKNOWN
|
|
|
|
hfactory $hPath/msg plain internal text
|
|
hfactory $hPath/Amplitude plain internal float
|
|
hfactory $hPath/Frequence plain internal float
|
|
hfactory $hPath/NaN plain internal float
|
|
hfactory $hPath/T2 plain internal float
|
|
|
|
hset $hPath/Amplitude 0.0
|
|
hset $hPath/Frequence 0.0
|
|
hset $hPath/NaN 0.0
|
|
hset $hPath/T2 0.0
|
|
|
|
hsetprop $hPath klass environment
|
|
hsetprop $hPath privilege spy
|
|
hsetprop $hPath type part
|
|
hsetprop $hPath control true
|
|
hsetprop $hPath data true
|
|
|
|
foreach {hdbPath klass control data nxsave mutable priv alias} {
|
|
/sics/he3/Amplitude NXsensor true true true true user he3_Amplitude
|
|
/sics/he3/Frequence NXsensor true true true true user he3_Frequence
|
|
/sics/he3/NaN NXsample true true true true user he3_NaN
|
|
/sics/he3/T2 NXsample true true true true user he3_T2
|
|
} {
|
|
hsetprop $hdbPath nxalias $alias
|
|
hsetprop $hdbPath klass $klass
|
|
hsetprop $hdbPath privilege $priv
|
|
hsetprop $hdbPath control $control
|
|
hsetprop $hdbPath data $data
|
|
hsetprop $hdbPath nxsave $nxsave
|
|
hsetprop $hdbPath mutable $mutable
|
|
hsetprop $hdbPath sdsinfo ::nexus::scobj::sdsinfo
|
|
}
|
|
|
|
::scobj::hinitprops $pa(NAME)
|
|
|
|
makesctcontroller sct_he3 std $pa(IP):$pa(PORT)
|
|
|
|
hsetprop $hPath read ::scobj::he3::rqStatFunc
|
|
hsetprop $hPath rdState ::scobj::he3::rdStatFunc $hPath
|
|
|
|
# Initialise properties required for generating the API for GumTree and to save data
|
|
#::scobj::hinitprops $pa(NAME) Amplitude Frequence NaN T2
|
|
|
|
if {[SplitReply [environment_simulation]]=="false"} {
|
|
sct_he3 poll $hPath $pa(INTERVAL)
|
|
}
|
|
|
|
hsetprop $hPath tuning $pa(TUNING)
|
|
|
|
if {$pa(TUNING)} {
|
|
hfactory $hPath/send_trigger plain user text
|
|
|
|
::scobj::hinitprops $pa(NAME) send_trigger
|
|
|
|
hsetprop $hPath/send_trigger write ::scobj::he3::sendTrigger
|
|
hsetprop $hPath/send_trigger checkReply ::scobj::he3::checkReplyFunc /sics/$pa(NAME)
|
|
|
|
if {[SplitReply [environment_simulation]]=="false"} {
|
|
sct_he3 write $hPath/send_trigger $pa(INTERVAL)
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
proc He3Trigger {} {
|
|
set cmd "trigger\r\n"
|
|
sct_he3 send $cmd
|
|
}
|
|
|
|
publish He3Trigger user
|
|
|
|
|
|
# main driver call
|
|
#::scobj::he3::mkHe3 {
|
|
# name "he3"
|
|
# IP 137.157.204.8
|
|
# PORT 22
|
|
# tuning 1
|
|
# interval 1
|
|
#}
|
|
|