From 915ab1a0a29d92ba5bd08a9027dec5a990d18f31 Mon Sep 17 00:00:00 2001 From: Jing Chen Date: Wed, 30 May 2012 11:50:11 +1000 Subject: [PATCH] replace name hv_control.tcl with sct_hv.tcl r3554 | jgn | 2012-05-30 11:50:11 +1000 (Wed, 30 May 2012) | 1 line --- .../pelican/config/beamline/hv_control.tcl | 10 - .../pelican/config/beamline/sct_hv.tcl | 273 +++++++++++++----- 2 files changed, 197 insertions(+), 86 deletions(-) delete mode 100644 site_ansto/instrument/pelican/config/beamline/hv_control.tcl diff --git a/site_ansto/instrument/pelican/config/beamline/hv_control.tcl b/site_ansto/instrument/pelican/config/beamline/hv_control.tcl deleted file mode 100644 index 904a59ff..00000000 --- a/site_ansto/instrument/pelican/config/beamline/hv_control.tcl +++ /dev/null @@ -1,10 +0,0 @@ -fileeval $cfPath(beamline)/sct_hv.tcl - -::scobj::hv::mkHV { - name "hv" - IP localhost - PORT 55010 - tuning 1 - interval 3 -} - diff --git a/site_ansto/instrument/pelican/config/beamline/sct_hv.tcl b/site_ansto/instrument/pelican/config/beamline/sct_hv.tcl index 5f587f5a..1b935587 100644 --- a/site_ansto/instrument/pelican/config/beamline/sct_hv.tcl +++ b/site_ansto/instrument/pelican/config/beamline/sct_hv.tcl @@ -40,72 +40,97 @@ ############################################################################################################################## +proc debug_log {args} { + set d1 [clock format [clock seconds] -format %d%h%Y] + set fd [open "../log/pressure$d1.log" a] + puts $fd "[clock format [clock seconds] -format "%D %T "] [string trim $args "{}"]" + close $fd +} + + namespace eval ::scobj::hv { } -proc ::scobj::hv:setting {par} { +proc ::scobj::hv:setting {field} { 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 + switch $field { + "voltage" {set comm "set hv=$newPara\r\n"} + "pressure" {set comm "set pressure=$newPara\r\n"} + "mode" {set comm "set mode=$newPara\r\n"} + "date" {set comm "set date=$newPara\r\n"} + default {error "ERROR: illegal input command, type help for more info" + return idle + } } + + 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" +# @brief send "get status" command to the HV device and obtain the latest status of the device +proc ::scobj::hv::getHVStatusFunc {mode} { + switch $mode { + "state" {set comm "get status\r\n"} + "config" {set comm "get config\r\n"} + default {error "ERROR: illegal input command, type help for more info" + return idle + } + } + sct send $comm - return rdParaState + #after 500 + return rdHVStatus } ## -# @brief Read and record the parameters' values from the HV device -proc ::scobj::hv::rdParaStateFunc {basePath} { +# @brief Read and record the HV status from the HV device +proc ::scobj::hv::rdHVStatusFunc {basePath mode} { set replyStr [sct result] - #broadcast "Reply from hv_get: $replyStr" - + hset $basePath/msg $replyStr + #broadcast "Reply from get $mode: $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 "=;"] + error "ERROR: cannot get the current parameters setting from the HV device, check again!" + } else { + set replyText [split [string trimright $replyStr "\r\n "] ","] - array set paraArr $s2 + if {$mode == "state"} { + hset $basePath/status/state "[lindex $replyText 3] [lindex $replyText 4]" + hset $basePath/status/voltage "[lindex $replyText 5] [lindex $replyText 6]" + hset $basePath/status/current "[lindex $replyText 7] [lindex $replyText 8]" + hset $basePath/status/pressure1 "[lindex $replyText 10] [lindex $replyText 11]" + hset $basePath/status/pressure2 "[lindex $replyText 13] [lindex $replyText 14]" + hset $basePath/status/pressure3 "[lindex $replyText 16] [lindex $replyText 17]" + hset $basePath/status/pressure4 "[lindex $replyText 19] [lindex $replyText 20]" + hset $basePath/status/pressure5 "[lindex $replyText 22] [lindex $replyText 23]" + hset $basePath/status/pressure6 "[lindex $replyText 25] [lindex $replyText 26]" + hset $basePath/status/PLC-S "[lindex $replyText 28]" + hset $basePath/status/PLC-H "[lindex $replyText 30]" + hset $basePath/status/Presr-S "[lindex $replyText 32]" + hset $basePath/status/Presr-H "[lindex $replyText 34]" + hset $basePath/status/Soft-S "[lindex $replyText 36]" + hset $basePath/status/Hard-S "[lindex $replyText 38]" - hset $basePath/hv1 $paraArr(hv1) - hset $basePath/i1 $paraArr(i1) - hset $basePath/hv2 $paraArr(hv2) - hset $basePath/i2 $paraArr(i2) + set logdata "[lindex $replyText 10] [lindex $replyText 13] [lindex $replyText 16] [lindex $replyText 19] [lindex $replyText 22] [lindex $replyText 25]" + debug_log $logdata - #broadcast "HV1:$paraArr(hv1); I1:$paraArr(i1); HV2:$paraArr(hv2); I2:$paraArr(i2)\n" + } elseif {$mode == "config"} { + hset $basePath/config/mode "[lindex $replyText 3] [lindex $replyText 4]" + hset $basePath/config/hv "[lindex $replyText 5]" + hset $basePath/config/pressure_threshold "[lindex $replyText 6] [lindex $replyText 7]" + } else { + return idle + } sct utime readtime } @@ -135,59 +160,155 @@ proc ::scobj::hv::mkHV {argList} { 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 + hfactory /sics/$pa(NAME)/status plain user none + hfactory /sics/$pa(NAME)/status/voltage plain user text + hfactory /sics/$pa(NAME)/status/current plain user text + hfactory /sics/$pa(NAME)/status/pressure1 plain user text + hfactory /sics/$pa(NAME)/status/pressure2 plain user text + hfactory /sics/$pa(NAME)/status/pressure3 plain user text + hfactory /sics/$pa(NAME)/status/pressure4 plain user text + hfactory /sics/$pa(NAME)/status/pressure5 plain user text + hfactory /sics/$pa(NAME)/status/pressure6 plain user text + hfactory /sics/$pa(NAME)/status/state plain user text + hfactory /sics/$pa(NAME)/status/PLC-S plain user text + hfactory /sics/$pa(NAME)/status/PLC-H plain user text + hfactory /sics/$pa(NAME)/status/Presr-S plain user text + hfactory /sics/$pa(NAME)/status/Presr-H plain user text + hfactory /sics/$pa(NAME)/status/Soft-S plain user text + hfactory /sics/$pa(NAME)/status/Hard-S plain user text + + hfactory /sics/$pa(NAME)/config plain user none + hfactory /sics/$pa(NAME)/config/hv plain user text + hfactory /sics/$pa(NAME)/config/mode plain user text + hfactory /sics/$pa(NAME)/config/pressure_threshold 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 read ::scobj::hv::getHVStatusFunc "state" + hsetprop /sics/$pa(NAME)/status rdHVStatus ::scobj::hv::rdHVStatusFunc /sics/$pa(NAME) "state" - hsetprop /sics/$pa(NAME)/status tuning $pa(TUNING) + hsetprop /sics/$pa(NAME)/config read ::scobj::hv::getHVStatusFunc "config" + hsetprop /sics/$pa(NAME)/config rdHVStatus ::scobj::hv::rdHVStatusFunc /sics/$pa(NAME) "config" # Initialise properties required for generating the API for GumTree and to save data - ::scobj::hinitprops $pa(NAME) hv1 i1 hv2 i2 msg + ::scobj::hinitprops $pa(NAME) status config + ::scobj::hinitprops $pa(NAME) status/voltage status/current status/state + ::scobj::hinitprops $pa(NAME) status/pressure1 status/pressure2 status/pressure3 status/pressure4 status/pressure5 status/pressure6 + ::scobj::hinitprops $pa(NAME) status/PLC-S status/PLC-H status/Presr-S status/Presr-H status/Soft-S status/Hard-S + ::scobj::hinitprops $pa(NAME) config/hv config/pressure_threshold config/mode - sct_hv poll /sics/$pa(NAME)/status $pa(INTERVAL) + if {[SplitReply [environment_simulation]]=="false"} { + sct_hv poll /sics/$pa(NAME)/status $pa(INTERVAL) + sct_hv poll /sics/$pa(NAME)/config $pa(INTERVAL) + } + + hsetprop /sics/$pa(NAME) tuning $pa(TUNING) 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 + hfactory /sics/$pa(NAME)/set_hv plain user int + hfactory /sics/$pa(NAME)/set_pressure plain user int + hfactory /sics/$pa(NAME)/set_mode plain user text + hfactory /sics/$pa(NAME)/set_date plain user text + + ::scobj::hinitprops $pa(NAME) set_hv set_pressure set_mode set_date - ::scobj::hinitprops $pa(NAME) status set_hv1 set_hv2 set_i1 set_i2 + hsetprop /sics/$pa(NAME)/set_hv write ::scobj::hv:setting "voltage" + hsetprop /sics/$pa(NAME)/set_hv checkReply ::scobj::hv::checkReplyFunc /sics/$pa(NAME) - 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_pressure write ::scobj::hv:setting "pressure" + hsetprop /sics/$pa(NAME)/set_pressure 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_hv2 oldStatus UNKNOWN + hsetprop /sics/$pa(NAME)/set_mode write ::scobj::hv:setting "mode" + hsetprop /sics/$pa(NAME)/set_mode 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_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) + hsetprop /sics/$pa(NAME)/set_date write ::scobj::hv:setting "date" + hsetprop /sics/$pa(NAME)/set_date checkReply ::scobj::hv::checkReplyFunc /sics/$pa(NAME) + if {[SplitReply [environment_simulation]]=="false"} { + sct_hv write /sics/$pa(NAME)/set_hv $pa(INTERVAL) + sct_hv write /sics/$pa(NAME)/set_pressure $pa(INTERVAL) + sct_hv write /sics/$pa(NAME)/set_mode $pa(INTERVAL) + sct_hv write /sics/$pa(NAME)/set_date $pa(INTERVAL) + } } } +proc hvGetStatus {} { + set cmd "get status\r\n" + sct_hv send $cmd +} + +proc hvGetConfig {} { + set cmd "get config\r\n" + sct_hv send $cmd +} + +proc hvClearError {} { + set cmd "clear error\r\n" + sct_hv send $cmd +} + +proc hvSetHV {vol} { + set cmd "set hv=$vol\r\n" + sct_hv send $cmd +} + +proc hvSetPressure {pressure} { + set cmd "set pressure=$pressure\r\n" + sct_hv send $cmd +} + +proc hvSetMode {mode} { + set cmd "set mode=$mode\r\n" + sct_hv send $cmd +} + +proc hvSetDate {date} { + set cmd "set date=$date\r\n" + sct_hv send $cmd +} + +proc hvPowerUp {} { + set cmd "power up\r\n" + sct_hv send $cmd +} + +proc hvPowerDown {} { + set cmd "power down\r\n" + sct_hv send $cmd +} + +proc hvHelp {} { + set cmd "help\r\n" + sct_hv send $cmd +} + +publish hvGetStatus user +publish hvGetConfig user +publish hvClearError user +publish hvSetHV user +publish hvSetPressure user +publish hvSetMode user +publish hvSetDate user +publish hvPowerUp user +publish hvPowerDown user +publish hvHelp user + +# Main process call +::scobj::hv::mkHV { + name "hv" + IP 137.157.202.215 + PORT 55011 + tuning 1 + interval 5 +} + + + + + +