From 4619a57eff2d09bfc6502164b6297f9c0c7931e6 Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Wed, 18 Feb 2015 14:14:11 +1100 Subject: [PATCH 01/10] Pullback from Quokka 2015-02-18 --- .../magneticField/sct_bruker_BEC1.tcl | 83 ------------------ .../environment/magneticField/sct_tsi_smc.tcl | 4 +- .../config/environment/sct_hiden_xcs.tcl | 76 ++++++++++++++--- .../temperature/sct_julabo_lh45.tcl | 85 +++++++++++++++++++ .../temperature/sct_julabo_lh45_gen.tcl | 2 +- .../temperature/sct_lakeshore_370.tcl | 2 +- .../temperature/sct_oxford_mercury.tcl | 2 +- .../config/hmm/hmm_configuration_common_1.tcl | 20 +++++ .../environment/sct_antonparr_MCR500.tcl | 4 + .../sans/config/environment/sct_rheometer.tcl | 1 + .../config/motors/motor_configuration.tcl | 4 +- .../instrument/sans/quokka_configuration.tcl | 5 +- 12 files changed, 187 insertions(+), 101 deletions(-) diff --git a/site_ansto/instrument/config/environment/magneticField/sct_bruker_BEC1.tcl b/site_ansto/instrument/config/environment/magneticField/sct_bruker_BEC1.tcl index fa1dc6fd..cebab88c 100644 --- a/site_ansto/instrument/config/environment/magneticField/sct_bruker_BEC1.tcl +++ b/site_ansto/instrument/config/environment/magneticField/sct_bruker_BEC1.tcl @@ -1366,88 +1366,5 @@ proc add_bruker_bec1 {name IP port {_tol 0.1} {CID 1} {CTYPE B} } { handle_exception $catch_status $message "In subroutine add_bruker_bec1()." } -namespace eval ::scobj::bruker_bec1 { -set debug_threshold 5 -} -proc ::scobj::bruker_bec1::sics_log {debug_level debug_string} { - set catch_status [ catch { - set debug_threshold ${::scobj::bruker_bec1::debug_threshold} - if {${debug_level} >= ${debug_threshold}} { - sicslog "::scobj::bruker_bec1::${debug_string}" - } - } catch_message ] -} - clientput "file evaluation of sct_bruker_bec1.tcl" -::scobj::bruker_bec1::sics_log 9 "file evaluation of sct_bruker_bec1.tcl" - -proc ::scobj::bruker_bec1::read_config {} { - set catch_status [ catch { - set ns "::scobj::bruker_bec1" - dict for {k v} $::config_dict { - if { [dict exists $v "implementation"] } { - if { !([dict exists $v "name"] && [dict exists $v "enabled"]) } { - continue - } - set name [dict get $v name] - set enabled [string tolower [dict get $v "enabled"]] - set implementation [dict get $v "implementation"] - if { !([dict exists $::config_dict $implementation]) } { - continue - } - set v [dict get $::config_dict $implementation] - if { !([dict exists $v "driver"]) } { - continue - } - if { [string equal -nocase [dict get $v "driver"] "bruker_bec1"] } { - if { [string equal -nocase $enabled "true" ] || [string equal -nocase $enabled "always"] } { - if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } { - set asyncqueue "null" - ${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue" - } elseif { [dict exists $v "asyncqueue"] } { - set asyncqueue [dict get $v "asyncqueue"] - } else { - if { [dict exists $v "asyncprotocol"] } { - set asyncprotocol [dict get $v "asyncprotocol"] - } else { - set asyncprotocol ${name}_protocol - MakeAsyncProtocol ${asyncprotocol} - if { [dict exists $v "terminator"] } { - ${asyncprotocol} sendterminator "[dict get $v "terminator"]" - ${asyncprotocol} replyterminator "[dict get $v "terminator"]" - } - } - set asyncqueue ${name}_queue - set IP [dict get $v ip] - set PORT [dict get $v port] - MakeAsyncQueue ${asyncqueue} ${asyncprotocol} ${IP} ${PORT} - if { [dict exists $v "timeout"] } { - ${asyncqueue} timeout "[dict get $v "timeout"]" - } - } - set arg_list [list] - foreach arg {tol id type} { - if {[dict exists $v $arg]} { - lappend arg_list "[dict get $v $arg]" - } else { - ${ns}::sics_log 9 "Missing configuration value $arg" - error "Missing configuration value $arg" - } - } - add_bruker_bec1 ${name} "aqadapter" ${asyncqueue} {*}$arg_list - } - } - } - } - } catch_message ] - handle_exception ${catch_status} ${catch_message} -} - -if { [info exists ::config_dict] } { - ::scobj::bruker_bec1::read_config -} else { - ::scobj::bruker_bec1::sics_log 5 "No config dict" -} - - namespace import ::scobj::bruker_BEC1::* diff --git a/site_ansto/instrument/config/environment/magneticField/sct_tsi_smc.tcl b/site_ansto/instrument/config/environment/magneticField/sct_tsi_smc.tcl index cc91ca94..2334e95f 100644 --- a/site_ansto/instrument/config/environment/magneticField/sct_tsi_smc.tcl +++ b/site_ansto/instrument/config/environment/magneticField/sct_tsi_smc.tcl @@ -289,7 +289,7 @@ proc ::scobj::tsi_smc::mkDriver { sct_controller name device_class simulation_fl hsetprop ${scobj_hpath}/setpoint mutable true hsetprop ${scobj_hpath}/setpoint nxsave true hsetprop ${scobj_hpath}/setpoint lowerlimit 0 - hsetprop ${scobj_hpath}/setpoint upperlimit 500.0 + hsetprop ${scobj_hpath}/setpoint upperlimit 15000.0 hsetprop ${scobj_hpath}/setpoint tolerance 10 hsetprop ${scobj_hpath}/setpoint permlink data_set "B[format "%02d" ${id}]SP01" hsetprop ${scobj_hpath}/setpoint @description "B[format "%02d" ${id}]SP01" @@ -429,7 +429,7 @@ proc ::scobj::tsi_smc::mkDriver { sct_controller name device_class simulation_fl hsetprop ${scobj_hpath}/b/Lower mutable true hsetprop ${scobj_hpath}/b/Lower nxsave true hsetprop ${scobj_hpath}/b/Lower lowerlimit 0 - hsetprop ${scobj_hpath}/b/Lower upperlimit 2 + hsetprop ${scobj_hpath}/b/Lower upperlimit 60 hsetprop ${scobj_hpath}/b/Lower oldval 0.0 hsetprop ${scobj_hpath}/b/Lower klass "parameter" hsetprop ${scobj_hpath}/b/Lower sdsinfo "::nexus::scobj::sdsinfo" diff --git a/site_ansto/instrument/config/environment/sct_hiden_xcs.tcl b/site_ansto/instrument/config/environment/sct_hiden_xcs.tcl index 0801bad6..a56a10da 100644 --- a/site_ansto/instrument/config/environment/sct_hiden_xcs.tcl +++ b/site_ansto/instrument/config/environment/sct_hiden_xcs.tcl @@ -176,6 +176,35 @@ proc ::scobj::hiden_xcs::fetch_flow {tc_root nextState cmd_str} { handle_exception ${catch_status} ${catch_message} } +# function to request the read of a parameter on a device +proc ::scobj::hiden_xcs::getTarget {tc_root nextState cmd_str} { + set catch_status [ catch { + debug_log ${tc_root} 1 "getTarget tc_root=${tc_root} sct=[sct] cmd=${cmd_str}" + if { [hpropexists [sct] geterror] } { + hdelprop [sct] geterror + } + set cmd "${cmd_str}" +# getTarget hook code starts + if { [hpropexists [sct] target] } { + sct result [sct target] + } else { + sct result [hval [sct]] + } + set cmd "@@NOSEND@@" +# getTarget hook code ends + if { [hpropexists [sct] geterror] } { + debug_log ${tc_root} 9 "[sct] error: [sct geterror]" + error "[sct geterror]" + } + debug_log ${tc_root} 1 "getTarget sct send ${cmd}" + if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} { + sct send "${cmd}" + } + return ${nextState} + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + # function to request the read of a parameter on a device proc ::scobj::hiden_xcs::getValue {tc_root nextState cmd_str} { set catch_status [ catch { @@ -254,16 +283,20 @@ proc ::scobj::hiden_xcs::pid_flow {tc_root sp pv} { set p_value [expr {[sct pid_pvalue] * [sct pid_error]}] set d_value [expr {[sct pid_dvalue] * (${pv} - [sct oldval])}] sct pid_deriv [sct pid_error] - sct pid_integ [expr {[sct pid_integ] + [sct pid_error]}] + sct pid_integ [expr {[sct pid_integ] + [sct pid_error] * [sct pid_ivalue]}] if { [sct pid_integ] > [sct pid_imax] } { sct pid_integ [sct pid_imax] } if { [sct pid_integ] < -[sct pid_imax] } { sct pid_integ -[sct pid_imax] } - set i_value [expr {[sct pid_ivalue] * [sct pid_integ]}] + set i_value [sct pid_integ] set pid [expr {${p_value} + ${i_value} + ${d_value}}] # pid_flow hook code starts + if { ![hval ${tc_root}/auto] } { + set pid 0.0 + sct pid_integ 0.0 + } foreach node [list ${tc_root}/analog/sp1 ${tc_root}/analog/sp2] { if { !([hpropexists ${node} bias_flow] && [hgetpropval ${node} bias_flow] == ${pid}) } { hsetprop ${node} bias_flow ${pid} @@ -289,16 +322,20 @@ proc ::scobj::hiden_xcs::pid_humidity {tc_root sp pv} { set p_value [expr {[sct pid_pvalue] * [sct pid_error]}] set d_value [expr {[sct pid_dvalue] * (${pv} - [sct oldval])}] sct pid_deriv [sct pid_error] - sct pid_integ [expr {[sct pid_integ] + [sct pid_error]}] + sct pid_integ [expr {[sct pid_integ] + [sct pid_error] * [sct pid_ivalue]}] if { [sct pid_integ] > [sct pid_imax] } { sct pid_integ [sct pid_imax] } if { [sct pid_integ] < -[sct pid_imax] } { sct pid_integ -[sct pid_imax] } - set i_value [expr {[sct pid_ivalue] * [sct pid_integ]}] + set i_value [sct pid_integ] set pid [expr {${p_value} + ${i_value} + ${d_value}}] # pid_humidity hook code starts + if { ![hval ${tc_root}/auto] } { + set pid 0.0 + sct pid_integ 0.0 + } set sign 1 foreach node [list ${tc_root}/analog/sp1 ${tc_root}/analog/sp2] { set sign [expr -${sign}] @@ -757,6 +794,19 @@ proc ::scobj::hiden_xcs::mkDriver { sct_controller name device_class simulation_ set scobj_hpath /sics/${name} + hfactory ${scobj_hpath}/auto plain user int + hsetprop ${scobj_hpath}/auto control true + hsetprop ${scobj_hpath}/auto data true + hsetprop ${scobj_hpath}/auto mutable true + hsetprop ${scobj_hpath}/auto nxsave true + hsetprop ${scobj_hpath}/auto values 0,1 + hsetprop ${scobj_hpath}/auto oldval 0 + hset ${scobj_hpath}/auto 0 + hsetprop ${scobj_hpath}/auto klass "environment" + hsetprop ${scobj_hpath}/auto sdsinfo "::nexus::scobj::sdsinfo" + hsetprop ${scobj_hpath}/auto type "part" + hsetprop ${scobj_hpath}/auto nxalias "${name}_auto" + hfactory ${scobj_hpath}/enabled plain user int hsetprop ${scobj_hpath}/enabled read ${ns}::getValue ${scobj_hpath} read_digital {?DOUT,2} hsetprop ${scobj_hpath}/enabled read_digital ${ns}::read_digital ${scobj_hpath} @@ -1021,15 +1071,17 @@ proc ::scobj::hiden_xcs::mkDriver { sct_controller name device_class simulation_ hsetprop ${scobj_hpath}/flow/sensor pid_deriv "0" hsetprop ${scobj_hpath}/flow/sensor pid_dvalue "0.0" hsetprop ${scobj_hpath}/flow/sensor pid_error "0" - hsetprop ${scobj_hpath}/flow/sensor pid_imax "30" + hsetprop ${scobj_hpath}/flow/sensor pid_imax "50" hsetprop ${scobj_hpath}/flow/sensor pid_integ "0" hsetprop ${scobj_hpath}/flow/sensor pid_ivalue "0.1" - hsetprop ${scobj_hpath}/flow/sensor pid_pvalue "0.2" + hsetprop ${scobj_hpath}/flow/sensor pid_pvalue "0.1" hsetprop ${scobj_hpath}/flow/sensor sdsinfo "::nexus::scobj::sdsinfo" hsetprop ${scobj_hpath}/flow/sensor type "part" hsetprop ${scobj_hpath}/flow/sensor nxalias "${name}_flow_sensor" hfactory ${scobj_hpath}/flow/setpoint plain user float + hsetprop ${scobj_hpath}/flow/setpoint read ${ns}::getTarget ${scobj_hpath} rdValue {@} + hsetprop ${scobj_hpath}/flow/setpoint rdValue ${ns}::rdValue ${scobj_hpath} hsetprop ${scobj_hpath}/flow/setpoint write ${ns}::write_flow ${scobj_hpath} noResponse {} hsetprop ${scobj_hpath}/flow/setpoint noResponse ${ns}::noResponse ${scobj_hpath} hsetprop ${scobj_hpath}/flow/setpoint check ${ns}::checkrange ${scobj_hpath} @@ -1056,6 +1108,7 @@ proc ::scobj::hiden_xcs::mkDriver { sct_controller name device_class simulation_ if {[string equal -nocase "${simulation_flag}" "false"]} { ${sct_controller} poll ${scobj_hpath}/flow/sensor 1 + ${sct_controller} poll ${scobj_hpath}/flow/setpoint 1 ${sct_controller} write ${scobj_hpath}/flow/setpoint } else { ::scobj::hiden_xcs::sics_log 9 "simulation_flag=${simulation_flag} => No poll/write for hiden_xcs" @@ -1081,15 +1134,17 @@ proc ::scobj::hiden_xcs::mkDriver { sct_controller name device_class simulation_ hsetprop ${scobj_hpath}/humidity/sensor pid_deriv "0" hsetprop ${scobj_hpath}/humidity/sensor pid_dvalue "0.0" hsetprop ${scobj_hpath}/humidity/sensor pid_error "0" - hsetprop ${scobj_hpath}/humidity/sensor pid_imax "30" + hsetprop ${scobj_hpath}/humidity/sensor pid_imax "20" hsetprop ${scobj_hpath}/humidity/sensor pid_integ "0" hsetprop ${scobj_hpath}/humidity/sensor pid_ivalue "0.1" - hsetprop ${scobj_hpath}/humidity/sensor pid_pvalue "0.2" + hsetprop ${scobj_hpath}/humidity/sensor pid_pvalue "1.0" hsetprop ${scobj_hpath}/humidity/sensor sdsinfo "::nexus::scobj::sdsinfo" hsetprop ${scobj_hpath}/humidity/sensor type "part" hsetprop ${scobj_hpath}/humidity/sensor nxalias "${name}_humidity_sensor" hfactory ${scobj_hpath}/humidity/setpoint plain user float + hsetprop ${scobj_hpath}/humidity/setpoint read ${ns}::getTarget ${scobj_hpath} rdValue {@} + hsetprop ${scobj_hpath}/humidity/setpoint rdValue ${ns}::rdValue ${scobj_hpath} hsetprop ${scobj_hpath}/humidity/setpoint write ${ns}::write_humidity ${scobj_hpath} noResponse {} hsetprop ${scobj_hpath}/humidity/setpoint noResponse ${ns}::noResponse ${scobj_hpath} hsetprop ${scobj_hpath}/humidity/setpoint check ${ns}::chkrange_function ${scobj_hpath} @@ -1102,8 +1157,8 @@ proc ::scobj::hiden_xcs::mkDriver { sct_controller name device_class simulation_ hsetprop ${scobj_hpath}/humidity/setpoint data true hsetprop ${scobj_hpath}/humidity/setpoint mutable true hsetprop ${scobj_hpath}/humidity/setpoint nxsave true - hsetprop ${scobj_hpath}/humidity/setpoint lowerlimit 10 - hsetprop ${scobj_hpath}/humidity/setpoint upperlimit 90 + hsetprop ${scobj_hpath}/humidity/setpoint lowerlimit 0 + hsetprop ${scobj_hpath}/humidity/setpoint upperlimit 100 hsetprop ${scobj_hpath}/humidity/setpoint tolerance 1 hsetprop ${scobj_hpath}/humidity/setpoint permlink data_set "G[format "%02d" ${id}]SP02" hsetprop ${scobj_hpath}/humidity/setpoint @description "G[format "%02d" ${id}]SP02" @@ -1116,6 +1171,7 @@ proc ::scobj::hiden_xcs::mkDriver { sct_controller name device_class simulation_ if {[string equal -nocase "${simulation_flag}" "false"]} { ${sct_controller} poll ${scobj_hpath}/humidity/sensor 1 + ${sct_controller} poll ${scobj_hpath}/humidity/setpoint 1 ${sct_controller} write ${scobj_hpath}/humidity/setpoint } else { ::scobj::hiden_xcs::sics_log 9 "simulation_flag=${simulation_flag} => No poll/write for hiden_xcs" diff --git a/site_ansto/instrument/config/environment/temperature/sct_julabo_lh45.tcl b/site_ansto/instrument/config/environment/temperature/sct_julabo_lh45.tcl index 9dfb08ca..5c21a3e6 100644 --- a/site_ansto/instrument/config/environment/temperature/sct_julabo_lh45.tcl +++ b/site_ansto/instrument/config/environment/temperature/sct_julabo_lh45.tcl @@ -439,3 +439,88 @@ proc add_julabo_lh45 { name IP port {sensor "bath"} {_tol 5.0} {CID 1} {CTYPE T} } makesctemon $name /sics/$name/emon/monmode /sics/$name/emon/isintol /sics/$name/emon/errhandler } + +namespace eval ::scobj::julabo_lh45 { +set debug_threshold 5 +} +proc ::scobj::julabo_lh45::sics_log {debug_level debug_string} { + set catch_status [ catch { + set debug_threshold ${::scobj::julabo_lh45::debug_threshold} + if {${debug_level} >= ${debug_threshold}} { + sicslog "::scobj::julabo_lh45::${debug_string}" + } + } catch_message ] +} + +clientput "file evaluation of sct_julabo_lh45.tcl" +::scobj::julabo_lh45::sics_log 9 "file evaluation of sct_julabo_lh45.tcl" + +proc ::scobj::julabo_lh45::read_config {} { + set catch_status [ catch { + set ns "::scobj::julabo_lh45" + dict for {k v} $::config_dict { + if { [dict exists $v "implementation"] } { + if { !([dict exists $v "name"] && [dict exists $v "enabled"]) } { + continue + } + set name [dict get $v name] + set enabled [string tolower [dict get $v "enabled"]] + set implementation [dict get $v "implementation"] + if { !([dict exists $::config_dict $implementation]) } { + continue + } + set v [dict get $::config_dict $implementation] + if { !([dict exists $v "driver"]) } { + continue + } + if { [string equal -nocase [dict get $v "driver"] "julabo_lh45"] } { + if { [string equal -nocase $enabled "true" ] || [string equal -nocase $enabled "always"] } { + if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } { + set asyncqueue "null" + ${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue" + } elseif { [dict exists $v "asyncqueue"] } { + set asyncqueue [dict get $v "asyncqueue"] + } else { + if { [dict exists $v "asyncprotocol"] } { + set asyncprotocol [dict get $v "asyncprotocol"] + } else { + set asyncprotocol ${name}_protocol + MakeAsyncProtocol ${asyncprotocol} + if { [dict exists $v "terminator"] } { + ${asyncprotocol} sendterminator "[dict get $v "terminator"]" + ${asyncprotocol} replyterminator "[dict get $v "terminator"]" + } + } + set asyncqueue ${name}_queue + set IP [dict get $v ip] + set PORT [dict get $v port] + MakeAsyncQueue ${asyncqueue} ${asyncprotocol} ${IP} ${PORT} + if { [dict exists $v "timeout"] } { + ${asyncqueue} timeout "[dict get $v "timeout"]" + } + } + set arg_list [list] + foreach arg {ctrl_sensor tol id type} { + if {[dict exists $v $arg]} { + lappend arg_list "[dict get $v $arg]" + } else { + ${ns}::sics_log 9 "Missing configuration value $arg" + error "Missing configuration value $arg" + } + } + add_julabo_lh45 ${name} "aqadapter" ${asyncqueue} {*}$arg_list + } + } + } + } + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +if { [info exists ::config_dict] } { + ::scobj::julabo_lh45::read_config +} else { + ::scobj::julabo_lh45::sics_log 5 "No config dict" +} + + diff --git a/site_ansto/instrument/config/environment/temperature/sct_julabo_lh45_gen.tcl b/site_ansto/instrument/config/environment/temperature/sct_julabo_lh45_gen.tcl index aa790cec..833f8028 100644 --- a/site_ansto/instrument/config/environment/temperature/sct_julabo_lh45_gen.tcl +++ b/site_ansto/instrument/config/environment/temperature/sct_julabo_lh45_gen.tcl @@ -452,7 +452,7 @@ proc ::scobj::julabo_lh45_gen::mkDriver { sct_controller name device_class simul hsetprop ${scobj_hpath}/setpoint data true hsetprop ${scobj_hpath}/setpoint mutable true hsetprop ${scobj_hpath}/setpoint nxsave true - hsetprop ${scobj_hpath}/setpoint lowerlimit 10 + hsetprop ${scobj_hpath}/setpoint lowerlimit -20 hsetprop ${scobj_hpath}/setpoint upperlimit 90 hsetprop ${scobj_hpath}/setpoint tolerance ${tol} hsetprop ${scobj_hpath}/setpoint permlink data_set "T[format "%02d" ${id}]SP01" diff --git a/site_ansto/instrument/config/environment/temperature/sct_lakeshore_370.tcl b/site_ansto/instrument/config/environment/temperature/sct_lakeshore_370.tcl index 74233b4a..6fe63945 100644 --- a/site_ansto/instrument/config/environment/temperature/sct_lakeshore_370.tcl +++ b/site_ansto/instrument/config/environment/temperature/sct_lakeshore_370.tcl @@ -50,7 +50,7 @@ namespace eval ::scobj::[set vendor]_[set device] { proc debug_log {debug_level arg_string} { # write a timestamped string message to a log file for debugging - set debug_threshold 0 + set debug_threshold 5 if {$debug_level >= $debug_threshold} { set fd [open "[set [namespace current]::log_file]" "a"] set line "[clock format [clock seconds] -format "%T"] $arg_string" diff --git a/site_ansto/instrument/config/environment/temperature/sct_oxford_mercury.tcl b/site_ansto/instrument/config/environment/temperature/sct_oxford_mercury.tcl index 22ebad6b..67266192 100644 --- a/site_ansto/instrument/config/environment/temperature/sct_oxford_mercury.tcl +++ b/site_ansto/instrument/config/environment/temperature/sct_oxford_mercury.tcl @@ -58,7 +58,7 @@ namespace eval ::scobj::[set vendor]_[set device] { proc debug_log {debug_level arg_string} { # write a timestamped string message to a log file for debugging - set debug_threshold 0 + set debug_threshold 5 if {$debug_level >= $debug_threshold} { set fd [open "[set [namespace current]::log_file]" "a"] set line "[clock format [clock seconds] -format "%T"] $arg_string" diff --git a/site_ansto/instrument/config/hmm/hmm_configuration_common_1.tcl b/site_ansto/instrument/config/hmm/hmm_configuration_common_1.tcl index cbe97274..807fd39b 100644 --- a/site_ansto/instrument/config/hmm/hmm_configuration_common_1.tcl +++ b/site_ansto/instrument/config/hmm/hmm_configuration_common_1.tcl @@ -1471,6 +1471,26 @@ sicslist setatt ::histogram_memory::ratemap_xy_total klass detector sicslist setatt ::histogram_memory::ratemap_xy_total long_name total_maprate sicslist setatt ::histogram_memory::ratemap_xy_total mutable true +# Returns 0 If all trips acknowledged, -n if n trips unacknowledged, +n if too many acks? +::utility::macro::getset float ::histogram_memory::reset_trip {args} { + set num_trips [ SplitReply [hmm configure detector_protect_num_trip] ] + set num_acks [ SplitReply [hmm configure detector_protect_num_trip_ack] ] + set trip_cnt_diff [expr {$num_acks - $num_trips}] + if {$args == ""} { + return "reset_trip = $trip_cnt_diff" + } else { + if {$trip_cnt_diff != 0} { + hmm configure fat_detector_protect_num_trip_ack $num_trips + hmm astop + wait 2 + hmm init + } + } +} +sicslist setatt ::histogram_memory::reset_trip klass detector +sicslist setatt ::histogram_memory::reset_trip long_name reset_trip +sicslist setatt ::histogram_memory::reset_trip data false + ## # @brief Update the beam monitors when the histmem has finished counting. proc ::histogram_memory::countend_event {} { diff --git a/site_ansto/instrument/sans/config/environment/sct_antonparr_MCR500.tcl b/site_ansto/instrument/sans/config/environment/sct_antonparr_MCR500.tcl index bd93bd8c..3dae5815 100644 --- a/site_ansto/instrument/sans/config/environment/sct_antonparr_MCR500.tcl +++ b/site_ansto/instrument/sans/config/environment/sct_antonparr_MCR500.tcl @@ -33,8 +33,12 @@ proc ::scobj::antonparr_MCR500::mkDriver { speed_name torque_name tol settle } { set catch_status [ catch { # mkDriver hook code starts + if [::utility::obj_exists $speed_name] { add_rheo $speed_name $tol $settle + } + if [::utility::obj_exists $torque_name] { add_rheo $torque_name $tol $settle + } # mkDriver hook code ends } catch_message ] handle_exception ${catch_status} ${catch_message} diff --git a/site_ansto/instrument/sans/config/environment/sct_rheometer.tcl b/site_ansto/instrument/sans/config/environment/sct_rheometer.tcl index 7c2f49e7..463214f7 100644 --- a/site_ansto/instrument/sans/config/environment/sct_rheometer.tcl +++ b/site_ansto/instrument/sans/config/environment/sct_rheometer.tcl @@ -100,4 +100,5 @@ proc add_rheo {rhControl tol settle} { hfactory /sics/$rhControl/settletime plain user float hset /sics/$rhControl/settletime $settle hsetprop /sics/$rhControl timecheck 0 + hsetprop /sics/$rhControl callBack "rhCallBack /sics/$rhControl" } diff --git a/site_ansto/instrument/sans/config/motors/motor_configuration.tcl b/site_ansto/instrument/sans/config/motors/motor_configuration.tcl index 846db865..e765bdff 100644 --- a/site_ansto/instrument/sans/config/motors/motor_configuration.tcl +++ b/site_ansto/instrument/sans/config/motors/motor_configuration.tcl @@ -718,7 +718,7 @@ Motor apx $motor_driver_type [params \ axis E\ units mm\ hardlowerlim -260\ - hardupperlim 5\ + hardupperlim 45\ maxSpeed 5\ maxAccel 5\ maxDecel 5\ @@ -730,7 +730,7 @@ apx part collimator apx long_name apx apx home 0 apx softlowerlim -255 -apx softupperlim 5 +apx softupperlim 45 apx speed 5 # Sample aperture y diff --git a/site_ansto/instrument/sans/quokka_configuration.tcl b/site_ansto/instrument/sans/quokka_configuration.tcl index d558d904..8728a0f8 100644 --- a/site_ansto/instrument/sans/quokka_configuration.tcl +++ b/site_ansto/instrument/sans/quokka_configuration.tcl @@ -61,12 +61,15 @@ fileeval $cfPath(hmm)/detector.tcl fileeval $cfPath(scan)/scan.tcl fileeval $cfPath(commands)/commands.tcl fileeval $cfPath(anticollider)/anticollider.tcl -fileeval $cfPath(environment)/temperature/sct_julabo_lh45.tcl +fileeval $cfPath(environment)/temperature/sct_julabo_lh45_gen.tcl fileeval $cfPath(environment)/temperature/sct_qlink.tcl fileeval $cfPath(environment)/magneticField/sct_tsi_smc.tcl fileeval $cfPath(environment)/temperature/sct_oxford_itc.tcl fileeval $cfPath(environment)/magneticField/oxford_labview.tcl +fileeval $cfPath(environment)/magneticField/sct_oxford12tlv.tcl fileeval $cfPath(environment)/magneticField/sct_bruker_BEC1.tcl +fileeval $cfPath(environment)/magneticField/sct_bruker.tcl +fileeval $cfPath(beamline)/sct_he3_polanal.tcl fileeval $cfPath(environment)/environment.tcl fileeval $cfPath(environment)/sct_rheometer.tcl fileeval $cfPath(environment)/sct_antonparr_MCR500.tcl From bf8be461ee28317e5539b2eee6110b8df055ba80 Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Wed, 18 Feb 2015 14:46:54 +1100 Subject: [PATCH 02/10] Add in from Quokka --- .../environment/magneticField/sct_bruker.tcl | 131 ++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 site_ansto/instrument/config/environment/magneticField/sct_bruker.tcl diff --git a/site_ansto/instrument/config/environment/magneticField/sct_bruker.tcl b/site_ansto/instrument/config/environment/magneticField/sct_bruker.tcl new file mode 100644 index 00000000..e86bab65 --- /dev/null +++ b/site_ansto/instrument/config/environment/magneticField/sct_bruker.tcl @@ -0,0 +1,131 @@ +# Generated driver for bruker +# vim: ft=tcl tabstop=8 softtabstop=2 shiftwidth=2 nocindent smartindent +# + +namespace eval ::scobj::bruker { + set debug_threshold 5 +} + +proc ::scobj::bruker::debug_log {tc_root debug_level debug_string} { + set catch_status [ catch { + set debug_threshold [hgetpropval ${tc_root} debug_threshold] + if {${debug_level} >= ${debug_threshold}} { + set now [clock seconds] + set ts [clock format ${now} -format "%Y%m%d"] + set log_file_name "../log/bruker_[basename ${tc_root}]_${ts}.log" + set fd [open "${log_file_name}" "a"] + set ts [clock format ${now} -format "%T"] + puts ${fd} "${ts} ${debug_string}" + close ${fd} + } + } catch_message ] +} + +proc ::scobj::bruker::sics_log {debug_level debug_string} { + set catch_status [ catch { + set debug_threshold ${::scobj::bruker::debug_threshold} + if {${debug_level} >= ${debug_threshold}} { + sicslog "::scobj::bruker::${debug_string}" + } + } catch_message ] +} + +proc ::scobj::bruker::mkDriver { sct_controller name device_class simulation_flag ip_address tcp_port id datype tol } { + ::scobj::bruker::sics_log 9 "::scobj::bruker::mkDriver ${sct_controller} ${name} ${device_class} ${simulation_flag} ${ip_address} ${tcp_port} ${id} ${datype} ${tol}" + set ns "[namespace current]" + set catch_status [ catch { + +# mkWrapper hook code starts + add_bruker_bec1 $name $ip_address $tcp_port $tol $id $datype +# mkWrapper hook code ends + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +proc ::scobj::bruker::add_driver {name device_class simulation_flag ip_address tcp_port id datype {tol 0.1}} { + set catch_status [ catch { + ::scobj::bruker::sics_log 9 "::scobj::bruker::add_driver ${name} ${device_class} ${simulation_flag} ${ip_address} ${tcp_port} ${id} ${datype} ${tol}" + ::scobj::bruker::sics_log 9 "No sctcontroller for bruker" + ::scobj::bruker::sics_log 1 "::scobj::bruker::mkDriver sct_${name} ${name} ${device_class} ${simulation_flag} ${ip_address} ${tcp_port} ${id} ${datype} ${tol}" + ::scobj::bruker::mkDriver sct_${name} ${name} ${device_class} ${simulation_flag} ${ip_address} ${tcp_port} ${id} ${datype} ${tol} + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +namespace eval ::scobj::bruker { + namespace export debug_threshold + namespace export debug_log + namespace export sics_log + namespace export mkDriver + namespace export add_driver +} + +proc add_bruker {name ip_address tcp_port id datype {tol 0.1}} { + set simulation_flag "[string tolower [SplitReply [environment_simulation]]]" + ::scobj::bruker::add_driver ${name} "environment" ${simulation_flag} ${ip_address} ${tcp_port} ${id} ${datype} ${tol} +} + +clientput "file evaluation of sct_bruker.tcl" +::scobj::bruker::sics_log 9 "file evaluation of sct_bruker.tcl" + +proc ::scobj::bruker::read_config {} { + set catch_status [ catch { + set ns "::scobj::bruker" + dict for {k u} $::config_dict { + if { [dict exists $u "implementation"] } { + set simulation_flag "[string tolower [SplitReply [environment_simulation]]]" + set device_class "environment" + if { !([dict exists $u "name"] && [dict exists $u "enabled"]) } { + continue + } + set enabled [string tolower [dict get $u "enabled"]] + if { ! ([string equal -nocase $enabled "true" ] || [string equal -nocase $enabled "always"]) } { + continue + } + if { [dict exists $u "simulation_group"] } { + set simulation_flag [SplitReply [[string tolower [dict get $u "simulation_group"]]]] + } + if { [dict exists $u "device_class"] } { + set device_class "[dict get $u "device_class"]" + } + set name [dict get $u name] + set implementation [dict get $u "implementation"] + if { !([dict exists $::config_dict $implementation]) } { + continue + } + set v [dict get $::config_dict $implementation] + if { !([dict exists $v "driver"]) } { + continue + } + if { [string equal -nocase [dict get $v "driver"] "bruker"] } { + ::scobj::bruker::sics_log 9 "No sctcontroller for bruker" + set ip_address [dict get $v ip] + set tcp_port [dict get $v port] + set arg_list [list] + set missing_list [list] + foreach arg {id datype tol} { + if {[dict exists $u $arg]} { + lappend arg_list "[dict get $u $arg]" + } elseif {[dict exists $v $arg]} { + lappend arg_list "[dict get $v $arg]" + } else { + ${ns}::sics_log 9 "Missing configuration value $arg" + lappend missing_list $arg + } + } + if { [llength $missing_list] > 0 } { + error "$name is missing configuration values $missing_list" + } + ${ns}::mkDriver sct_${name} ${name} ${device_class} ${simulation_flag} ${ip_address} ${tcp_port} {*}$arg_list + } + } + } + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +if { [info exists ::config_dict] } { + ::scobj::bruker::read_config +} else { + ::scobj::bruker::sics_log 5 "No config dict" +} From a5498a2a77b96a9f6dcec7a55bb2984df1918eb2 Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Thu, 19 Feb 2015 09:48:38 +1100 Subject: [PATCH 03/10] Pull some changes from RELEASE-3_1 in gen_sct and *.sct --- .../config/environment/isotech_ps.sct | 2 +- .../environment/temperature/julabo_lh45.sct | 4 +- site_ansto/instrument/util/gen_sct.py | 885 +++++++++++++----- 3 files changed, 632 insertions(+), 259 deletions(-) diff --git a/site_ansto/instrument/config/environment/isotech_ps.sct b/site_ansto/instrument/config/environment/isotech_ps.sct index 585a29d4..ea3672f4 100644 --- a/site_ansto/instrument/config/environment/isotech_ps.sct +++ b/site_ansto/instrument/config/environment/isotech_ps.sct @@ -5,7 +5,7 @@ driver isotech_ps = { vendor = isotech; device = ps; protocol = std; class = environment; simulation_group = environment_simulation; - protocol_args = '"\r"'; + protocol_args = '{terminator \r}'; group = { readable = 5 mutable = true diff --git a/site_ansto/instrument/config/environment/temperature/julabo_lh45.sct b/site_ansto/instrument/config/environment/temperature/julabo_lh45.sct index 20b2f7e3..5f706bb3 100644 --- a/site_ansto/instrument/config/environment/temperature/julabo_lh45.sct +++ b/site_ansto/instrument/config/environment/temperature/julabo_lh45.sct @@ -8,7 +8,7 @@ driver julabo_lh45_gen = { simulation_group = environment_simulation add_args = '{id 1} {ctrl_sensor "bath"} {tol 5.0}'; make_args = 'id ctrl_sensor tol'; - protocol_args = '"\r"'; + protocol_args = '{terminator \r}'; # # Unnamed group has variables at device level # @@ -22,7 +22,7 @@ driver julabo_lh45_gen = { permlink = 'T.SP01'; writeable = 1; write_function = setPoint; write_command = 'out_sp_00'; driveable = sensor/'value'; - lowerlimit = 10; upperlimit = 90; tolerance = '${tol}'; + lowerlimit = -20; upperlimit = 90; tolerance = '${tol}'; } var overtemp_warnlimit = { read_command = 'in_sp_03'; diff --git a/site_ansto/instrument/util/gen_sct.py b/site_ansto/instrument/util/gen_sct.py index 3cddcfc8..52bda187 100755 --- a/site_ansto/instrument/util/gen_sct.py +++ b/site_ansto/instrument/util/gen_sct.py @@ -30,17 +30,10 @@ # import os +import re import ply.lex as lex import ply.yacc as yacc -global Verbose -global DriverDump -global CodeDump -global FunctionTypes -global DriveableFunctionTypes -global NumberOfLinesIn -global NumberOfLinesOut - states = ( ('tcl', 'exclusive'), ) @@ -63,6 +56,34 @@ DriveableFunctionTypes = [ Verbose = False DriverDump = False CodeDump = False +PrintedFileName = -1 +NumberOfLinesIn = 0 +NumberOfLinesOut = 0 +SourceFileList = [] +SourceLineList = [] + +def PrintParseError(message): + global PrintedFileName + global lexer + global SourceLineList, SourceData + curr_line = lexer.lineno + curr_file = SourceLineList[curr_line - 1][0] + if curr_file != PrintedFileName: + PrintedFileName = curr_file + SourceFile = SourceFileList[curr_file] + print "in", SourceFile + print message + print "%4d:" % SourceLineList[curr_line - 1][1], SourceData[curr_line - 1] + +def PrintPostError(message): + global PrintedFileName + global SourceLineList + curr_file = 0 + if curr_file != PrintedFileName: + PrintedFileName = curr_file + SourceFile = SourceFileList[curr_file] + print "in", SourceFile + print message # # Tokenizer: This recognizes the tokens which can be keywords, identifiers, @@ -96,6 +117,7 @@ reserved = { 'VAR' : 'VAR', 'PROPERTY' : 'PROPERTY', 'CONTROL' : 'CONTROL', + 'CONDITIONAL' : 'CONDITIONAL', 'DATA' : 'DATA', 'NXSAVE' : 'NXSAVE', 'MUTABLE' : 'MUTABLE', @@ -212,16 +234,17 @@ def t_tcl_newline(t): t.lexer.lineno += t.value.count("\n") def t_tcl_error(t): - print("Illegal tcl character '%s'" % t.value[0]) + message = "Illegal tcl character '%s'" % t.value[0] + PrintParseError(message) t.lexer.skip(1) def t_TEXT_STRING1(t): - r'\'[^\']+\'' + r'\'[^\']*\'' t.value = t.value[1:-1] return t def t_TEXT_STRING2(t): - r"\"[^\"]+\"" + r"\"[^\"]*\"" t.value = t.value[1:-1] return t @@ -240,7 +263,8 @@ def t_FLOATER(t): try: t.value = float(t.value) except ValueError: - print "Floating value invalid:", t.value + message = "Floating value invalid: " + repr(t.value) + PrintParseError(message) t.value = 0.0 return t @@ -249,7 +273,8 @@ def t_INTEGER(t): try: t.value = int(t.value) except ValueError: - print "Integer value too large:", t.value + message = "Integer value too large: " + repr(t.value) + PrintParseError(message) t.value = 0 return t @@ -270,7 +295,9 @@ def t_newline(t): t.lexer.lineno += t.value.count("\n") def t_error(t): - print("Illegal character '%s'" % t.value[0]) + message = "Illegal character '%s' at line %d" % \ + (t.value[0], t.lexer.lineno) + PrintParseError(message) t.lexer.skip(1) # @@ -430,6 +457,7 @@ def p_var_typ_ass(p): | DATA EQUALS true_false | NXSAVE EQUALS true_false | MUTABLE EQUALS true_false + | CONDITIONAL EQUALS text_string ''' p[0] = { p[1] : p[3] } @@ -532,6 +560,14 @@ def p_code(p): | CODE code_type id_or_str EQUALS LBRACE tcl_code_block RBRACE | CODE code_type id_or_str EQUALS TCL_BEG code_block TCL_END ''' + if p[3].lower() == 'preamble': + name = 'preamble' + elif p[3].lower() == 'postamble': + name = 'postamble' + elif p[3].lower() == 'mkdriver': + name = 'mkDriver' + elif p[3].lower() == 'mkwrapper': + name = 'mkWrapper' p[0] = { 'Code' : { 'name' : p[3], 'type' : p[2], 'text' : p[6] }} def p_code_type(p): @@ -585,7 +621,10 @@ def p_empty(p): pass def p_error(t): - print("Syntax error at '%s'" % t.value), t + message = "Syntax error at line %d" % lexer.lineno + message += " " + repr(t) + message += " " + repr(t.value) + PrintParseError(message) # # Utility functions @@ -598,6 +637,54 @@ def make_path(MyVar): path += MyVar['name'] return path +def generate_filename(MyDriver): + global args + old_name = "sct_%s.tcl" % MyDriver['name'] + new_name = "%s_sct.tcl" % MyDriver['name'] + if 'PathName' in MyDriver: + full_old_name = os.path.join(MyDriver['PathName'], old_name) + full_new_name = os.path.join(MyDriver['PathName'], new_name) + else: + full_old_name = old_name + full_new_name = new_name + + # This block of code generates shell commands to help the old->new rename + if Move: + fd = open("git_mv.sh", "a") + fd.write( "git mv " + full_old_name + " " + full_new_name + "\n") + fd.close() + fd = open("grep_sed.sh", "a") + fd.write( "for f in $(grep " + old_name + " instrument -Irl" + "); do\n") + fd.write( " echo ${f}\n") + fd.write( " sed -i ${f} -e 's/" + old_name + "/" + new_name + "/'\n") + fd.write( "done\n") + fd.close() + + if args.sct == "before": + MyDriver['filename'] = old_name + MyDriver['fullname'] = full_old_name + else: + MyDriver['filename'] = new_name + MyDriver['fullname'] = full_new_name + +def parse_args(arg_str): + ''' + Parse the TCL argument string into a list of identifiers (in order) plus + a map of identifier to default value (or None) returned as a 2-tuple + ''' + arg_list = re.findall(r'({[^}]+}|[A-Za-z0-9_]+)', arg_str) + arg_lst = [] + arg_map = {} + for arg in arg_list: + if arg.startswith('{'): + bits = arg[1:-1].split(None, 1) + arg_lst.append(bits[0]) + arg_map[bits[0]] = bits[1] + else: + arg_lst.append(arg) + arg_map[arg] = None + return (arg_lst, arg_map) + # # This section handles building a driver tree from the Abstract Syntax Tree # generated by the parser. The driver tree has all of the defaults and @@ -709,7 +796,8 @@ def build_variable(MyDriver, p): MyDriver['Funcs'][MyVar[func]]['type'] = func else: # TODO FIXME error message - print 'Error: Function type mismatch: var = ' + str(MyVar) + ', code = ' + str(MyDriver['Funcs'][MyVar[func]]) + ', func = ' + str(func) + message = 'Error: Function type mismatch: var = ' + str(MyVar) + ', code = ' + str(MyDriver['Funcs'][MyVar[func]]) + ', func = ' + str(func) + PrintPostError(message) MyDriver['Funcs'][MyVar[func]]['reference_count'] += 1 if 'permlink' in MyVar: device_type, node_type = MyVar['permlink'].split('.') @@ -802,6 +890,30 @@ def adjust_group(MyGroup): if Verbose: print 'post adjust_group', MyGroup +def check_func_code(MyDriver): + for name in MyDriver['Funcs']: + #print name + left_paren_count = 0 + right_paren_count = 0 + left_brack_count = 0 + right_brack_count = 0 + left_brace_count = 0 + right_brace_count = 0 + for idx, line in enumerate(MyDriver['Funcs'][name]['text']): + #print "%4d:" % (idx + 1), line + left_paren_count += line.count('(') + right_paren_count += line.count(')') + left_brack_count += line.count('[') + right_brack_count += line.count(']') + left_brace_count += line.count('{') + right_brace_count += line.count('}') + if left_paren_count != right_paren_count: + PrintPostError("Warning: Mismatched Parens in function %s (%d != %d)" % (name, left_paren_count, right_paren_count)) + if left_brack_count != right_brack_count: + PrintPostError("Warning: Mismatched Brackets in function %s (%d != %d)" % (name, left_brack_count, right_brack_count)) + if left_brace_count != right_brace_count: + PrintPostError("Warning: Mismatched Braces in function %s (%d != %d)" % (name, left_brace_count, right_brace_count)) + def build_driver(MyDriver, TheTree): if Verbose: print "TheTree:", TheTree @@ -834,7 +946,34 @@ def build_driver(MyDriver, TheTree): MyDriver[key] = item[key] for item in MyDriver['Permlink']: if len(MyDriver['Permlink'][item]) > 1: - print 'Error: duplicate permlink entries for "%s"' % item, MyDriver['Permlink'][item] + message = 'Error: duplicate permlink entries for "%s"' % item + message += " " + repr(MyDriver['Permlink'][item]) + PrintPostError(message) + if 'add_args' in MyDriver: + MyDriver['add_args_lst'], MyDriver['add_args_map'] = parse_args(MyDriver['add_args']) + if Verbose: + print "ADD_ARGS:", MyDriver['add_args'] + arg_map = MyDriver['add_args_map'] + for arg in arg_map: + print ' %s:' % arg, arg_map[arg] + if 'make_args' in MyDriver: + MyDriver['make_args_lst'], MyDriver['make_args_map'] = parse_args(MyDriver['make_args']) + if Verbose: + print "MAKE_ARGS:", MyDriver['make_args'] + arg_map = MyDriver['make_args_map'] + for arg in arg_map: + print ' %s:' % arg, arg_map[arg] + if 'protocol_args' in MyDriver: + MyDriver['protocol_args_lst'], MyDriver['protocol_args_map'] = parse_args(MyDriver['protocol_args']) + if Verbose: + print "PROTOCOL_ARGS:", MyDriver['protocol_args'] + arg_map = MyDriver['protocol_args_map'] + for arg in arg_map: + print ' %s:' % arg, arg_map[arg] + if 'add_args_lst' in MyDriver and 'make_args_lst' in MyDriver: + if MyDriver['add_args_lst'] != MyDriver['make_args_lst']: + print "Add_Args:", MyDriver['add_args_lst'] + print "Make_Args:", MyDriver['make_args_lst'] if Verbose: print "MyDriver:", MyDriver # @@ -872,10 +1011,10 @@ def dump_driver_groups(groups, indent): if Comment in groups[item]: print indent + ' # %s = \'%s\'' % (Comment, groups[item][Comment]) for subitem in sorted([x for x in groups[item] if not x in Deferred]): - print indent + ' ', subitem, '=', groups[item][subitem] + print indent + ' ', subitem, '= \'%s\'' % groups[item][subitem] if 'GroupProperty' in groups[item]: for subitem in groups[item]['GroupProperty']: - print indent + ' GroupProperty', subitem, '=', groups[item]['GroupProperty'][subitem] + print indent + ' GroupProperty', subitem, '= \'%s\'' % groups[item]['GroupProperty'][subitem] dump_driver_vars(groups[item]['Vars'], indent) dump_driver_groups(groups[item]['Groups'], indent + ' ') print indent + '}' @@ -893,6 +1032,12 @@ def dump_driver_funcs(funcs): def dump_driver(MyDriver): print 'DRIVER ' + MyDriver['name'] + ' = {' Comments = ['PathName', 'Permlink'] + Comments += ['add_args_lst'] + Comments += ['add_args_map'] + Comments += ['make_args_lst'] + Comments += ['make_args_map'] + Comments += ['protocol_args_lst'] + Comments += ['protocol_args_map'] Deferred = ['Groups', 'Funcs', 'Deferred', 'name'] + Comments for Comment in sorted(Comments): if Comment in MyDriver: @@ -924,21 +1069,29 @@ def put_preamble(MyDriver): txt += ['namespace eval %s {' % MyDriver['namespace']] txt += [' set debug_threshold %s' % str( MyDriver['debug_threshold'])] if len(MyDriver['Permlink']) > 0: - if 'make_args' in MyDriver and 'id' in MyDriver['make_args'].split(): + if 'make_args_lst' in MyDriver and 'id' in MyDriver['make_args_lst']: pass else: txt += [' if { ![info exists ::scobj::permlink_device_counter]} {'] txt += [' set ::scobj::permlink_device_counter 0'] txt += [' }'] + func = 'preamble' + if func in MyDriver['Funcs']: + txt += ['# %s hook code starts' % func] + txt += MyDriver['Funcs'][func]['text'] + txt += ['# %s hook code ends' % func] txt += ['}'] txt += [''] txt += ['proc %s::debug_log {tc_root debug_level debug_string} {' % MyDriver['namespace']] txt += [' set catch_status [ catch {'] txt += [' set debug_threshold [hgetpropval ${tc_root} debug_threshold]'] txt += [' if {${debug_level} >= ${debug_threshold}} {'] - txt += [' set fd [open "../log/%s_[basename ${tc_root}].log" "a"]' % MyDriver['name']] - txt += [' set line "[clock format [clock seconds] -format "%T"] ${debug_string}"'] - txt += [' puts ${fd} "${line}"'] + txt += [' set now [clock seconds]'] + txt += [' set ts [clock format ${now} -format "%Y%m%d"]'] + txt += [' set log_file_name "../log/%s_[basename ${tc_root}]_${ts}.log"' % MyDriver['name']] + txt += [' set fd [open "${log_file_name}" "a"]'] + txt += [' set ts [clock format ${now} -format "%T"]'] + txt += [' puts ${fd} "${ts} ${debug_string}"'] txt += [' close ${fd}'] txt += [' }'] txt += [' } catch_message ]'] @@ -1158,7 +1311,12 @@ def put_checkstatus_function(MyDriver, func): txt += ['# %s hook code goes here' % func] txt += [' if {[sct driving]} {'] txt += [' set sp "[sct target]"'] - txt += [' set pv "[hval ${tc_root}/[sct driveable]]"'] + txt += [' if {[hpropexists [sct] simulated] && [sct simulated] == "true"} {'] + txt += [' set pv "${sp}"'] + txt += [' hupdateif ${tc_root}/[sct driveable] ${sp}'] + txt += [' } else {'] + txt += [' set pv "[hval ${tc_root}/[sct driveable]]"'] + txt += [' }'] txt += [' if { abs(${pv} - ${sp}) <= [sct tolerance] } {'] txt += [' if { [hpropexists [sct] settle_time] } {'] txt += [' if { [hpropexists [sct] settle_time_start] } {'] @@ -1217,14 +1375,14 @@ def put_pid_function(MyDriver, func): txt += [' set p_value [expr {[sct pid_pvalue] * [sct pid_error]}]'] txt += [' set d_value [expr {[sct pid_dvalue] * (${pv} - [sct oldval])}]'] txt += [' sct pid_deriv [sct pid_error]'] - txt += [' sct pid_integ [expr {[sct pid_integ] + [sct pid_error]}]'] + txt += [' sct pid_integ [expr {[sct pid_integ] + [sct pid_error] * [sct pid_ivalue]}]'] txt += [' if { [sct pid_integ] > [sct pid_imax] } {'] txt += [' sct pid_integ [sct pid_imax]'] txt += [' }'] txt += [' if { [sct pid_integ] < -[sct pid_imax] } {'] txt += [' sct pid_integ -[sct pid_imax]'] txt += [' }'] - txt += [' set i_value [expr {[sct pid_ivalue] * [sct pid_integ]}]'] + txt += [' set i_value [sct pid_integ]'] txt += [' set pid [expr {${p_value} + ${i_value} + ${d_value}}]'] if func in MyDriver['Funcs'] and len(MyDriver['Funcs'][func]['text']) > 0: txt += ['# %s hook code starts' % func] @@ -1239,156 +1397,201 @@ def put_pid_function(MyDriver, func): txt += ['}'] emit(txt) -def put_group(MyDriver, MyGroup): +def put_var(MyDriver, MyGroup, MyVar): readable_or_writeable = False txt = [] + postfix = [] + if MyGroup['name']: + nodename = MyGroup['path'] + '/' + MyVar['name'] + else: + nodename = MyVar['name'] + + # Check driveable attributes are present if required + if 'driveable' in MyVar and MyVar['driveable']: + for attr in ('lowerlimit', 'upperlimit', 'tolerance'): + if attr not in MyVar: + msg = 'Driveable: %s does not have required attribute: %s' % (nodename, attr) + print 'Warning:', msg + txt += [' # Warning: ' + msg] + # Check PID attributes are present if required + if 'pid_function' in MyVar: + for attr in ('pid_pvalue', + 'pid_ivalue', + 'pid_dvalue', + 'pid_imax', + 'pid_error', + 'pid_deriv', + 'pid_integ', + ): + if attr not in MyVar['Property']: + msg = 'PID: %s does not have required attribute: %s' % (nodename, attr) + print 'Warning:', msg + txt += [' # Warning: ' + msg] + + txt += [' hfactory ${scobj_hpath}/%s plain %s %s' % (nodename, MyVar['priv'], MyVar['type'])] + if MyVar['readable'] > 0: + readable_or_writeable = True + fetch_func = MyVar['fetch_function'] + if fetch_func == 'none': + fetch_func = 'getValue' + read_func = MyVar['read_function'] + if 'read_command' in MyVar: + read_command = MyVar['read_command'] + else: + read_command = '' + txt += [' hsetprop ${scobj_hpath}/%s read ${ns}::%s ${scobj_hpath} %s {%s}' % (nodename, fetch_func, read_func, read_command)] + txt += [' hsetprop ${scobj_hpath}/%s %s ${ns}::%s ${scobj_hpath}' % (nodename, read_func, read_func)] + if MyVar['writeable'] > 0 or MyVar['driveable']: + readable_or_writeable = True + check_func = MyVar['check_function'] + checkrange_func = MyVar['checkrange_function'] + write_func = MyVar['write_function'] + if 'write_command' in MyVar: + write_command = MyVar['write_command'] + else: + write_command = '' + txt += [' hsetprop ${scobj_hpath}/%s write ${ns}::%s ${scobj_hpath} %s {%s}' % (nodename, write_func, check_func, write_command)] + txt += [' hsetprop ${scobj_hpath}/%s %s ${ns}::%s ${scobj_hpath}' % (nodename, check_func, check_func)] + txt += [' hsetprop ${scobj_hpath}/%s check ${ns}::%s ${scobj_hpath}' % (nodename, checkrange_func)] + if MyVar['driveable']: + halt_func = MyVar['halt_function'] + checklimits_func = MyVar['checklimits_function'] + checkstatus_func = MyVar['checkstatus_function'] + txt += [' hsetprop ${scobj_hpath}/%s driving 0' % nodename] + txt += [' hsetprop ${scobj_hpath}/%s checklimits ${ns}::%s ${scobj_hpath}' % (nodename, checklimits_func)] + txt += [' hsetprop ${scobj_hpath}/%s checkstatus ${ns}::%s ${scobj_hpath}' % (nodename, checkstatus_func)] + txt += [' hsetprop ${scobj_hpath}/%s halt ${ns}::%s ${scobj_hpath}' % (nodename, halt_func)] + txt += [' hsetprop ${scobj_hpath}/%s driveable %s' % (nodename, MyVar['driveable'])] + if 'control' in MyVar: + txt += [' hsetprop ${scobj_hpath}/%s control %s' % (nodename, MyVar['control'])] + if 'data' in MyVar: + txt += [' hsetprop ${scobj_hpath}/%s data %s' % (nodename, MyVar['data'])] + if 'mutable' in MyVar: + txt += [' hsetprop ${scobj_hpath}/%s mutable %s' % (nodename, MyVar['mutable'])] + if 'nxsave' in MyVar: + txt += [' hsetprop ${scobj_hpath}/%s nxsave %s' % (nodename, MyVar['nxsave'])] + if 'lowerlimit' in MyVar: + txt += [' hsetprop ${scobj_hpath}/%s lowerlimit %s' % (nodename, MyVar['lowerlimit'])] + if 'upperlimit' in MyVar: + txt += [' hsetprop ${scobj_hpath}/%s upperlimit %s' % (nodename, MyVar['upperlimit'])] + if 'tolerance' in MyVar: + txt += [' hsetprop ${scobj_hpath}/%s tolerance %s' % (nodename, MyVar['tolerance'])] + if 'units' in MyVar: + txt += [' hsetprop ${scobj_hpath}/%s units %s' % (nodename, MyVar['units'])] + if 'allowed' in MyVar: + txt += [' hsetprop ${scobj_hpath}/%s values %s' % (nodename, MyVar['allowed'])] + if 'permlink' in MyVar: + device_type, node_type = MyVar['permlink'].split('.') + if device_type.startswith("#"): + if 'make_args_lst' in MyDriver and 'permlink' in MyDriver['make_args_lst']: + idx = int(device_type[1:]) + device_type = '[string index ${permlink} %d]' % idx + else: + message = 'Error: permlink required in make_ags' + PrintPostError(message) + if 'make_args_lst' in MyDriver and 'id' in MyDriver['make_args_lst']: + permlink = device_type + '[format "%02d" ${id}]' + node_type + else: + permlink = device_type + '${permlink_device_number}' + node_type + txt += [' hsetprop ${scobj_hpath}/%s permlink data_set "%s"' % (nodename, permlink)] + txt += [' hsetprop ${scobj_hpath}/%s @description "%s"' % (nodename, permlink)] + if 'value' in MyVar: + txt += [' hsetprop ${scobj_hpath}/%s oldval %s' % (nodename, MyVar['value'])] + txt += [' hset ${scobj_hpath}/%s %s' % (nodename, MyVar['value'])] + else: + if MyVar['type'] == 'none': + pass + elif MyVar['type'] == 'int': + txt += [' hsetprop ${scobj_hpath}/%s oldval 0' % nodename] + elif MyVar['type'] == 'float': + txt += [' hsetprop ${scobj_hpath}/%s oldval 0.0' % nodename] + else: + txt += [' hsetprop ${scobj_hpath}/%s oldval UNKNOWN' % nodename] + for key in sorted(MyVar['Property']): + txt += [' hsetprop ${scobj_hpath}/%s %s "%s"' % (nodename, key, MyVar['Property'][key])] + # Generate __ at runtime for nxalias + if 'nxalias' not in MyVar['Property']: + nxalias = '${name}_' + make_path(MyVar) + txt += [' hsetprop ${scobj_hpath}/%s nxalias "%s"' % (nodename, nxalias)] + + if readable_or_writeable: + txt += [''] + txt += [' if {[string equal -nocase "${simulation_flag}" "false"]} {'] + if MyVar['readable'] > 0: + poll_period = MyVar['readable'] + if poll_period < 1: + poll_period = 1 + if poll_period > 3600: + poll_period = 3600 + txt += [' ${sct_controller} poll ${scobj_hpath}/%s %s' % (nodename, poll_period)] + if MyVar['writeable'] > 0 or MyVar['driveable']: + txt += [' ${sct_controller} write ${scobj_hpath}/%s' % nodename] + if MyVar['driveable']: + # Generate __ at runtime for driveable + driveable = '${name}_' + make_path(MyVar) + postfix += [' ansto_makesctdrive %s ${scobj_hpath}/%s ${scobj_hpath}/%s ${sct_controller}' % (driveable, nodename, MyVar['driveable'])] + txt += [' hsetprop ${scobj_hpath}/%s simulated false' % nodename] + txt += [' } else {'] + txt += [' %s::sics_log 9 "simulation_flag=${simulation_flag} => No poll/write for %s"' % (MyDriver['namespace'], MyDriver['name'])] + txt += [' hsetprop ${scobj_hpath}/%s simulated true' % nodename] + txt += [' }'] + + if 'conditional' in MyVar: + for idx, line in enumerate(txt): + if len(line) > 0: + txt[idx] = ' ' + line + txt.insert(0, ' if {%s} {' % MyVar['conditional']) + txt.append(' }') + if len(postfix) > 0: + for idx, line in enumerate(postfix): + if len(line) > 0: + postfix[idx] = ' ' + line + postfix.insert(0, ' if {%s} {' % MyVar['conditional']) + postfix.append(' }') + + return (txt, postfix) + +def put_group(MyDriver, MyGroup): + txt = [] + dfr = [] if MyGroup['name']: txt += [''] txt += [' hfactory ${scobj_hpath}/%s plain spy none' % MyGroup['path']] - if 'GroupProperty' in MyGroup: - for key in sorted(MyGroup['GroupProperty']): - txt += [' hsetprop ${scobj_hpath}/%s %s "%s"' % (MyGroup['path'], key, MyGroup['GroupProperty'][key])] - groupname = MyGroup['path'] + '/' else: - groupname = '' + pass + for var in sorted(MyGroup['Vars']): txt += [''] MyVar = MyGroup['Vars'][var] - nodename = groupname + MyVar['name'] - # Check driveable attributes are present if required - if 'driveable' in MyVar and MyVar['driveable']: - for attr in ('lowerlimit', 'upperlimit', 'tolerance'): - if attr not in MyVar: - msg = 'Driveable: %s does not have required attribute: %s' % (nodename, attr) - print 'Warning:', msg - txt += [' # Warning: ' + msg] - # Check PID attributes are present if required - if 'pid_function' in MyVar: - for attr in ('pid_pvalue', - 'pid_ivalue', - 'pid_dvalue', - 'pid_imax', - 'pid_error', - 'pid_deriv', - 'pid_integ', - ): - if attr not in MyVar['Property']: - msg = 'PID: %s does not have required attribute: %s' % (nodename, attr) - print 'Warning:', msg - txt += [' # Warning: ' + msg] - txt += [' hfactory ${scobj_hpath}/%s plain %s %s' % (nodename, MyVar['priv'], MyVar['type'])] - if MyVar['readable'] > 0: - readable_or_writeable = True - fetch_func = MyVar['fetch_function'] - if fetch_func == 'none': - fetch_func = 'getValue' - read_func = MyVar['read_function'] - read_command = MyVar['read_command'] - txt += [' hsetprop ${scobj_hpath}/%s read ${ns}::%s ${scobj_hpath} %s {%s}' % (nodename, fetch_func, read_func, read_command)] - txt += [' hsetprop ${scobj_hpath}/%s %s ${ns}::%s ${scobj_hpath}' % (nodename, read_func, read_func)] - if MyVar['writeable'] > 0 or MyVar['driveable']: - readable_or_writeable = True - check_func = MyVar['check_function'] - checkrange_func = MyVar['checkrange_function'] - write_func = MyVar['write_function'] - if 'write_command' in MyVar: - write_command = MyVar['write_command'] - else: - write_command = '' - txt += [' hsetprop ${scobj_hpath}/%s write ${ns}::%s ${scobj_hpath} %s {%s}' % (nodename, write_func, check_func, write_command)] - txt += [' hsetprop ${scobj_hpath}/%s %s ${ns}::%s ${scobj_hpath}' % (nodename, check_func, check_func)] - txt += [' hsetprop ${scobj_hpath}/%s check ${ns}::%s ${scobj_hpath}' % (nodename, checkrange_func)] - if MyVar['driveable']: - halt_func = MyVar['halt_function'] - checklimits_func = MyVar['checklimits_function'] - checkstatus_func = MyVar['checkstatus_function'] - txt += [' hsetprop ${scobj_hpath}/%s driving 0' % nodename] - txt += [' hsetprop ${scobj_hpath}/%s checklimits ${ns}::%s ${scobj_hpath}' % (nodename, checklimits_func)] - txt += [' hsetprop ${scobj_hpath}/%s checkstatus ${ns}::%s ${scobj_hpath}' % (nodename, checkstatus_func)] - txt += [' hsetprop ${scobj_hpath}/%s halt ${ns}::%s ${scobj_hpath}' % (nodename, halt_func)] - txt += [' hsetprop ${scobj_hpath}/%s driveable %s' % (nodename, MyVar['driveable'])] - if 'control' in MyVar: - txt += [' hsetprop ${scobj_hpath}/%s control %s' % (nodename, MyVar['control'])] - if 'data' in MyVar: - txt += [' hsetprop ${scobj_hpath}/%s data %s' % (nodename, MyVar['data'])] - if 'mutable' in MyVar: - txt += [' hsetprop ${scobj_hpath}/%s mutable %s' % (nodename, MyVar['mutable'])] - if 'nxsave' in MyVar: - txt += [' hsetprop ${scobj_hpath}/%s nxsave %s' % (nodename, MyVar['nxsave'])] - if 'lowerlimit' in MyVar: - txt += [' hsetprop ${scobj_hpath}/%s lowerlimit %s' % (nodename, MyVar['lowerlimit'])] - if 'upperlimit' in MyVar: - txt += [' hsetprop ${scobj_hpath}/%s upperlimit %s' % (nodename, MyVar['upperlimit'])] - if 'tolerance' in MyVar: - txt += [' hsetprop ${scobj_hpath}/%s tolerance %s' % (nodename, MyVar['tolerance'])] - if 'units' in MyVar: - txt += [' hsetprop ${scobj_hpath}/%s units %s' % (nodename, MyVar['units'])] - if 'allowed' in MyVar: - txt += [' hsetprop ${scobj_hpath}/%s values %s' % (nodename, MyVar['allowed'])] - if 'permlink' in MyVar: - device_type, node_type = MyVar['permlink'].split('.') - if device_type.startswith("#"): - if 'make_args' in MyDriver and 'permlink' in MyDriver['make_args'].split(): - idx = int(device_type[1:]) - device_type = '[string index ${permlink} %d]' % idx - else: - print 'Error: permlink required in make_ags' - if 'make_args' in MyDriver and 'id' in MyDriver['make_args'].split(): - permlink = device_type + '[format "%02d" ${id}]' + node_type - else: - permlink = device_type + '${permlink_device_number}' + node_type - txt += [' hsetprop ${scobj_hpath}/%s permlink data_set "%s"' % (nodename, permlink)] - txt += [' hsetprop ${scobj_hpath}/%s @description "%s"' % (nodename, permlink)] - if 'value' in MyVar: - txt += [' hsetprop ${scobj_hpath}/%s oldval %s' % (nodename, MyVar['value'])] - txt += [' hset ${scobj_hpath}/%s %s' % (nodename, MyVar['value'])] - else: - if MyVar['type'] == 'none': - pass - elif MyVar['type'] == 'int': - txt += [' hsetprop ${scobj_hpath}/%s oldval 0' % nodename] - elif MyVar['type'] == 'float': - txt += [' hsetprop ${scobj_hpath}/%s oldval 0.0' % nodename] - else: - txt += [' hsetprop ${scobj_hpath}/%s oldval UNKNOWN' % nodename] - for key in sorted(MyVar['Property']): - txt += [' hsetprop ${scobj_hpath}/%s %s "%s"' % (nodename, key, MyVar['Property'][key])] - # Generate __ at runtime for nxalias - if 'nxalias' not in MyVar['Property']: - nxalias = '${name}_' + make_path(MyVar) - txt += [' hsetprop ${scobj_hpath}/%s nxalias "%s"' % (nodename, nxalias)] - if not MyGroup['name']: + infix, postfix = put_var(MyDriver, MyGroup, MyVar) + txt += infix + dfr += postfix + + if MyGroup['name']: + if 'GroupProperty' in MyGroup: + for key in sorted(MyGroup['GroupProperty']): + txt += [' hsetprop ${scobj_hpath}/%s %s "%s"' % (MyGroup['path'], key, MyGroup['GroupProperty'][key])] + else: if 'GroupProperty' in MyGroup: txt += [''] for key in sorted(MyGroup['GroupProperty']): txt += [' hsetprop ${scobj_hpath} %s "%s"' % (key, MyGroup['GroupProperty'][key])] - if readable_or_writeable: - txt += [''] - txt += [' if {[string equal -nocase "${simulation_flag}" "false"]} {'] - for var in sorted(MyGroup['Vars']): - MyVar = MyGroup['Vars'][var] - nodename = groupname + MyVar['name'] - if MyVar['readable'] > 0: - poll_period = MyVar['readable'] - if poll_period < 1: - poll_period = 1 - if poll_period > 3600: - poll_period = 3600 - txt += [' ${sct_controller} poll ${scobj_hpath}/%s %s' % (nodename, poll_period)] - for var in sorted(MyGroup['Vars']): - MyVar = MyGroup['Vars'][var] - nodename = groupname + MyVar['name'] - if MyVar['writeable'] > 0 or MyVar['driveable']: - txt += [' ${sct_controller} write ${scobj_hpath}/%s' % nodename] - if MyVar['driveable']: - # Generate __ at runtime for driveable - driveable = '${name}_' + make_path(MyVar) - MyDriver['Deferred'] += ['ansto_makesctdrive %s ${scobj_hpath}/%s ${scobj_hpath}/%s ${sct_controller}' % (driveable, nodename, MyVar['driveable'])] - txt += [' } else {'] - txt += [' %s::sics_log 9 "simulation_flag=${simulation_flag} => No poll/write for %s"' % (MyDriver['namespace'], MyDriver['name'])] - txt += [' }'] + for grp in sorted(MyGroup['Groups']): txt += put_group(MyDriver, MyGroup['Groups'][grp]) + + txt += dfr + + if 'conditional' in MyGroup: + for idx, line in enumerate(txt): + if len(line) > 0: + txt[idx] = ' ' + line + if len(txt[0]) == 0: + txt.pop(0) + txt.insert(0, ' if {%s} {' % MyGroup['conditional']) + txt.insert(0, '') + txt.append(' }') + return txt def put_mkDriver(MyDriver): @@ -1398,8 +1601,8 @@ def put_mkDriver(MyDriver): else: line = 'proc %s::mkDriver { sct_controller name device_class simulation_flag ip_address tcp_port } {' % (MyDriver['namespace']) txt += [line] - if 'make_args' in MyDriver: - make_args = ' '.join(["${%s}"%arg for arg in MyDriver['make_args'].split()]) + if 'make_args_lst' in MyDriver: + make_args = ' '.join(["${%s}"%arg for arg in MyDriver['make_args_lst']]) txt += [' %s::sics_log 9 "%s::mkDriver ${sct_controller} ${name} ${device_class} ${simulation_flag} ${ip_address} ${tcp_port} %s"' % (MyDriver['namespace'], MyDriver['namespace'], make_args)] else: txt += [' %s::sics_log 9 "%s::mkDriver ${sct_controller} ${name} ${device_class} ${simulation_flag} ${ip_address} ${tcp_port}"' % (MyDriver['namespace'], MyDriver['namespace'])] @@ -1413,7 +1616,7 @@ def put_mkDriver(MyDriver): txt += ['# %s hook code ends' % func] else: if len(MyDriver['Permlink']) > 0: - if 'make_args' in MyDriver and 'id' in MyDriver['make_args'].split(): + if 'make_args_lst' in MyDriver and 'id' in MyDriver['make_args_lst']: pass else: txt += [' set permlink_device_number [format "%02d" [incr ::scobj::permlink_device_counter]]'] @@ -1425,6 +1628,7 @@ def put_mkDriver(MyDriver): ms_line = ' MakeSICSObj ${name} SCT_OBJECT' txt += [ms_line] txt += [''] + txt += [' sicslist setatt ${name} driver %s' % MyDriver['name']] txt += [' sicslist setatt ${name} klass ${device_class}'] txt += [' sicslist setatt ${name} long_name ${name}'] if 'DriverProperty' in MyDriver: @@ -1436,6 +1640,7 @@ def put_mkDriver(MyDriver): for group in sorted(MyDriver['Groups']): txt += put_group(MyDriver, MyDriver['Groups'][group]) + txt += [' hsetprop ${scobj_hpath} driver %s' % MyDriver['name']] txt += [' hsetprop ${scobj_hpath} klass ${device_class}'] txt += [' hsetprop ${scobj_hpath} data true'] txt += [' hsetprop ${scobj_hpath} debug_threshold %s' % str(MyDriver['debug_threshold'])] @@ -1456,7 +1661,7 @@ def put_mkDriver(MyDriver): txt += ['}'] emit(txt) -def put_postamble(MyDriver): +def put_add_driver(MyDriver): txt = [''] if 'add_args' in MyDriver: line = 'proc %s::add_driver {name device_class simulation_flag ip_address tcp_port %s} {' % (MyDriver['namespace'], MyDriver['add_args']) @@ -1464,8 +1669,8 @@ def put_postamble(MyDriver): line = 'proc %s::add_driver {name device_class simulation_flag ip_address tcp_port} {' % (MyDriver['namespace']) txt += [line] txt += [' set catch_status [ catch {'] - if 'make_args' in MyDriver: - make_args = ' '.join(["${%s}"%arg for arg in MyDriver['make_args'].split()]) + if 'make_args_lst' in MyDriver: + make_args = ' '.join(["${%s}"%arg for arg in MyDriver['make_args_lst']]) txt += [' %s::sics_log 9 "%s::add_driver ${name} ${device_class} ${simulation_flag} ${ip_address} ${tcp_port} %s"' % (MyDriver['namespace'], MyDriver['namespace'], make_args)] else: txt += [' %s::sics_log 9 "%s::add_driver ${name} ${device_class} ${simulation_flag} ${ip_address} ${tcp_port}"' % (MyDriver['namespace'], MyDriver['namespace'])] @@ -1478,18 +1683,29 @@ def put_postamble(MyDriver): txt += [' makesctcontroller sct_${name} aqadapter ${tcp_port}'] txt += [' } else {'] if 'protocol_args' in MyDriver: - protocol_args = MyDriver['protocol_args'].replace('\\', '\\\\').replace('"', '\\"') - txt += [' %s::sics_log 9 "makesctcontroller sct_${name} %s ${ip_address}:${tcp_port} %s"' % (MyDriver['namespace'], MyDriver['protocol'], protocol_args)] - txt += [' makesctcontroller sct_${name} %s ${ip_address}:${tcp_port} %s' % (MyDriver['protocol'], MyDriver['protocol_args'])] + protocol_args = [] + for arg in MyDriver['protocol_args_lst']: + if 'add_args_lst' in MyDriver and arg in MyDriver['add_args_lst']: + protocol_args.append('${%s}' % arg) + elif arg in MyDriver['protocol_args_map'] and MyDriver['protocol_args_map'][arg] is not None: + protocol_args.append(MyDriver['protocol_args_map'][arg]) + else: + PrintPostError('Protocol arg %s is not in add_args and has no default' % arg) + tmp = ' '.join(protocol_args).replace('\\', '\\\\').replace('"', '\\"') + txt += [' %s::sics_log 9 "makesctcontroller sct_${name} %s ${ip_address}:${tcp_port} %s"' % (MyDriver['namespace'], MyDriver['protocol'], tmp)] + tmp = ' '.join(protocol_args) + txt += [' makesctcontroller sct_${name} %s ${ip_address}:${tcp_port} %s' % (MyDriver['protocol'], tmp)] else: txt += [' %s::sics_log 9 "makesctcontroller sct_${name} %s ${ip_address}:${tcp_port}"' % (MyDriver['namespace'], MyDriver['protocol'])] txt += [' makesctcontroller sct_${name} %s ${ip_address}:${tcp_port}' % MyDriver['protocol']] txt += [' }'] txt += [' } else {'] - txt += [' %s::sics_log 9 "simulation_flag={simulation_flag} => No sctcontroller for %s"' % (MyDriver['namespace'], MyDriver['name'])] + txt += [' %s::sics_log 9 "simulation_flag=${simulation_flag} => Null sctcontroller for %s"' % (MyDriver['namespace'], MyDriver['name'])] + txt += [' %s::sics_log 9 "makesctcontroller sct_${name} aqadapter NULL"' % MyDriver['namespace']] + txt += [' makesctcontroller sct_${name} aqadapter NULL'] txt += [' }'] - if 'make_args' in MyDriver: - make_args = ' '.join(["${%s}"%arg for arg in MyDriver['make_args'].split()]) + if 'make_args_lst' in MyDriver: + make_args = ' '.join(["${%s}"%arg for arg in MyDriver['make_args_lst']]) txt += [' %s::sics_log 1 "%s::mkDriver sct_${name} ${name} ${device_class} ${simulation_flag} ${ip_address} ${tcp_port} %s"' % (MyDriver['namespace'], MyDriver['namespace'], make_args)] txt += [' %s::mkDriver sct_${name} ${name} ${device_class} ${simulation_flag} ${ip_address} ${tcp_port} %s' % (MyDriver['namespace'], make_args)] else: @@ -1501,13 +1717,21 @@ def put_postamble(MyDriver): txt += [' } catch_message ]'] txt += [' handle_exception ${catch_status} ${catch_message}'] txt += ['}'] - txt += [''] + emit(txt) + +def put_postamble(MyDriver): + txt = [''] txt += ['namespace eval %s {' % MyDriver['namespace']] txt += [' namespace export debug_threshold'] txt += [' namespace export debug_log'] txt += [' namespace export sics_log'] txt += [' namespace export mkDriver'] txt += [' namespace export add_driver'] + func = 'postamble' + if func in MyDriver['Funcs']: + txt += ['# %s hook code starts' % func] + txt += MyDriver['Funcs'][func]['text'] + txt += ['# %s hook code ends' % func] txt += ['}'] txt += [''] if 'add_args' in MyDriver: @@ -1516,15 +1740,17 @@ def put_postamble(MyDriver): line = 'proc add_%s {name ip_address tcp_port} {' % MyDriver['name'] txt += [line] txt += [' set simulation_flag "[string tolower [SplitReply [%s]]]"' % MyDriver['simulation_group']] - line = ' %s::add_driver ${name} "%s" "${simulation_flag}" ${ip_address} ${tcp_port}' % (MyDriver['namespace'], MyDriver['class']) - if 'add_args' in MyDriver: - for arg in MyDriver['add_args'].split(): - line += ' "${%s}"' % arg + line = ' %s::add_driver ${name} "%s"' % (MyDriver['namespace'], MyDriver['class']) + for arg in ['simulation_flag', 'ip_address', 'tcp_port']: + line += ' ${%s}' % arg + if 'add_args_lst' in MyDriver: + for arg in MyDriver['add_args_lst']: + line += ' ${%s}' % arg txt += [line] txt += ['}'] txt += [''] - txt += ['clientput "file evaluation of sct_%s.tcl"' % MyDriver['name']] - txt += ['%s::sics_log 9 "file evaluation of sct_%s.tcl"' % (MyDriver['namespace'], MyDriver['name'])] + txt += ['clientput "file evaluation of %s"' % MyDriver['filename']] + txt += ['%s::sics_log 9 "file evaluation of %s"' % (MyDriver['namespace'], MyDriver['filename'])] emit(txt) def put_read_config(MyDriver): @@ -1559,42 +1785,96 @@ def put_read_config(MyDriver): txt += [' continue'] txt += [' }'] txt += [' if { [string equal -nocase [dict get $v "driver"] "%s"] } {' % MyDriver['name']] - txt += [' if { ![string equal -nocase "${simulation_flag}" "false"] } {'] - txt += [' set asyncqueue "null"'] - txt += [' ${ns}::sics_log 9 "simulation_flag=${simulation_flag} => using null asyncqueue"'] - txt += [' } elseif { [dict exists $v "asyncqueue"] } {'] - txt += [' set asyncqueue [dict get $v "asyncqueue"]'] - txt += [' if { [string equal -nocase ${asyncqueue} "sct"] } {'] - txt += [' set ip_address [dict get $v ip]'] - txt += [' set tcp_port [dict get $v port]'] - txt += [' }'] - txt += [' } else {'] - txt += [' if { [dict exists $v "asyncprotocol"] } {'] - txt += [' set asyncprotocol [dict get $v "asyncprotocol"]'] - txt += [' } else {'] - txt += [' set asyncprotocol ${name}_protocol'] - txt += [' MakeAsyncProtocol ${asyncprotocol}'] - txt += [' if { [dict exists $v "terminator"] } {'] - txt += [' ${asyncprotocol} sendterminator "[dict get $v "terminator"]"'] - txt += [' ${asyncprotocol} replyterminator "[dict get $v "terminator"]"'] - txt += [' }'] - txt += [' }'] - txt += [' set asyncqueue ${name}_queue'] - txt += [' set ip_address [dict get $v ip]'] - txt += [' set tcp_port [dict get $v port]'] - txt += [' MakeAsyncQueue ${asyncqueue} ${asyncprotocol} ${ip_address} ${tcp_port}'] - txt += [' if { [dict exists $v "timeout"] } {'] - txt += [' ${asyncqueue} timeout "[dict get $v "timeout"]"'] - txt += [' }'] - txt += [' }'] - if 'make_args' in MyDriver: + if ('WrapperProperty' in MyDriver) and ('nosctcontroller' in MyDriver['WrapperProperty']): + txt += [' %s::sics_log 9 "No sctcontroller for %s"' % (MyDriver['namespace'], MyDriver['name'])] + txt += [' set ip_address [dict get $v ip]'] + txt += [' set tcp_port [dict get $v port]'] + else: + txt += [' if { ![string equal -nocase "${simulation_flag}" "false"] } {'] + txt += [' set asyncqueue "null"'] + txt += [' ${ns}::sics_log 9 "simulation_flag=${simulation_flag} => using null asyncqueue"'] + txt += [' ${ns}::sics_log 9 "makesctcontroller sct_${name} aqadapter NULL"'] + txt += [' makesctcontroller sct_${name} aqadapter NULL'] + txt += [' } elseif { [dict exists $v "asyncqueue"] } {'] + txt += [' set asyncqueue [dict get $v "asyncqueue"]'] + txt += [' if { [string equal -nocase ${asyncqueue} "sct"] } {'] + txt += [' set ip_address [dict get $v ip]'] + txt += [' set tcp_port [dict get $v port]'] + if 'protocol_args_lst' in MyDriver: + txt += [' set arg_list [list]'] + txt += [' set missing_list [list]'] + default_list = [] + for arg in [key for key in MyDriver['protocol_args_lst'] if MyDriver['protocol_args_map'][key] is not None]: + default_list += [arg, MyDriver['protocol_args_map'][arg]] + if len(default_list) > 0: + txt += [' array unset default_map'] + txt += [' array set default_map [list %s]' % ' '.join(default_list)] + txt += [' foreach arg {' + ' '.join(MyDriver['protocol_args_lst']) + '} {'] + txt += [' if {[dict exists $u $arg]} {'] + txt += [' lappend arg_list "[dict get $u $arg]"'] + txt += [' } elseif {[dict exists $v $arg]} {'] + txt += [' lappend arg_list "[dict get $v $arg]"'] + if len(default_list) > 0: + txt += [' } elseif {[info exists default_map($arg)]} {'] + txt += [' lappend arg_list $default_map($arg)'] + txt += [' } else {'] + txt += [' ${ns}::sics_log 9 "Missing configuration value $arg"'] + txt += [' lappend missing_list $arg'] + txt += [' }'] + txt += [' }'] + txt += [' if { [llength $missing_list] > 0 } {'] + txt += [' error "$name is missing configuration values $missing_list"'] + txt += [' }'] + protocol_args = ' {*}$arg_list' + else: + protocol_args = '' + txt += [' makesctcontroller sct_${name} %s ${ip_address}:${tcp_port}%s' % (MyDriver['protocol'], protocol_args)] + txt += [' } else {'] + txt += [' makesctcontroller sct_${name} aqadapter ${asyncqueue}'] + txt += [' }'] + txt += [' } else {'] + txt += [' if { [dict exists $v "asyncprotocol"] } {'] + txt += [' set asyncprotocol [dict get $v "asyncprotocol"]'] + txt += [' } else {'] + txt += [' set asyncprotocol ${name}_protocol'] + txt += [' MakeAsyncProtocol ${asyncprotocol}'] + txt += [' if { [dict exists $v "sendterminator"] } {'] + txt += [' ${asyncprotocol} sendterminator "[dict get $v "sendterminator"]"'] + txt += [' } elseif { [dict exists $v "terminator"] } {'] + txt += [' ${asyncprotocol} sendterminator "[dict get $v "terminator"]"'] + txt += [' }'] + txt += [' if { [dict exists $v "replyterminator"] } {'] + txt += [' ${asyncprotocol} replyterminator "[dict get $v "replyterminator"]"'] + txt += [' } elseif { [dict exists $v "terminator"] } {'] + txt += [' ${asyncprotocol} replyterminator "[dict get $v "terminator"]"'] + txt += [' }'] + txt += [' }'] + txt += [' set asyncqueue ${name}_queue'] + txt += [' set ip_address [dict get $v ip]'] + txt += [' set tcp_port [dict get $v port]'] + txt += [' MakeAsyncQueue ${asyncqueue} ${asyncprotocol} ${ip_address} ${tcp_port}'] + txt += [' if { [dict exists $v "timeout"] } {'] + txt += [' ${asyncqueue} timeout "[dict get $v "timeout"]"'] + txt += [' }'] + txt += [' makesctcontroller sct_${name} aqadapter ${asyncqueue}'] + txt += [' }'] + if 'make_args_lst' in MyDriver: txt += [' set arg_list [list]'] txt += [' set missing_list [list]'] - txt += [' foreach arg {' + MyDriver['make_args'] + '} {'] + default_list = [] + for arg in [key for key in MyDriver['make_args_lst'] if MyDriver['make_args_map'][key] is not None]: + default_list += [arg, MyDriver['make_args_map'][arg]] + if len(default_list) > 0: + txt += [' array unset default_map'] + txt += [' array set default_map [list %s]' % ' '.join(default_list)] + txt += [' foreach arg {' + ' '.join(MyDriver['make_args_lst']) + '} {'] txt += [' if {[dict exists $u $arg]} {'] txt += [' lappend arg_list "[dict get $u $arg]"'] txt += [' } elseif {[dict exists $v $arg]} {'] txt += [' lappend arg_list "[dict get $v $arg]"'] + if len(default_list) > 0: + txt += [' } elseif {[info exists default_map($arg)]} {'] + txt += [' lappend arg_list $default_map($arg)'] txt += [' } else {'] txt += [' ${ns}::sics_log 9 "Missing configuration value $arg"'] txt += [' lappend missing_list $arg'] @@ -1603,17 +1883,10 @@ def put_read_config(MyDriver): txt += [' if { [llength $missing_list] > 0 } {'] txt += [' error "$name is missing configuration values $missing_list"'] txt += [' }'] - txt += [' if { [string equal -nocase ${asyncqueue} "sct"] } {'] - txt += [' ${ns}::add_driver ${name} ${device_class} ${simulation_flag} ${ip_address} ${tcp_port} {*}$arg_list'] - txt += [' } else {'] - txt += [' ${ns}::add_driver ${name} ${device_class} ${simulation_flag} "aqadapter" ${asyncqueue} {*}$arg_list'] - txt += [' }'] + make_args = ' {*}$arg_list' else: - txt += [' if { [string equal -nocase ${asyncqueue} "sct"] } {'] - txt += [' ${ns}::add_driver ${name} ${device_class} ${simulation_flag} ${ip_address} ${tcp_port}'] - txt += [' } else {'] - txt += [' ${ns}::add_driver ${name} ${device_class} ${simulation_flag} "aqadapter" ${asyncqueue}'] - txt += [' }'] + make_args = '' + txt += [' ${ns}::mkDriver sct_${name} ${name} ${device_class} ${simulation_flag} ${ip_address} ${tcp_port}' + make_args] txt += [' }'] txt += [' }'] txt += [' }'] @@ -1661,13 +1934,12 @@ def generate_driver(MyDriver): global NumberOfLinesOut global fdo NumberOfLinesOut = 0 - full_filename = filename = "sct_%s.tcl" % MyDriver['name'] - if 'PathName' in MyDriver: - full_filename = os.path.join(MyDriver['PathName'], filename) - fdo = open(full_filename, 'w') + generate_filename(MyDriver) + fdo = open(MyDriver['fullname'], 'w') put_preamble(MyDriver) put_standard_code(MyDriver) put_mkDriver(MyDriver) + put_add_driver(MyDriver) put_postamble(MyDriver) put_read_config(MyDriver) put_check_config(MyDriver) @@ -1678,7 +1950,9 @@ def generate_driver(MyDriver): print "Function:", f, "Type:", MyDriver['Funcs'][f]['type'], '#Uses:', MyDriver['Funcs'][f]['reference_count'] for l in MyDriver['Funcs'][f]['text']: print " ", l - print "Produced file %s with %d lines." % (filename, NumberOfLinesOut) + if Verbose: + print "Produced file %s with %d lines." % \ + ( MyDriver['filename'], NumberOfLinesOut) def process_drivers(TheDrivers): if Verbose: @@ -1692,62 +1966,144 @@ def process_drivers(TheDrivers): MyDriver['Permlink'] = {} MyDriver['Deferred'] = [] build_driver(MyDriver, TheDrivers[driver]) + check_func_code(MyDriver) if Verbose: print "MyDriver:", MyDriver['name'], '=', MyDriver if DriverDump or Verbose: dump_driver(MyDriver) generate_driver(MyDriver) -def process_source(source_files): - global PathName +def load_file(source_file, depth_list): + global SourceFileList, SourceLineList + # find the file and set the name + SourceFile = os.path.realpath(os.path.abspath(source_file)) + if not os.path.isfile(SourceFile): + #print source_file, SourceFile, SourceFileList + if len(SourceFileList) > 0: + trial_name = os.path.join(os.path.dirname(SourceFileList[0]), source_file) + #print trial_name + if os.path.isfile(trial_name): + SourceFile = os.path.realpath(os.path.abspath(trial_name)) + if SourceFile in depth_list: + PrintPostError('Error: recursive include of: %s' % SourceFile) + for idx, name in enumerate(depth_list): + PrintPostError(' ' * idx + name) + raise Exception('Bad recursive include of "' + SourceFile + '"') + SourceFileList.append(SourceFile) + curr_file = len(SourceFileList) - 1 + fd = open(SourceFile, 'r') + LocalData = [] + line_no = 0 + execing = False + exec_input = [] + exec_line = 0 + for line in fd: + line_no += 1 + line = line.rstrip('\n') + if execing: + match = re.match(r'\s*%end', line, flags=re.IGNORECASE) + if match: + #print "exec_input:" + #for temp_line in exec_input: + # print " " + temp_line + kw = {} + kw['exec_output'] = [] + exec('\n'.join(exec_input)) in kw + #print "exec_output:" + for line in kw['exec_output']: + # print " " + line + LocalData.append(line) + SourceLineList.append((curr_file, exec_line)) + exec_input = [] + execing = False + else: + exec_input.append(line) + continue + match = re.match(r'\s*%exec', line, flags=re.IGNORECASE) + if match: + execing = True + exec_line = line_no + continue + match = re.match(r'\s*%include\s+', line, flags=re.IGNORECASE) + if match: + new_source = re.sub(r'\s*%include\s+(.*)', r'\1', line, flags=re.IGNORECASE) + LocalData += load_file(new_source, depth_list + [SourceFile]) + continue + LocalData.append(line) + SourceLineList.append((curr_file, line_no)) + fd.close() + return LocalData + +def dump_source_files(data): + global SourceFileList, SourceLineList + print "SourceFileList:", SourceFileList + print "SourceLineList:", SourceLineList + curr_file = -1 + for line_no, line in enumerate(data): + if SourceLineList[line_no][0] != curr_file: + curr_file = SourceLineList[line_no][0] + print "File:", SourceFileList[curr_file] + print "%4d:" % SourceLineList[line_no][1], line + +def process_source(source_file): + global PathName, SourceFile global TheDrivers - global NumberOfLinesIn + global NumberOfLinesIn, NumberOfLinesOut + global SourceData + global PrintedFileName + global SourceFileList, SourceLineList TheDrivers = {} - # - # Build the lexer - # - lexer = lex.lex() - - - # - # Build the parser - # - #yaccer = yacc.yacc(tabmodule="gen_sct",outputdir="/tmp",write_tables=0,debug=0) - yaccer = yacc.yacc() - - for source_file in source_files: - PathName = os.path.realpath(os.path.abspath(os.path.dirname(source_file))) - fd = open(source_file, 'r') - data = fd.read() - fd.close() - NumberOfLinesIn = data.count('\n') - start_line = lexer.lineno - yaccer.parse(data) - stop_line = lexer.lineno - print 'Consumed file %s with %d lines (%d, %d)' % (source_file, - NumberOfLinesIn, start_line, stop_line - 1) - lexer.lineno = 1 + PrintedFileName = -1 + NumberOfLinesIn = 0 + NumberOfLinesOut = 0 + SourceFileList = list() + SourceLineList = list() + PathName = os.path.realpath(os.path.abspath(os.path.dirname(source_file))) + SourceData = load_file(source_file, []) + NumberOfLinesIn = len(SourceData) + start_line = lexer.lineno + yaccer.parse('\n'.join(SourceData)) + stop_line = lexer.lineno + if Verbose: + print 'Consumed file %s with %d lines (%d, %d)' % \ + (source_file, NumberOfLinesIn, start_line, stop_line - 1) + lexer.lineno = 1 process_drivers(TheDrivers) + if args.list: + dump_source_files(SourceData) def main(): + global lexer, yaccer global Verbose + global Move global DriverDump global CodeDump + global args import argparse + # RELEASE-3_1="before", RELEASE-3_2="after" + default_sct = "before" parser = argparse.ArgumentParser() parser.add_argument("-c", "--code", help="dump code", action="store_true") parser.add_argument("-d", "--driver", help="dump driver", action="store_true") + parser.add_argument("-l", "--list", help="list output", + action="store_true") + parser.add_argument("-m", "--move", help="generate move commands", + action="store_true") + parser.add_argument("--sct", + help="where to put the sct in the filename [%s]" % default_sct, + choices=["before", "after"], default=default_sct) parser.add_argument("-v", "--verbose", help="verbose output", action="store_true") parser.add_argument("driver_source", help="driver source file", nargs="*") args = parser.parse_args() - print args + if args.verbose: + print args if args.code: CodeDump = True else: @@ -1756,13 +2112,30 @@ def main(): DriverDump = True else: DriverDump = False + if args.move: + Move = True + else: + Move = False if args.verbose: Verbose = True else: Verbose = False - source_files = args.driver_source - if source_files: - process_source(source_files) + source_files = args.driver_source # + if source_files and len(source_files) > 0: + # Build the lexer + # + lexer = lex.lex() + + + # + # Build the parser + # + #yaccer = yacc.yacc(tabmodule="gen_sct",outputdir="/tmp",write_tables=0,debug=0) + yaccer = yacc.yacc(debug=0) + + + for source_file in source_files: + process_source(source_file) if __name__ == "__main__": main() From fea223beff9e894ac3c11e106b46be0563f04d88 Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Fri, 17 Apr 2015 10:48:20 +1000 Subject: [PATCH 04/10] Add motor soma to dingo configuration --- .../config/motors/motor_configuration.tcl | 189 ++++++++----- .../instrument/dingo/util/sics_config.ini | 251 ++++++++++++++++++ 2 files changed, 370 insertions(+), 70 deletions(-) create mode 100644 site_ansto/instrument/dingo/util/sics_config.ini diff --git a/site_ansto/instrument/dingo/config/motors/motor_configuration.tcl b/site_ansto/instrument/dingo/config/motors/motor_configuration.tcl index aa4a1f69..e7f4dc5a 100644 --- a/site_ansto/instrument/dingo/config/motors/motor_configuration.tcl +++ b/site_ansto/instrument/dingo/config/motors/motor_configuration.tcl @@ -16,6 +16,12 @@ if {$sim_mode == "true"} { #MakeAsyncQueue mc3 DMC2280 [dict get $::MOTOR_HOSTPORT MC3 HOST] [dict get $::MOTOR_HOSTPORT MC3 PORT] } +set sample_stage_rotate "normal_sample_stage" +if { [ info exists ::config_dict ] } { + if { [ dict exists $::config_dict sample_stage implementation ] } { + set sample_stage_rotate [ dict get $::config_dict sample_stage implementation ] + } +} # Dummy translation motor, useful for testing scans set dummy_Home 0 @@ -135,41 +141,43 @@ sy softlowerlim -50 sy softupperlim 230 sy home 0 -# mc1: Sample rotation axis -# Gearbox 100:1, screw pitch 356:1 -# Encoder 2P17 -#set stth_Home 821487 -set stth_Home 0 -#set stthStepRate [expr -$motorrate*100.0] -set stthStepRate -2478000 -Motor stth $motor_driver_type [params \ - asyncqueue mc1\ - host mc1-dingo\ - port pmc1-dingo\ - axis D\ - units degree\ - hardlowerlim -722\ - hardupperlim 722\ - maxSpeed 0.12\ - maxAccel 1\ - maxDecel 1\ - stepsPerX $stthStepRate\ - absEnc 1\ - absEncHome $stth_Home\ - nopowersave 1\ - cntsPerX 93206.75556 ] -stth speed 0.1 -stth accel 0.1 -stth decel 0.1 -stth part sample -stth long_name stth -stth softlowerlim 0.01 -stth softupperlim 359.99 -stth home 0 -#stth bias_bits 25 -#stth bias_bias -33432264 -stth rotary_bits 25 -stth creep_offset 0.05 +if {[string equal -nocase ${sample_stage_rotate} "normal_sample_stage"]} { + # mc1: Sample rotation axis + # Gearbox 100:1, screw pitch 356:1 + # Encoder 2P17 + #set stth_Home 821487 + set stth_Home 0 + #set stthStepRate [expr -$motorrate*100.0] + set stthStepRate -2478000 + Motor stth $motor_driver_type [params \ + asyncqueue mc1\ + host mc1-dingo\ + port pmc1-dingo\ + axis D\ + units degree\ + hardlowerlim -722\ + hardupperlim 722\ + maxSpeed 2.0\ + maxAccel 1\ + maxDecel 1\ + stepsPerX $stthStepRate\ + absEnc 1\ + absEncHome $stth_Home\ + nopowersave 1\ + cntsPerX 93206.75556 ] + stth speed 0.5 + stth accel 0.1 + stth decel 0.1 + stth part sample + stth long_name stth + stth softlowerlim 0.01 + stth softupperlim 359.99 + stth home 0 + #stth bias_bits 25 + #stth bias_bias -33432264 + stth rotary_bits 25 + stth creep_offset 0.05 +} # mc1: detection Z-stage Translation # Gearbox 5:1, Gear ratio 16:1, pitch 4mm @@ -199,40 +207,81 @@ dz softlowerlim 0 dz softupperlim 170 dz home 0 -# mc1:H Sample rotation axis -# Resolver 2,048 counts per degree -# Motor 12,500 steps per degree -# Positive steps are CCW viewed from above -set soma_Home 9867748 -#set somaStepRate [expr -$motorrate*100.0] -set somaStepRate 12500 -Motor soma $motor_driver_type [params \ - asyncqueue mc1\ - host mc1-dingo\ - port pmc1-dingo\ - axis H\ - units degree\ - hardlowerlim -722\ - hardupperlim 722\ - maxSpeed 12\ - maxAccel 1\ - maxDecel 1\ - stepsPerX $somaStepRate\ - absEnc 1\ - absEncHome $soma_Home\ - nopowersave 1\ - cntsPerX 2048 ] -soma speed 0.1 -soma accel 0.1 -soma decel 0.1 -soma part sample -soma long_name soma -soma softlowerlim -1 -soma softupperlim 361 -soma home 0 -#soma bias_bits 25 -#soma rotary_bits 25 -soma creep_offset 0.05 +if {[string equal -nocase ${sample_stage_rotate} "soma"]} { + # mc1:H Sample rotation axis + # Resolver 2,048 counts per degree + # Motor 12,500 steps per degree + # Positive steps are CCW viewed from above + set soma_Home 9867748 + #set somaStepRate [expr -$motorrate*100.0] + set somaStepRate 12500 + Motor soma $motor_driver_type [params \ + asyncqueue mc1\ + host mc1-dingo\ + port pmc1-dingo\ + axis H\ + units degree\ + hardlowerlim -722\ + hardupperlim 722\ + maxSpeed 12\ + maxAccel 1\ + maxDecel 1\ + stepsPerX $somaStepRate\ + absEnc 1\ + absEncHome $soma_Home\ + nopowersave 1\ + cntsPerX 2048 ] + soma speed 0.1 + soma accel 0.1 + soma decel 0.1 + soma part sample + soma long_name soma + soma softlowerlim -1 + soma softupperlim 361 + soma home 0 + #soma bias_bits 25 + #soma rotary_bits 25 + soma creep_offset 0.05 +} + +if {[string equal -nocase ${sample_stage_rotate} "somb"]} { + # mc1:D,H Sample rotation axis + # Resolver 4,096 counts per degree + # Motor 10*25,000 steps per degree + # Positive steps are CCW viewed from above + set somb_Home [expr 2**23] + #set sombStepRate [expr -$motorrate*100.0] + set sombStepRate [expr 10 * 25000] + Motor somb $motor_driver_type [params \ + asyncqueue mc1\ + host mc1-dingo\ + port pmc1-dingo\ + axis D\ + encoderaxis H\ + units degree\ + hardlowerlim -722\ + hardupperlim 722\ + maxSpeed 0.4\ + maxAccel 1\ + maxDecel 1\ + stepsPerX $sombStepRate\ + absEnc 1\ + absEncHome $somb_Home\ + nopowersave 1\ + cntsPerX 4096 ] + somb speed 0.1 + somb accel 0.1 + somb decel 0.1 + somb part sample + somb long_name somb + somb softlowerlim -1 + somb softupperlim 361 + somb home 0 + somb bias_bits 24 + somb bias_bias [expr 2**23] + #somb rotary_bits 25 + somb creep_offset 0.05 +} ############################ @@ -243,7 +292,7 @@ soma creep_offset 0.05 # # mc2: Camera translation axis along beam -# Gearbox ?, Gear ratio ?, +# Gearbox ?, Gear ratio ?, set dy_Home 8847069 set dyStepRate [expr 25000.0/2.0] Motor dy $motor_driver_type [params \ diff --git a/site_ansto/instrument/dingo/util/sics_config.ini b/site_ansto/instrument/dingo/util/sics_config.ini new file mode 100644 index 00000000..9be02e0a --- /dev/null +++ b/site_ansto/instrument/dingo/util/sics_config.ini @@ -0,0 +1,251 @@ +[CF5] +cascade = T1:CF5_ls340,sample_stage:normal_sample_stage +enabled = False +[Default] +cascade = sample_stage:normal_sample_stage +enabled = True +[Function_Generator] +datype = V +enabled = False +id = 1 +implementation = none +name = pulser +optype = function_generator +[I1] +datype = I +enabled = False +id = 1 +implementation = none +name = curr1 +optype = multimeter +[I2] +datype = I +enabled = False +id = 2 +implementation = none +name = curr2 +optype = multimeter +[T1] +datype = T +enabled = False +id = 1 +implementation = none +name = tc1 +optype = temperature +[T2] +datype = T +enabled = False +id = 2 +implementation = none +name = tc2 +optype = temperature +[T3] +datype = T +enabled = False +id = 3 +implementation = none +name = tc3 +optype = temperature +[T4] +datype = T +enabled = False +id = 4 +implementation = none +name = tc4 +optype = temperature +[V1] +datype = V +enabled = False +id = 1 +implementation = none +name = volts1 +optype = multimeter +[V2] +datype = V +enabled = False +id = 2 +implementation = none +name = volts2 +optype = multimeter +[sample_stage] +enabled = Always +implementation = somb +name = sample_stage +optype = motion_axis +[CF5_ls340] +asyncqueue = sct +desc = "Lakeshore 340 temperature controller" +driver = "ls340" +imptype = temperature +ip = 10.157.205.34 +port = 4001 +terminator = \r\n +tol1 = 1.0 +tol2 = 1.0 + +[agilent_33220A] +asyncqueue = sct +desc = "Function Generator" +driver = agilent_33220A +imptype = function_generator +ip = 10.157.205.16 +port = 5025 + +[ls336_01] +asyncqueue = sct +desc = "Lakeshore 336 temperature controller" +driver = "ls336" +imptype = temperature +ip = 10.157.205.28 +port = 7777 +terminator = \r\n +tol1 = 1.0 +tol2 = 1.0 + +[ls336_02] +asyncqueue = sct +desc = "Lakeshore 336 temperature controller" +driver = "ls336" +imptype = temperature +ip = 10.157.205.29 +port = 7777 +terminator = \r\n +tol1 = 1.0 +tol2 = 1.0 + +[ls336_04] +asyncqueue = sct +desc = "Lakeshore 336 temperature controller" +driver = "ls336" +imptype = temperature +ip = 10.157.205.30 +port = 7777 +terminator = \r\n +tol1 = 1.0 +tol2 = 1.0 + +[ls336_05] +asyncqueue = sct +desc = "Lakeshore 336 temperature controller" +driver = "ls336" +imptype = temperature +ip = 137.157.201.21 +port = 7777 +terminator = \r\n +tol1 = 1.0 +tol2 = 1.0 + +[ls336_06] +asyncqueue = sct +desc = "Lakeshore 336 temperature controller" +driver = "ls336" +imptype = temperature +ip = 137.157.201.21 +port = 7777 +terminator = \r\n +tol1 = 1.0 +tol2 = 1.0 + +[ls336_11] +desc = "Lakeshore 336 temperature controller" +driver = "ls336" +imptype = temperature +ip = 10.157.205.27 +port = 7777 +terminator = \r\n +tol1 = 1.0 +tol2 = 1.0 + +[ls336_12] +asyncqueue = sct +desc = "Lakeshore 336 temperature controller" +driver = "ls336" +imptype = temperature +ip = 10.157.205.31 +port = 7777 +terminator = \r\n +tol1 = 1.0 +tol2 = 1.0 + +[ls340_01] +asyncqueue = sct +desc = "Lakeshore 340 temperature controller" +driver = "ls340" +imptype = temperature +ip = 137.157.201.86 +port = 4001 +terminator = \r\n +tol1 = 1.0 +tol2 = 1.0 + +[ls340_02] +asyncqueue = sct +desc = "Lakeshore 340 temperature controller" +driver = "ls340" +imptype = temperature +ip = 137.157.201.86 +port = 4002 +terminator = \r\n +tol1 = 1.0 +tol2 = 1.0 + +[ls340_11] +desc = "Lakeshore 340 temperature controller" +driver = "ls340" +imptype = temperature +ip = 137.157.201.86 +port = 4001 +terminator = \r\n +tol1 = 1.0 +tol2 = 1.0 + +[mercury_scpi_01] +desc = "Oxford Mercury temperature controller with three temperature loops." +driver = "mercury_base" +imptype = temperature +ip = 10.157.205.5 +permlink = LT +port = 7020 +terminator = \r\n +tol = 1.0 +valve_tol = 2 + +[mercury_scpi_02] +desc = "Oxford Mercury temperature controller with four temperature loops and needle valve control" +driver = "mercury_scpi" +imptype = temperature +ip = 10.157.205.47 +permlink = LT +port = 7020 +terminator = \r\n +tol = 1.0 +valve_tol = 2 + +[normal_sample_stage] +desc = "This is the default sample stage configuration" +imptype = motion_axis + +[protek_01] +asyncqueue = sct +desc = "Protek Multimeter" +driver = "protekmm" +imptype = multimeter +ip = 10.157.205.36 +port = 4001 + +[protek_02] +asyncqueue = sct +desc = "Protek Multimeter" +driver = "protekmm" +imptype = multimeter +ip = 10.157.205.37 +port = 4001 + +[soma] +desc = "This is alternative Sample Omega A" +imptype = motion_axis + +[somb] +desc = "This is alternative Sample Omega B" +imptype = motion_axis + From 349171e8ecc483b5cfb02289a1f9459cec25f8d9 Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Fri, 17 Apr 2015 11:45:05 +1000 Subject: [PATCH 05/10] Minor changes from Taipan motor_config --- .../instrument/tas/config/motors/motor_configuration.tcl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/site_ansto/instrument/tas/config/motors/motor_configuration.tcl b/site_ansto/instrument/tas/config/motors/motor_configuration.tcl index 0f027691..b60e16d4 100644 --- a/site_ansto/instrument/tas/config/motors/motor_configuration.tcl +++ b/site_ansto/instrument/tas/config/motors/motor_configuration.tcl @@ -479,7 +479,7 @@ Motor mhfocus $motor_driver_type [params \ maxSpeed 3.6\ maxAccel 1.728\ maxDecel 1.728\ - stepsPerX [expr -25000.0 * 50.0 / 360.0]\ + stepsPerX [expr 25000.0 * 50.0 / 360.0]\ absEnc 1\ bias_bits 12\ bias_bias 1300\ @@ -510,7 +510,7 @@ Motor m1 $motor_driver_type [params \ maxDecel 0.25\ stepsPerX 100000\ absEnc 1\ - absEncHome 16189898\ + absEncHome 16190612\ cntsPerX -2048] m1 part crystal m1 long_name m1 From d07a0418b6ea4b651c96487a2306c224dbcac758 Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Fri, 17 Apr 2015 11:49:10 +1000 Subject: [PATCH 06/10] Add Taipan euler_config --- .../tas/config/motors/euler_configuration.tcl | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 site_ansto/instrument/tas/config/motors/euler_configuration.tcl diff --git a/site_ansto/instrument/tas/config/motors/euler_configuration.tcl b/site_ansto/instrument/tas/config/motors/euler_configuration.tcl new file mode 100644 index 00000000..ceda6d7a --- /dev/null +++ b/site_ansto/instrument/tas/config/motors/euler_configuration.tcl @@ -0,0 +1,76 @@ +# This must be loaded by motor_configuration.tcl + +set ephi_Home 26575217 +#set echi_Home 24224381 +#set echi_Home 8919294 +set echi_Home 24207159 +set eom_Home 23165482 + +# Sample Lower Tilt sgl -> Euler Chi +Motor echi $motor_driver_type [params \ + asyncqueue mc2\ + axis B\ + units degrees\ + hardlowerlim -45\ + hardupperlim 120\ + maxSpeed 2\ + maxAccel 2\ + maxDecel 2\ + stepsPerX -25000\ + absEnc 1\ + absEncHome $echi_Home\ + cntsPerX 8192] +setHomeandRange -motor echi -home 0 -lowrange 10 -uprange 95 +echi softlowerlim -10 +echi softupperlim 120 +echi home 0 +echi speed 1 +echi movecount $move_count +echi precision 0.01 +echi part sample +echi long_name euler_chi + +# Sample Upper Tilt sgu -> Euler Phi +Motor ephi $motor_driver_type [params \ + asyncqueue mc2\ + axis A\ + units degrees\ + hardlowerlim -365\ + hardupperlim 365\ + maxSpeed 5\ + maxAccel 5\ + maxDecel 5\ + stepsPerX -12500\ + absEnc 1\ + absEncHome $ephi_Home\ + cntsPerX -4096] +setHomeandRange -motor ephi -home 0 -lowrange -360 -uprange 360 +ephi softlowerlim -360 +ephi softupperlim 360 +ephi home 0 +ephi speed 3 +ephi movecount $move_count +ephi precision 0.01 +ephi part sample +ephi long_name euler_phi + +# Sample Upper Translation stu -> euler omega stage +Motor eom $motor_driver_type [params \ + asyncqueue mc2\ + axis C\ + units degrees\ + hardlowerlim -45\ + hardupperlim 80\ + maxSpeed 2\ + maxAccel 2\ + maxDecel 2\ + stepsPerX 25000\ + absEnc 1\ + absEncHome $eom_Home\ + cntsPerX -8192] +setHomeandRange -motor eom -home 0 -lowrange 35 -uprange 80 +eom speed 1 +eom movecount $move_count +eom precision 0.01 +eom part sample +eom long_name euler_omega From 1f9dd8da95cf434f49bf0bb99c67a97968ec12f3 Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Fri, 17 Apr 2015 12:15:01 +1000 Subject: [PATCH 07/10] Pullback from Quokka 2015-04-17 --- .../config/environment/temperature/sct_watlow_mrm.tcl | 4 ++-- .../sans/config/motors/positmotor_configuration.tcl | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/site_ansto/instrument/config/environment/temperature/sct_watlow_mrm.tcl b/site_ansto/instrument/config/environment/temperature/sct_watlow_mrm.tcl index 6258c1d4..26dbe3ae 100644 --- a/site_ansto/instrument/config/environment/temperature/sct_watlow_mrm.tcl +++ b/site_ansto/instrument/config/environment/temperature/sct_watlow_mrm.tcl @@ -56,8 +56,8 @@ proc ::scobj::watlow_mrm::add_driver {name device_class simulation_flag ip_addre ::scobj::watlow_mrm::sics_log 9 "makesctcontroller sct_${name} aqadapter ${tcp_port}" makesctcontroller sct_${name} aqadapter ${tcp_port} } else { - ::scobj::watlow_mrm::sics_log 9 "makesctcontroller sct_${name} std ${ip_address}:${tcp_port}" - makesctcontroller sct_${name} std ${ip_address}:${tcp_port} + ::scobj::watlow_mrm::sics_log 9 "makesctcontroller sct_${name} modbus ${ip_address}:${tcp_port}" + makesctcontroller sct_${name} modbus ${ip_address}:${tcp_port} } } else { ::scobj::watlow_mrm::sics_log 9 "simulation_flag={simulation_flag} => No sctcontroller for watlow_mrm" diff --git a/site_ansto/instrument/sans/config/motors/positmotor_configuration.tcl b/site_ansto/instrument/sans/config/motors/positmotor_configuration.tcl index 860d8b07..5b3f1425 100644 --- a/site_ansto/instrument/sans/config/motors/positmotor_configuration.tcl +++ b/site_ansto/instrument/sans/config/motors/positmotor_configuration.tcl @@ -47,11 +47,21 @@ set 10sample_table { 10 -214.5996 } +set 5sample_table { + 1 120 + 2 60 + 3 0 + 4 -60 + 5 -120 +} + if { [ info exists ::config_dict ] } { if { [ dict exists $::config_dict sample_stage implementation ] } { set implementation [ dict get $::config_dict sample_stage implementation ] if {$implementation == "normal_sample_stage"} { # Don't make posit motor + } elseif {$implementation == "5_pos_sample_tumbler"} { + mkPosit sct_mc1 sampleNum float samx sample $5sample_table } elseif {$implementation == "10_pos_sample_stage"} { mkPosit sct_mc1 sampleNum float samx sample $10sample_table } elseif {$implementation == "20_pos_sample_stage"} { From 1a93e494d9ce50fc28e25887517dab0dcacefc9a Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Fri, 17 Apr 2015 12:38:19 +1000 Subject: [PATCH 08/10] Add a test setup for Pelican --- site_ansto/instrument/TEST_SICS/setup/pelican | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100755 site_ansto/instrument/TEST_SICS/setup/pelican diff --git a/site_ansto/instrument/TEST_SICS/setup/pelican b/site_ansto/instrument/TEST_SICS/setup/pelican new file mode 100755 index 00000000..1baca5db --- /dev/null +++ b/site_ansto/instrument/TEST_SICS/setup/pelican @@ -0,0 +1,16 @@ +#!/bin/bash +echo me:${0} +. $(dirname ${0})/common +status=${?} +echo root:${status}:${root} +if [ ! ${status} ]; then + exit 1 +fi +gnome-terminal \ + --tab --title="Motors" \ + --working-directory=${root}/fakeGalil \ + --command="${root}/fakeGalil/SIM_GALIL.py -w pelican" \ + --tab --title="Bash" \ + --working-directory=${root} \ + --command="bash" + From 843a9f46bec265c829bb98f4d1d31a9bc59f5ce5 Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Fri, 17 Apr 2015 12:52:17 +1000 Subject: [PATCH 09/10] Pullback changes from Platypus --- .../instrument/reflectometer/config/hmm/hmm_configuration.tcl | 3 ++- site_ansto/instrument/reflectometer/platypus_configuration.tcl | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/site_ansto/instrument/reflectometer/config/hmm/hmm_configuration.tcl b/site_ansto/instrument/reflectometer/config/hmm/hmm_configuration.tcl index 747c6986..8dc46750 100644 --- a/site_ansto/instrument/reflectometer/config/hmm/hmm_configuration.tcl +++ b/site_ansto/instrument/reflectometer/config/hmm/hmm_configuration.tcl @@ -19,7 +19,8 @@ proc ::histogram_memory::init_OAT_TABLE {} { hmm configure fat_frame_source EXTERNAL # OAT_TABLE -set X { -210.5 -209.5 } NXC 421 Y { -110.5 -109.5 } NYC 221 T { 0 40 } NTC 1000 - OAT_TABLE -set X { 56.5 -56.5 } NXC 1 Y { 110.5 109.5 } NYC 221 T { 0 40 } NTC 1000 +# OAT_TABLE -set X { 56.5 -56.5 } NXC 1 Y { 110.5 109.5 } NYC 221 T { 0 40 } NTC 1000 + OAT_TABLE -set X { 60.5 -60.5 } NXC 1 Y { 110.5 109.5 } NYC 221 T { 0 40 } NTC 1000 } message ] { if {$::errorCode=="NONE"} {return $message} return -code error $message diff --git a/site_ansto/instrument/reflectometer/platypus_configuration.tcl b/site_ansto/instrument/reflectometer/platypus_configuration.tcl index 7cefb18d..ac3a6946 100644 --- a/site_ansto/instrument/reflectometer/platypus_configuration.tcl +++ b/site_ansto/instrument/reflectometer/platypus_configuration.tcl @@ -27,6 +27,7 @@ fileeval $cfPath(plc)/plc.tcl fileeval $cfPath(counter)/counter.tcl fileeval $cfPath(environment)/sct_syr.tcl fileeval $cfPath(environment)/sct_syringe_pump.tcl +fileeval $cfPath(environment)/isotech_ps_sct.tcl fileeval $cfPath(environment)/sct_knauer_pump.tcl fileeval $cfPath(environment)/sct_mvp.tcl fileeval $cfPath(environment)/sct_mvp_valve.tcl @@ -40,6 +41,7 @@ fileeval $cfPath(environment)/temperature/sct_lakeshore_336.tcl fileeval $cfPath(environment)/temperature/sct_ls336.tcl fileeval $cfPath(environment)/temperature/sct_lakeshore_340.tcl fileeval $cfPath(environment)/temperature/sct_ls340.tcl +fileeval $cfPath(environment)/temperature/sct_julabo_lh45.tcl fileeval $cfPath(environment)/temperature/sct_julabo_lh45_gen.tcl fileeval $cfPath(hmm)/hmm_configuration.tcl fileeval $cfPath(nexus)/nxscripts.tcl From f2568b681dde1025c3b696590dfdbb07d0b4f4a0 Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Fri, 17 Apr 2015 13:12:42 +1000 Subject: [PATCH 10/10] Pullback from Wombat 2015-04-17 --- .../hipd/config/commands/cfcommands.tcl | 396 ++++++++++-------- .../hipd/config/hmm/hmm_configuration.tcl | 2 +- .../instrument/hipd/wombat_configuration.tcl | 2 +- 3 files changed, 232 insertions(+), 168 deletions(-) diff --git a/site_ansto/instrument/hipd/config/commands/cfcommands.tcl b/site_ansto/instrument/hipd/config/commands/cfcommands.tcl index d2980113..0c5ae243 100644 --- a/site_ansto/instrument/hipd/config/commands/cfcommands.tcl +++ b/site_ansto/instrument/hipd/config/commands/cfcommands.tcl @@ -1,166 +1,230 @@ -# cf commands for driving sample environment -# ajs feb 2015 - -# cf namespace -# assumes tc1 and tc2 are the cf8 336 and 340 lakeshores for now - -namespace eval cf { - variable wall_lag 10 - variable wall_max 300 - variable sample_tolerance 5 - variable wall_tolerance 5 - variable wall_set true - variable base_set true - variable base_control true - variable wall_control true - - proc UseWall {_wall_set _wall_control} { - variable wall_set - variable wall_control - if {$_wall_set == false} {set wall_set false} else {set wall_set true} - if {$_wall_control == false} {set wall_control false} else {set wall_control true} - } - - proc UseBase {_base_set _base_control} { - variable base_set - variable base_control - if {$_base_set == false} {set base_set false} else {set base_set true} - if {$_base_control == false} {set base_control false} else {set base_control true} - } - - - proc WallParams {_wall_lag _wall_max _wall_tolerance} { - variable wall_lag - variable wall_max - variable wall_tolerance - set wall_lag $_wall_lag - set wall_max $_wall_max - set wall_tolerance $_wall_tolerance - hset /sample/tc2/control/tolerance1 $wall_tolerance - } - - proc TempSet {temp} { - variable wall_lag - variable wall_max - variable base_set - variable wall_set - set tempc [expr {$temp - $wall_lag}] - if {$tempc < 4} {set tempc 4} - if {$tempc > $wall_max} {set tempc $wall_max} - hset /sample/tc1/sensor/setpoint1 $temp - if {$base_set} {hset /sample/tc1/sensor/setpoint2 $tempc} - if {$wall_set} {hset /sample/tc2/sensor/setpoint1 $tempc} - } - - proc TempDrive {temp} { - variable wall_lag - variable wall_max - variable base_control - variable wall_control - TempSet $temp - set tempc [expr {$temp - $wall_lag}] - if {$tempc < 4} {set tempc 4} - if {$tempc > $wall_max} {set tempc $wall_max} - set drstr "drive tc1_driveable \$temp" - if {$base_control} {append drstr " tc1_driveable2 \$tempc"} - if {$wall_control} {append drstr " tc2_driveable \$tempc"} - eval $drstr - } - - proc Tolerance {sample} { - hset /sample/tc1/control/tolerance1 $sample - hset /sample/tc1/control/tolerance2 $sample - } - - proc MakeCold {} { - variable sample_tolerance - variable wall_tolerance - Tolerance 20 - hset /sample/tc2/control/tolerance1 20 - hset /sample/tc2/sensor/setpoint1 4 - TempDrive 4 - Tolerance $sample_tolerance - hset /sample/tc2/control/tolerance1 $wall_tolerance - wait 300 - } - - - proc TempRun {temp delay numsteps oscno} { - TempDrive $temp - wait $delay - newfile HISTOGRAM_XY - for {set i 0} {$i < $numsteps} {incr i} { - oct oscillate_count $oscno - oct oscillate start - hmm countblock - save $i - } - } - - proc RampRun {start step fin oscno delay} { - histmem mode unlimited - newfile HISTOGRAM_XY - set loopvar 1 - set i 0 - while {$loopvar} { - set j [expr {$i*$step+$start}] - if {$j> $fin && $step > 0} {break} - if {$j< $fin && $step < 0} {break} - TempSet $j - wait $delay - oct oscillate_count $oscno - oct oscillate start - hmm countblock - save $i - incr i - } - } - - proc StepRun {start step fin oscno delay} { - histmem mode unlimited - newfile HISTOGRAM_XY - set loopvar 1 - set i 0 - while {$loopvar} { - set j [expr {$i*$step+$start}] - if {$j> $fin && $step > 0} {break} - if {$j< $fin && $step < 0} {break} - TempDrive $j - wait $delay - oct oscillate_count $oscno - oct oscillate start - hmm countblock - save $i - incr i - } - } - - proc HeaterOn {} { - variable base_set - variable wall_set - - hset /sample/tc1/heater/heaterRange_1 4 - if {$base_set} {hset /sample/tc1/heater/heaterRange_2 4} - if {$wall_set} {hset /sample/tc2/heater/heaterRange 5} - } - - proc GetTemp {} { - variable base_set - set t1top [hget /sample/tc1/sensor/sensorValueA] - broadcast "sample top : $t1top" - if {$base_set} { - set t1base [hget /sample/tc1/sensor/sensorValueB] - broadcast "sample base: $t1base" - } - set t1wall [hget /sample/tc2/sensor/sensorValueA] - broadcast "sample wall: $t1wall" - } - - - - namespace export * - namespace ensemble create -} - -publish cf user - +# cf commands for driving sample environment +# ajs feb 2015 + +# cf namespace +# assumes tc1 and tc2 are the cf8 336 and 340 lakeshores for now + +namespace eval cf { + variable wall_lag 10 + variable wall_max 200 + variable sample_tolerance 5 + variable wall_tolerance 5 + variable wall_set true + variable base_set true + variable base_control true + variable wall_control true + + proc UseWall {_wall_set _wall_control} { + variable wall_set + variable wall_control + if {$_wall_set == false} {set wall_set false} else {set wall_set true} + if {$_wall_control == false} {set wall_control false} else {set wall_control true} + } + + proc UseBase {_base_set _base_control} { + variable base_set + variable base_control + if {$_base_set == false} {set base_set false} else {set base_set true} + if {$_base_control == false} {set base_control false} else {set base_control true} + } + +proc RampOn {rate} { + variable base_set + variable wall_set + + hset /sample/tc1/control/ramp_Loop_1 1,$rate + if {$base_set} {hset /sample/tc1/control/ramp_Loop_2 1,$rate} + if {$wall_set} {hset /sample/tc2/control/ramp_Loop_1 1,$rate} + wait 5 +} + +proc RampOff {} { + variable base_set + variable wall_set + + hset /sample/tc1/control/ramp_Loop_1 0,5 + if {$base_set} {hset /sample/tc1/control/ramp_Loop_2 0,5} + if {$wall_set} {hset /sample/tc2/control/ramp_Loop_1 0,5} + wait 5 + +} + + + proc WallParams {_wall_lag _wall_max _wall_tolerance} { + variable wall_lag + variable wall_max + variable wall_tolerance + set wall_lag $_wall_lag + set wall_max $_wall_max + set wall_tolerance $_wall_tolerance + hset /sample/tc2/control/tolerance1 $wall_tolerance + } + + proc TempSet {temp} { + variable wall_lag + variable wall_max + variable base_set + variable wall_set + set tempc [expr {$temp - $wall_lag}] + if {$tempc < 4} {set tempc 4} + if {$tempc > $wall_max} {set tempc $wall_max} + hset /sample/tc1/sensor/setpoint1 $temp + if {$base_set} {hset /sample/tc1/sensor/setpoint2 $temp} + if {$wall_set} {hset /sample/tc2/sensor/setpoint1 $tempc} + } + + proc TempDrive {temp} { + variable wall_lag + variable wall_max + variable base_control + variable wall_control + TempSet $temp + set tempc [expr {$temp - $wall_lag}] + if {$tempc < 4} {set tempc 4} + if {$tempc > $wall_max} {set tempc $wall_max} + set drstr "drive tc1_driveable \$temp" + if {$base_control} {append drstr " tc1_driveable2 \$temp"} + if {$wall_control} {append drstr " tc2_driveable \$tempc"} + eval $drstr + } + + proc Tolerance {sample} { + hset /sample/tc1/control/tolerance1 $sample + hset /sample/tc1/control/tolerance2 $sample + } + + proc MakeCold {} { + variable sample_tolerance + variable wall_tolerance + Tolerance 20 + hset /sample/tc2/control/tolerance1 20 + hset /sample/tc2/sensor/setpoint1 4 + TempDrive 4 + Tolerance $sample_tolerance + hset /sample/tc2/control/tolerance1 $wall_tolerance + wait 300 + } + + + proc TempRun {temp delay numsteps oscno} { + RampOff + TempDrive $temp + wait $delay + newfile HISTOGRAM_XY + for {set i 0} {$i < $numsteps} {incr i} { + oct oscillate_count $oscno + oct oscillate start + hmm countblock + save $i + } + } + + proc StepRun {start step fin oscno delay} { + RampOff + histmem mode unlimited + newfile HISTOGRAM_XY + set loopvar 1 + set i 0 + while {$loopvar} { + set j [expr {$i*$step+$start}] + if {$j> $fin && $step > 0} {break} + if {$j< $fin && $step < 0} {break} + TempSet $j + wait $delay + oct oscillate_count $oscno + oct oscillate start + hmm countblock + save $i + incr i + } + } + + proc StepWaitRun {start step fin oscno delay} { + RampOff + histmem mode unlimited + newfile HISTOGRAM_XY + set loopvar 1 + set i 0 + while {$loopvar} { + set j [expr {$i*$step+$start}] + if {$j> $fin && $step > 0} {break} + if {$j< $fin && $step < 0} {break} + TempDrive $j + wait $delay + oct oscillate_count $oscno + oct oscillate start + hmm countblock + save $i + incr i + } + } + + + proc RampRun {start rate fin oscno} { + + RampOff + TempSet $start + wait 5 + set tim1 [clock seconds] + set tlength [expr abs($start-$fin)/($rate/60.0)] + broadcast $rate $tlength + RampOn $rate + wait 5 + TempSet $fin + set bool 0 + set i 0 + histmem mode unlimited + newfile HISTOGRAM_XY + while {$bool==0} { + oct oscillate_count $oscno + oct oscillate start + hmm countblock + save $i + incr i + set tim2 [expr [clock seconds]-$tim1] + broadcast $tim2 + if {$tim2>$tlength} {set bool 1} + } + RampOff + + } + + proc HeaterOn {} { + variable base_set + variable wall_set + + hset /sample/tc1/heater/heaterRange_1 4 + if {$base_set} {hset /sample/tc1/heater/heaterRange_2 4} + if {$wall_set} {hset /sample/tc2/heater/heaterRange 5} + } + + proc HeaterOff {} { + variable base_set + variable wall_set + + hset /sample/tc1/heater/heaterRange_1 0 + if {$base_set} {hset /sample/tc1/heater/heaterRange_2 0} + if {$wall_set} {hset /sample/tc2/heater/heaterRange 0} + } + + proc GetTemp {} { + variable base_set + set t1top [hget /sample/tc1/sensor/sensorValueA] + broadcast "sample top : $t1top" + + if {$base_set} { + set t1base [hget /sample/tc1/sensor/sensorValueB] + broadcast "sample base: $t1base" + } + set t1wall [hget /sample/tc2/sensor/sensorValueA] + broadcast "sample wall: $t1wall" + } + + + + namespace export * + namespace ensemble create +} + +publish cf user + diff --git a/site_ansto/instrument/hipd/config/hmm/hmm_configuration.tcl b/site_ansto/instrument/hipd/config/hmm/hmm_configuration.tcl index 45c94986..58300baa 100644 --- a/site_ansto/instrument/hipd/config/hmm/hmm_configuration.tcl +++ b/site_ansto/instrument/hipd/config/hmm/hmm_configuration.tcl @@ -28,7 +28,7 @@ proc ::histogram_memory::init_OAT_TABLE {args} { hmm configure fat_frame_source INTERNAL - set resolution "double_x" +# set resolution "double_x" switch $resolution { "hires" { diff --git a/site_ansto/instrument/hipd/wombat_configuration.tcl b/site_ansto/instrument/hipd/wombat_configuration.tcl index 49d8c3a4..ef0c7499 100644 --- a/site_ansto/instrument/hipd/wombat_configuration.tcl +++ b/site_ansto/instrument/hipd/wombat_configuration.tcl @@ -97,7 +97,7 @@ SetVoltScale 1000.0 # LS336 02 at 205.29 # add_sct_ls336 tc2 10.157.205.30 7777 "\r\n" 1.0 1.0 # add_sct_ls336 tc1 10.157.205.31 7777 "\r\n" 1.0 1.0 -# add_sct_ls340 tc3 137.157.201.86 4001 "\r\n" 1.0 1.0 +# add_sct_ls340 tc3 137.157.201.86 4002 "\r\n" 1.0 1.0 server_init ###########################################