configurationi init

r3266 | jgn | 2011-11-18 14:14:15 +1100 (Fri, 18 Nov 2011) | 1 line
This commit is contained in:
Jing Chen
2011-11-18 14:14:15 +11:00
committed by Douglas Clowes
parent 5596b9fd99
commit f0ce45b66c

View File

@@ -0,0 +1,176 @@
###########################################################################################################################
# @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]
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""}
}
sct send $comm
return checkReply
}
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!"
} else {
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)
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)
hsetprop /sics/$pa(NAME) read ::scobj::hv::getParaFunc
hsetprop /sics/$pa(NAME) rdParaState ::scobj::hv::rdParaStateFunc /sics/$pa(NAME)
hsetprop /sics/$pa(NAME) 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) $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) 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_hv2 write ::scobj::hv:setting "hv2"
hsetprop /sics/$pa(NAME)/set_hv2 checkReply ::scobj::hv::checkReplyFunc /sics/$pa(NAME)
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_i2 write ::scobj::hv:setting "i2"
hsetprop /sics/$pa(NAME)/set_i2 checkReply ::scobj::hv::checkReplyFunc /sics/$pa(NAME)
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)
}
}