diff --git a/site_ansto/instrument/config/environment/temperature/sct_lakeshore_218.tcl b/site_ansto/instrument/config/environment/temperature/sct_lakeshore_218.tcl index a9b32c08..72b30687 100644 --- a/site_ansto/instrument/config/environment/temperature/sct_lakeshore_218.tcl +++ b/site_ansto/instrument/config/environment/temperature/sct_lakeshore_218.tcl @@ -15,9 +15,16 @@ # # ----------------------------------------------------------------------------*/ +proc debug_log {args} { + set d1 [clock format [clock seconds] -format %d%h%Y] + set fd [open "../log/ls218Temp$d1.log" a] + puts $fd "[clock format [clock seconds] -format "%D %T "] [string trim $args "{}"]" + close $fd +} # Default temperature controller parameters namespace eval ::scobj::ls218 { + #variable logString "" } ############# Reading polled nodes ################################### @@ -61,6 +68,8 @@ proc ::scobj::ls218::getValue {idx cmd chID nextState} { # @param idx indicates which control loop or which input channel the command belongs to # @return idle Always returns system state idle - command sequence completed. proc ::scobj::ls218::rdValue {nodeName varName idx} { + #variable logString + if {[ catch { set replyData [string trimright [sct result] " \r\n"] set fields [split $replyData ,] @@ -96,6 +105,7 @@ proc ::scobj::ls218::rdValue {nodeName varName idx} { } } "Celsius" { hset $nodeName [lindex $fields 0] + #append $logString " Celsius - $fields;" set curValue [lindex $fields 0] } "CurveHd" { hset $nodeName/curve [lindex $fields 0] @@ -145,6 +155,7 @@ proc ::scobj::ls218::rdValue {nodeName varName idx} { } } "Kelvin" { hset $nodeName $fields + #append $logString " Kelvin - $fields;" set curValue $fields } "Linear" { hset $nodeName/varM [lindex $fields 0] @@ -175,22 +186,29 @@ proc ::scobj::ls218::rdValue {nodeName varName idx} { # 5 32 temp overrange # 6 64 units under range # 7 128 untis over range + set curValue $fields set field [string trimleft $fields 0] + if {[string length $field] == 0} { + set field 0 + } + set stateString "" set i [format %x $field] set i [expr 0x$i >> 4] set bitValue [expr 0x$i & 0x01] - if {$bitValue == 1} { append $nodeName "temp underrange, " } + if {$bitValue == 1} { append $stateString "temp underrange; " } set i [expr 0x$i >> 1] set bitValue [expr 0x$i & 0x01] - if {$bitValue == 1} { append $nodeName "temp overrange, " } + if {$bitValue == 1} { append $stateString "temp overrange; " } set i [expr 0x$i >> 1] set bitValue [expr 0x$i & 0x01] - if {$bitValue == 1} { append $nodeName "units under range, " } + if {$bitValue == 1} { append $stateString "units under range; " } set i [expr 0x$i >> 1] set bitValue [expr 0x$i & 0x01] - if {$bitValue == 1} { append $nodeName "untis over range" } + if {$bitValue == 1} { append $stateString "untis over range; " } + hset $nodeName $stateString } "SensorUnitValue" { hset $nodeName $fields + #append $logString " SensorUnitValue - $fields;" set curValue $fields } "data" { hset $nodeName $fields @@ -351,6 +369,8 @@ proc createParentHDBNode {hPath klass priv type control data} { # @param tol temperature tolerance in Kelvin (typ. 1) # @return nothing (well, the sct object) proc ::scobj::ls218::mkLS218 {argList} { + #variable logString + if {[ catch { foreach {k v} $argList { set KEY [string toupper $k] @@ -588,14 +608,14 @@ proc ::scobj::ls218::mkLS218 {argList} { # @internal time internal in polling the nodes # @return nothing (well, the sct object) -#::scobj::ls218::mkLS218 { -# name ls218 -# IP 137.157.202.219 -# PORT 4002 -# tuning 1 -# interval 5 -# inputChan {1 2 3 4 5 6 7 8} -# outputChan {1 2} -# relayChan {1 2 3 4 5 6 7 8} -#} +::scobj::ls218::mkLS218 { + name ls218 + IP 137.157.202.214 + PORT 4002 + tuning 1 + interval 5 + inputChan {1 2} + outputChan {} + relayChan {} +} diff --git a/site_ansto/instrument/pelican/config/hmm/hmm_configuration.tcl b/site_ansto/instrument/pelican/config/hmm/hmm_configuration.tcl index b43ca8b1..db420279 100644 --- a/site_ansto/instrument/pelican/config/hmm/hmm_configuration.tcl +++ b/site_ansto/instrument/pelican/config/hmm/hmm_configuration.tcl @@ -8,14 +8,15 @@ set sim_mode [SplitReply [hmm_simulation]] # Elastic peak index and time of flight channel width ::utility::mkVar elpk int user elpk true detector true true sicslist setatt elpk link data_set -::utility::mkVar tofw int user tofw true detector true true +::utility::mkVar tofw float user tofw true detector true true sicslist setatt tofw link data_set -sicslist setatt tofw units [::histogram_memory::clock_scale units] proc ::histogram_memory::init_OAT_TABLE {} { + variable INST_NXC "oat_nxc_eff" + variable INST_NYC "oat_nyc_eff" + if [ catch { - set twidth 3333 OAT_TABLE X -setdata MAX_CHAN 200 OAT_TABLE Y -setdata MAX_CHAN 1024 OAT_TABLE X -setdata BMIN -0.5 @@ -23,8 +24,32 @@ proc ::histogram_memory::init_OAT_TABLE {} { OAT_TABLE Y -setdata BMIN -0.5 OAT_TABLE Y -setdata BMAX 1023.5 - OAT_TABLE -set X { 199.5 198.5 } NXC 200 Y { -0.5 0.5 } NYC 64 T " 0 $twidth " NTC 1024 - tofw $twidth + set clock_scale 1000 + set freq 200 + set tbins 1000 + set xbins 200 + set ybins 64 + + set period [expr 1.0/$freq] + set tbinwidth_ns [expr $period/$tbins * 1e9] + hmm configure fat_clock_scale $clock_scale + hmm configure fat_frame_frequency $freq + # The entries in the time bin array are in nanoseconds/clock_scale because the clock base is in nanoseconds + set tbb0 0.0 + set tbb1 [expr $tbb0 + $tbinwidth_ns / $clock_scale] + OAT_TABLE -set X { 199.5 198.5 } NXC $xbins Y { -0.5 15.5 } NYC $ybins T "$tbb0 $tbb1" NTC $tbins + + # Use the ::histogram_memory::clock_scale function to make sure that the value in the + # time of flight channel width is consistent with its units + sicslist setatt tofw units [::histogram_memory::clock_scale units] + tofw [expr ($tbb1 - $tbb0) * [::histogram_memory::clock_scale]] + + if {$::sim_mode == "true"} { + hmm configure oat_ntc_eff $tbins + hmm configure $INST_NYC $ybins + hmm configure $INST_NXC $xbins + } + } message ] { if {$::errorCode=="NONE"} {return $message} return -code error $message @@ -151,16 +176,9 @@ proc ::histogram_memory::pre_count {} {} proc ::histogram_memory::post_count {} {} proc ::histogram_memory::isc_initialize {} { # Instrument specific X and Y dimension names - variable INST_NXC "oat_nxc_eff" - variable INST_NYC "oat_nyc_eff" if [ catch { ::histogram_memory::init_hmm_objs - if {$::sim_mode == "true"} { - hmm configure oat_ntc_eff 1024 - hmm configure $INST_NYC 64 - hmm configure $INST_NXC 200 - } BAT_TABLE -init # CAT_TABLE -init SAT_TABLE -init @@ -197,7 +215,69 @@ proc ::histogram_memory::isc_initialize {} { } proc histmem {cmd args} { - eval "_histmem $cmd $args" + set catch_status [ catch { + switch $cmd { + "tbins" { + if {$args == ""} { + set reply [OAT_TABLE -get NTC] + } else { + if {[llength $args] != 2} { + error "There should be two arguments in $args, the number of time bins and the desired frame frequency" + } else { + foreach {numbins freq} $args {} + if { ![string is integer $numbins]} { + error "$numbins should be an integer" + } + if { ![string is double $freq]} { + error "$freq should be a number" + } + set period [expr 1.0/$freq] + set tbinwidth_us [expr $period/$numbins * 1e6] + set clock_scale [::histogram_memory::clock_scale] + set tbb0 0.0 + set tbb1 [expr $tbb0 + $tbinwidth_us / $clock_scale] + hmm configure fat_frame_frequency $freq + OAT_TABLE -set T "$tbb0 $tbb1" NTC $numbins + set reply [_histmem loadconf] + } + } + } + "twidth" { + if {$args == ""} { + set tbins [OAT_TABLE -get T] + set tb0 [lindex $tbins 0] + set tb1 [lindex $tbins 1] + set reply [expr {($tb1 - $tb0) / [::histogram_memory::clock_scale]}] + } else { + if {[llength $args] != 2} { + error "There should be two arguments in $args, the desired time bin width and the frame frequency" + } else { + foreach {binw_us freq} $args {} + if { ![string is double $binw_us]} { + error "$binw_us should be a number" + } + if { ![string is double $freq]} { + error "$freq should be a number" + } + set period_us [expr {1e6/$freq}] + set numbins [expr {round(0.5 + $period_us/$binw_us)}] + set clock_scale [::histogram_memory::clock_scale] + set tbinwidth [expr {$binw_us / $clock_scale}] + set tbb0 0.0 + set tbb1 [expr $tbb0 + $tbinwidth] + hmm configure fat_frame_frequency $freq + OAT_TABLE -set T "$tbb0 $tbb1" NTC $numbins + set reply [_histmem loadconf] + } + } + } + default { + set reply [eval "_histmem $cmd $args"] + } + } + return $reply + } msg ] + handle_exception $catch_status $msg } publish histmem user diff --git a/site_ansto/instrument/pelican/pelican_configuration.tcl b/site_ansto/instrument/pelican/pelican_configuration.tcl index a27a1a8f..7b97c07a 100644 --- a/site_ansto/instrument/pelican/pelican_configuration.tcl +++ b/site_ansto/instrument/pelican/pelican_configuration.tcl @@ -24,6 +24,7 @@ fileeval $cfPath(motors)/positmotor_configuration.tcl fileeval $cfPath(plc)/plc.tcl fileeval $cfPath(counter)/counter.tcl fileeval $cfPath(beamline)/sct_power.tcl +fileeval $cfPath(environment)/temperature/sct_lakeshore_218.tcl fileeval $cfPath(hmm)/hmm_configuration.tcl fileeval $cfPath(hmm)/sct_hv.tcl fileeval $cfPath(nexus)/nxscripts.tcl