194 lines
6.7 KiB
Tcl
194 lines
6.7 KiB
Tcl
###########################################################################################################################
|
|
# @file Proptocols between SICS and High Voltage Controller
|
|
#
|
|
# This is a driver for SICS to make following communication with the High Voltage Controller
|
|
#
|
|
#
|
|
# 1. SICS uses TCP/IP protocol to interact with the HV component who shall provide an IP address
|
|
# together with an port number.
|
|
#
|
|
# 2. Commands From SICS to HV component,
|
|
# 1. HV_START hv1=xxx, i1=xxx, hv2=xxx, i2=xxx
|
|
# :: Responses from HV component back to SICS are either
|
|
# OK (if the system start correctly), or
|
|
# Error Message (if the system does not start normally, the error message shall indicate
|
|
# type of the errors)
|
|
#
|
|
# 2. HV_STOP (This will stop/shutdown the HV component totally)
|
|
#
|
|
# 3. HV_RESET (This will reset the HV component using the hv/i values specified in the Gumtree client GUI)
|
|
# :: Responses from HV component back to SICS are either
|
|
# OK (if the system start correctly), or
|
|
# Error Message (if the system does not start normally, the error message will indicate type of the errors)
|
|
#
|
|
# 4. HV_STATUS (This command will send to HV component automatically and regularly, i.e. every 1 sec)
|
|
# :: Responses from HV component back to SICS is "hv1=xxx, i1=xxx, hv2=xxx, i2=xxx, system=rampingup;\n",
|
|
# SICS uses this information to update their values in the SICS system and on the Gumtree client as well.
|
|
#
|
|
# 3. HV parameters to be dsiaplyed on the Gumtree GUI are, hv1, i1, hv2, i2, system
|
|
#
|
|
# Author: Jing Chen (jgn@ansto.gov.au) July 2011
|
|
#
|
|
# The HV Controller can be installed with the following command,
|
|
# ::scobj::hv::mkHV {
|
|
# name "hv"
|
|
# IP localhost
|
|
# PORT 55010
|
|
# tuning 1
|
|
# interval 1
|
|
#
|
|
##############################################################################################################################
|
|
|
|
|
|
namespace eval ::scobj::hv {
|
|
}
|
|
|
|
proc ::scobj::hv:setting {par} {
|
|
|
|
set newPara [sct target]
|
|
|
|
if{[sct oldStatus] != $newPara} {
|
|
set oldStatus $newPara
|
|
switch $par {
|
|
"hv1" {set comm "hv_set hv1 $newPara"}
|
|
"hv2" {set comm "hv_set hv2 $newPara"}
|
|
"i1" {set comm "hv_set i1 $newPara"}
|
|
"i2" {set comm "hv_set i2 $newPara"}
|
|
default {error "ERROR: illegal parameters, try "hv1","hv2","i1" or "i2""
|
|
return idle}
|
|
}
|
|
|
|
sct send $comm
|
|
return checkReply
|
|
} else {
|
|
return idle
|
|
}
|
|
}
|
|
|
|
proc ::scobj::hv::checkReplyFunc {basePath} {
|
|
set replyStr [sct result]
|
|
#analysis the reply from the HV Device
|
|
if {[string first "Error" $replyStr] != -1} {
|
|
broadcast "ERROR command, check again!!"
|
|
}
|
|
hset $basePath/msg $replyStr
|
|
return idle
|
|
}
|
|
|
|
##
|
|
|
|
# @brief send "hv_get" command to the HV device and obtain the latest values of those parameters
|
|
proc ::scobj::hv::getParaFunc {} {
|
|
set comm "hv_get"
|
|
sct send $comm
|
|
return rdParaState
|
|
}
|
|
|
|
##
|
|
# @brief Read and record the parameters' values from the HV device
|
|
proc ::scobj::hv::rdParaStateFunc {basePath} {
|
|
set replyStr [sct result]
|
|
#broadcast "Reply from hv_get: $replyStr"
|
|
|
|
if {[string first "Error" $replyStr] != -1} {
|
|
broadcast "ERROR: cannot get the current parameters setting from the HV device, check again!"
|
|
} elseif {$replyStr != [sct oldval]} {
|
|
sct oldval $replyStr
|
|
broadcast "oldval = [sct oldval]"
|
|
set s1 [string trimright $replyStr "\n"]
|
|
set s2 [split $s1 "=;"]
|
|
|
|
array set paraArr $s2
|
|
|
|
hset $basePath/hv1 $paraArr(hv1)
|
|
hset $basePath/i1 $paraArr(i1)
|
|
hset $basePath/hv2 $paraArr(hv2)
|
|
hset $basePath/i2 $paraArr(i2)
|
|
|
|
#broadcast "HV1:$paraArr(hv1); I1:$paraArr(i1); HV2:$paraArr(hv2); I2:$paraArr(i2)\n"
|
|
|
|
sct utime readtime
|
|
}
|
|
|
|
return idle
|
|
}
|
|
|
|
|
|
##
|
|
# @brief Make a HV Controller
|
|
#
|
|
# @param argList, {name "hv" IP localhost PORT 65123 tuning 1 interval 1}
|
|
#
|
|
# name: name of hv 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::hv::mkHV {argList} {
|
|
# Generate parameter array from the argument list
|
|
foreach {k v} $argList {
|
|
set KEY [string toupper $k]
|
|
set pa($KEY) $v
|
|
}
|
|
|
|
MakeSICSObj $pa(NAME) SCT_OBJECT
|
|
sicslist setatt $pa(NAME) klass instrument
|
|
sicslist setatt $pa(NAME) long_name $pa(NAME)
|
|
hsetprop /sics/$pa(NAME) status "IDLE"
|
|
|
|
hfactory /sics/$pa(NAME)/hv1 plain user int
|
|
hfactory /sics/$pa(NAME)/hv2 plain user int
|
|
hfactory /sics/$pa(NAME)/i1 plain user int
|
|
hfactory /sics/$pa(NAME)/i2 plain user int
|
|
hfactory /sics/$pa(NAME)/msg plain user text
|
|
|
|
#makesctcontroller sct_hv rfamp $pa(IP):$pa(PORT)
|
|
makesctcontroller sct_hv std $pa(IP):$pa(PORT)
|
|
|
|
hfactory /sics/$pa(NAME)/status plain user text
|
|
hsetprop /sics/$pa(NAME)/status read ::scobj::hv::getParaFunc
|
|
hsetprop /sics/$pa(NAME)/status rdParaState ::scobj::hv::rdParaStateFunc /sics/$pa(NAME)
|
|
hsetprop /sics/$pa(NAME)/status oldval UNKNOWN
|
|
hset /sics/$pa(NAME)/status idle
|
|
|
|
hsetprop /sics/$pa(NAME)/status tuning $pa(TUNING)
|
|
|
|
# Initialise properties required for generating the API for GumTree and to save data
|
|
::scobj::hinitprops $pa(NAME) hv1 i1 hv2 i2 msg
|
|
|
|
sct_hv poll /sics/$pa(NAME)/status $pa(INTERVAL)
|
|
|
|
if {$pa(TUNING)} {
|
|
hfactory /sics/$pa(NAME)/set_hv1 plain user int
|
|
hfactory /sics/$pa(NAME)/set_hv2 plain user int
|
|
hfactory /sics/$pa(NAME)/set_i1 plain user int
|
|
hfactory /sics/$pa(NAME)/set_i2 plain user int
|
|
|
|
::scobj::hinitprops $pa(NAME) status set_hv1 set_hv2 set_i1 set_i2
|
|
|
|
hsetprop /sics/$pa(NAME)/set_hv1 write ::scobj::hv:setting "hv1"
|
|
hsetprop /sics/$pa(NAME)/set_hv1 checkReply ::scobj::hv::checkReplyFunc /sics/$pa(NAME)
|
|
hsetprop /sics/$pa(NAME)/set_hv1 oldStatus UNKNOWN
|
|
|
|
hsetprop /sics/$pa(NAME)/set_hv2 write ::scobj::hv:setting "hv2"
|
|
hsetprop /sics/$pa(NAME)/set_hv2 checkReply ::scobj::hv::checkReplyFunc /sics/$pa(NAME)
|
|
hsetprop /sics/$pa(NAME)/set_hv2 oldStatus UNKNOWN
|
|
|
|
hsetprop /sics/$pa(NAME)/set_i1 write ::scobj::hv:setting "i1"
|
|
hsetprop /sics/$pa(NAME)/set_i1 checkReply ::scobj::hv::checkReplyFunc /sics/$pa(NAME)
|
|
hsetprop /sics/$pa(NAME)/set_i1 oldStatus UNKNOWN
|
|
|
|
hsetprop /sics/$pa(NAME)/set_i2 write ::scobj::hv:setting "i2"
|
|
hsetprop /sics/$pa(NAME)/set_i2 checkReply ::scobj::hv::checkReplyFunc /sics/$pa(NAME)
|
|
hsetprop /sics/$pa(NAME)/set_i2 oldStatus UNKNOWN
|
|
|
|
sct_hv write /sics/$pa(NAME)/set_hv1 $pa(INTERVAL)
|
|
sct_hv write /sics/$pa(NAME)/set_hv2 $pa(INTERVAL)
|
|
sct_hv write /sics/$pa(NAME)/set_i1 $pa(INTERVAL)
|
|
sct_hv write /sics/$pa(NAME)/set_i2 $pa(INTERVAL)
|
|
|
|
}
|
|
}
|
|
|