diff --git a/site_ansto/instrument/config/beamline/he3_polanal.sct b/site_ansto/instrument/config/beamline/he3_polanal.sct index 58541495..fe428deb 100644 --- a/site_ansto/instrument/config/beamline/he3_polanal.sct +++ b/site_ansto/instrument/config/beamline/he3_polanal.sct @@ -1,16 +1,31 @@ # vim: ts=8 sts=2 sw=2 expandtab autoindent smartindent nocindent driver he3_polanal = { + debug_threshold = 0; protocol = std; class = instrument; simulation_group = rfgen_simulation; - group = { + group polariser = { var spin = { type = text; readable = 10; - read_command = 'spin 0 0'; + read_command = 'polariser'; + read_function = rdValue; writeable = 1; - write_command = 'spin '; + write_command = 'polariser'; check_function = chkWrite; + allowed = "+,-,0" + } + } + group analyser = { + var spin = { + type = text; + readable = 10; + read_command = 'analyser'; + read_function = rdValue; + writeable = 1; + write_command = 'analyser'; + check_function = chkWrite; + allowed = "+,-,0" } } code chkWrite = {%% @@ -19,60 +34,40 @@ driver he3_polanal = { code rdValue = {%% set dlist [split ${data}] - if {[lindex ${dlist} 0] != "Spin"} { - sct geterror "Unexpected 'Spin' response '${data}'" + if {[llength ${dlist}] < 2} { + sct geterror "Syntax Error: '${data}'" error "[sct geterror]" } - set idx [lsearch ${dlist} "and"] - if { ${idx} < 0 } { - sct geterror "Unexpected 'and' response '${data}'" - error "[sct geterror]" + set my_name [basename [pathname [sct]]] + if {![string equal -nocase "[lindex ${dlist} 0]" "${my_name}"]} { + error "[lindex ${dlist} 0] is not ${my_name}" } - set plist [lrange ${dlist} 1 ${idx}-1] - set alist [lrange ${dlist} ${idx}+1 end] - if {[lindex ${plist} 0] != "Polariser"} { - sct geterror "Unexpected 'Polariser' response '${data}'" + if {[string match "*Not Active*" "${data}"]} { + set data 0 + } elseif {[string match -nocase "*Error:*" "${data}"]} { + sct geterror "${data}" error "[sct geterror]" - } elseif {[lindex ${plist} 1] == "In" && [lindex ${plist} 3] == "State"} { - set pstate [string index [lindex ${plist} 2] 1] - } elseif {[lindex ${plist} 1] == "Not" && [lindex ${plist} 2] == "Active"} { - set pstate 0 } else { - sct geterror "Unexpected 'Polariser State' response '${data}'" - error "[sct geterror]" + set data [lindex ${dlist} 1] } - if {[lindex ${alist} 0] != "Analyser"} { - sct geterror "Unexpected 'Analyser' response '${data}'" - error "[sct geterror]" - } elseif {[lindex ${alist} 1] == "In" && [lindex ${alist} 3] == "State"} { - set astate [string index [lindex ${alist} 2] 1] - } elseif {[lindex ${alist} 1] == "Not" && [lindex ${alist} 2] == "Active."} { - set astate 0 - } else { - sct geterror "Unexpected 'Analyser State' response '${data}'" - error "[sct geterror]" - } - set data "${pstate} ${astate}" %%} code setValue = {%% - set geterror "Spin target must be 'x/y', where x,y are 0,+,- and not '[sct target]'" - set dlist [split [sct target]] - if {[llength ${dlist}] != 2} { - set dlist [split [sct target] /] - if {[llength ${dlist}] != 2} { - sct geterror ${geterror} - error "[sct geterror]" - } + set cmd "${cmd_str}" + if {[string equal -nocase [sct target] "dn"]} { + set cmd "${cmd_str} -" } - if { [lindex ${dlist} 0] != "+" && [lindex ${dlist} 0] != "-" && [lindex ${dlist} 0] != "0" } { - sct geterror ${geterror} - error "[sct geterror]" + if {[string equal -nocase [sct target] "down"]} { + set cmd "${cmd_str} -" } - if { [lindex ${dlist} 1] != "+" && [lindex ${dlist} 1] != "-" && [lindex ${dlist} 1] != "0" } { - sct geterror ${geterror} - error "[sct geterror]" + if {[sct target] == "-" || [sct target] == -1} { + set cmd "${cmd_str} -" + } + if {[string equal -nocase [sct target] "up"]} { + set cmd "${cmd_str} +" + } + if {[sct target] == "+" || [sct target] == 1} { + set cmd "${cmd_str} +" } - set cmd "spin [lindex ${dlist} 0] [lindex ${dlist} 1]" %%} } diff --git a/site_ansto/instrument/config/beamline/sct_he3_polanal.tcl b/site_ansto/instrument/config/beamline/sct_he3_polanal.tcl index 2930048d..e4ee096a 100644 --- a/site_ansto/instrument/config/beamline/sct_he3_polanal.tcl +++ b/site_ansto/instrument/config/beamline/sct_he3_polanal.tcl @@ -3,7 +3,7 @@ # namespace eval ::scobj::he3_polanal { - set debug_threshold 5 + set debug_threshold 0 } proc ::scobj::he3_polanal::debug_log {tc_root debug_level debug_string} { @@ -99,40 +99,22 @@ proc ::scobj::he3_polanal::rdValue {tc_root} { } # rdValue hook code starts set dlist [split ${data}] - if {[lindex ${dlist} 0] != "Spin"} { - sct geterror "Unexpected 'Spin' response '${data}'" + if {[llength ${dlist}] < 2} { + sct geterror "Syntax Error: '${data}'" error "[sct geterror]" } - set idx [lsearch ${dlist} "and"] - if { ${idx} < 0 } { - sct geterror "Unexpected 'and' response '${data}'" - error "[sct geterror]" + set my_name [basename [pathname [sct]]] + if {![string equal -nocase "[lindex ${dlist} 0]" "${my_name}"]} { + error "[lindex ${dlist} 0] is not ${my_name}" } - set plist [lrange ${dlist} 1 ${idx}-1] - set alist [lrange ${dlist} ${idx}+1 end] - if {[lindex ${plist} 0] != "Polariser"} { - sct geterror "Unexpected 'Polariser' response '${data}'" + if {[string match "*Not Active*" "${data}"]} { + set data 0 + } elseif {[string match -nocase "*Error:*" "${data}"]} { + sct geterror "${data}" error "[sct geterror]" - } elseif {[lindex ${plist} 1] == "In" && [lindex ${plist} 3] == "State"} { - set pstate [string index [lindex ${plist} 2] 1] - } elseif {[lindex ${plist} 1] == "Not" && [lindex ${plist} 2] == "Active"} { - set pstate 0 } else { - sct geterror "Unexpected 'Polariser State' response '${data}'" - error "[sct geterror]" + set data [lindex ${dlist} 1] } - if {[lindex ${alist} 0] != "Analyser"} { - sct geterror "Unexpected 'Analyser' response '${data}'" - error "[sct geterror]" - } elseif {[lindex ${alist} 1] == "In" && [lindex ${alist} 3] == "State"} { - set astate [string index [lindex ${alist} 2] 1] - } elseif {[lindex ${alist} 1] == "Not" && [lindex ${alist} 2] == "Active."} { - set astate 0 - } else { - sct geterror "Unexpected 'Analyser State' response '${data}'" - error "[sct geterror]" - } - set data "${pstate} ${astate}" # rdValue hook code ends if { [hpropexists [sct] geterror] } { debug_log ${tc_root} 9 "[sct] error: [sct geterror]" @@ -159,24 +141,22 @@ proc ::scobj::he3_polanal::setValue {tc_root nextState cmd_str} { set par [sct target] set cmd "${cmd_str}${par}" # setValue hook code starts - set geterror "Spin target must be 'x/y', where x,y are 0,+,- and not '[sct target]'" - set dlist [split [sct target]] - if {[llength ${dlist}] != 2} { - set dlist [split [sct target] /] - if {[llength ${dlist}] != 2} { - sct geterror ${geterror} - error "[sct geterror]" - } + set cmd "${cmd_str}" + if {[string equal -nocase [sct target] "dn"]} { + set cmd "${cmd_str} -" } - if { [lindex ${dlist} 0] != "+" && [lindex ${dlist} 0] != "-" && [lindex ${dlist} 0] != "0" } { - sct geterror ${geterror} - error "[sct geterror]" + if {[string equal -nocase [sct target] "down"]} { + set cmd "${cmd_str} -" } - if { [lindex ${dlist} 1] != "+" && [lindex ${dlist} 1] != "-" && [lindex ${dlist} 1] != "0" } { - sct geterror ${geterror} - error "[sct geterror]" + if {[sct target] == "-" || [sct target] == -1} { + set cmd "${cmd_str} -" + } + if {[string equal -nocase [sct target] "up"]} { + set cmd "${cmd_str} +" + } + if {[sct target] == "+" || [sct target] == 1} { + set cmd "${cmd_str} +" } - set cmd "spin [lindex ${dlist} 0] [lindex ${dlist} 1]" # setValue hook code ends if { [hpropexists [sct] geterror] } { debug_log ${tc_root} 9 "[sct] error: [sct geterror]" @@ -208,35 +188,66 @@ proc ::scobj::he3_polanal::mkDriver { sct_controller name device_class simulatio set scobj_hpath /sics/${name} - hfactory ${scobj_hpath}/spin plain user text - hsetprop ${scobj_hpath}/spin read ${ns}::getValue ${scobj_hpath} rdValue {spin 0 0} - hsetprop ${scobj_hpath}/spin rdValue ${ns}::rdValue ${scobj_hpath} - hsetprop ${scobj_hpath}/spin write ${ns}::setValue ${scobj_hpath} chkWrite {spin } - hsetprop ${scobj_hpath}/spin chkWrite ${ns}::chkWrite ${scobj_hpath} - hsetprop ${scobj_hpath}/spin check ${ns}::checkrange ${scobj_hpath} - hsetprop ${scobj_hpath}/spin control true - hsetprop ${scobj_hpath}/spin data true - hsetprop ${scobj_hpath}/spin mutable true - hsetprop ${scobj_hpath}/spin nxsave true - hsetprop ${scobj_hpath}/spin oldval UNKNOWN - hsetprop ${scobj_hpath}/spin klass "parameter" - hsetprop ${scobj_hpath}/spin sdsinfo "::nexus::scobj::sdsinfo" - hsetprop ${scobj_hpath}/spin type "part" - hsetprop ${scobj_hpath}/spin nxalias "${name}_spin" + hfactory ${scobj_hpath}/analyser plain spy none + hsetprop ${scobj_hpath}/analyser data "true" + hsetprop ${scobj_hpath}/analyser klass "@none" + hsetprop ${scobj_hpath}/analyser type "part" - hsetprop ${scobj_hpath} data "true" - hsetprop ${scobj_hpath} klass "@none" - hsetprop ${scobj_hpath} type "part" + hfactory ${scobj_hpath}/analyser/spin plain user text + hsetprop ${scobj_hpath}/analyser/spin read ${ns}::getValue ${scobj_hpath} rdValue {analyser} + hsetprop ${scobj_hpath}/analyser/spin rdValue ${ns}::rdValue ${scobj_hpath} + hsetprop ${scobj_hpath}/analyser/spin write ${ns}::setValue ${scobj_hpath} chkWrite {analyser} + hsetprop ${scobj_hpath}/analyser/spin chkWrite ${ns}::chkWrite ${scobj_hpath} + hsetprop ${scobj_hpath}/analyser/spin check ${ns}::checkrange ${scobj_hpath} + hsetprop ${scobj_hpath}/analyser/spin control true + hsetprop ${scobj_hpath}/analyser/spin data true + hsetprop ${scobj_hpath}/analyser/spin mutable true + hsetprop ${scobj_hpath}/analyser/spin nxsave true + hsetprop ${scobj_hpath}/analyser/spin values -1,+1 + hsetprop ${scobj_hpath}/analyser/spin oldval UNKNOWN + hsetprop ${scobj_hpath}/analyser/spin klass "parameter" + hsetprop ${scobj_hpath}/analyser/spin sdsinfo "::nexus::scobj::sdsinfo" + hsetprop ${scobj_hpath}/analyser/spin type "part" + hsetprop ${scobj_hpath}/analyser/spin nxalias "${name}_analyser_spin" if {[string equal -nocase "${simulation_flag}" "false"]} { - ${sct_controller} poll ${scobj_hpath}/spin 10 - ${sct_controller} write ${scobj_hpath}/spin + ${sct_controller} poll ${scobj_hpath}/analyser/spin 10 + ${sct_controller} write ${scobj_hpath}/analyser/spin + } else { + ::scobj::he3_polanal::sics_log 9 "simulation_flag=${simulation_flag} => No poll/write for he3_polanal" + } + + hfactory ${scobj_hpath}/polariser plain spy none + hsetprop ${scobj_hpath}/polariser data "true" + hsetprop ${scobj_hpath}/polariser klass "@none" + hsetprop ${scobj_hpath}/polariser type "part" + + hfactory ${scobj_hpath}/polariser/spin plain user text + hsetprop ${scobj_hpath}/polariser/spin read ${ns}::getValue ${scobj_hpath} rdValue {polariser} + hsetprop ${scobj_hpath}/polariser/spin rdValue ${ns}::rdValue ${scobj_hpath} + hsetprop ${scobj_hpath}/polariser/spin write ${ns}::setValue ${scobj_hpath} chkWrite {polariser} + hsetprop ${scobj_hpath}/polariser/spin chkWrite ${ns}::chkWrite ${scobj_hpath} + hsetprop ${scobj_hpath}/polariser/spin check ${ns}::checkrange ${scobj_hpath} + hsetprop ${scobj_hpath}/polariser/spin control true + hsetprop ${scobj_hpath}/polariser/spin data true + hsetprop ${scobj_hpath}/polariser/spin mutable true + hsetprop ${scobj_hpath}/polariser/spin nxsave true + hsetprop ${scobj_hpath}/polariser/spin values -1,+1 + hsetprop ${scobj_hpath}/polariser/spin oldval UNKNOWN + hsetprop ${scobj_hpath}/polariser/spin klass "parameter" + hsetprop ${scobj_hpath}/polariser/spin sdsinfo "::nexus::scobj::sdsinfo" + hsetprop ${scobj_hpath}/polariser/spin type "part" + hsetprop ${scobj_hpath}/polariser/spin nxalias "${name}_polariser_spin" + + if {[string equal -nocase "${simulation_flag}" "false"]} { + ${sct_controller} poll ${scobj_hpath}/polariser/spin 10 + ${sct_controller} write ${scobj_hpath}/polariser/spin } else { ::scobj::he3_polanal::sics_log 9 "simulation_flag=${simulation_flag} => No poll/write for he3_polanal" } hsetprop ${scobj_hpath} klass ${device_class} hsetprop ${scobj_hpath} data true - hsetprop ${scobj_hpath} debug_threshold 5 + hsetprop ${scobj_hpath} debug_threshold 0 # mkDriver hook code goes here } catch_message ] handle_exception ${catch_status} ${catch_message}