Changes to 3He driver

This commit is contained in:
Douglas Clowes
2014-10-22 11:56:28 +11:00
parent d9660d1f7b
commit 2ed8269a0f
2 changed files with 117 additions and 111 deletions

View File

@ -1,16 +1,31 @@
# vim: ts=8 sts=2 sw=2 expandtab autoindent smartindent nocindent # vim: ts=8 sts=2 sw=2 expandtab autoindent smartindent nocindent
driver he3_polanal = { driver he3_polanal = {
debug_threshold = 0;
protocol = std; protocol = std;
class = instrument; class = instrument;
simulation_group = rfgen_simulation; simulation_group = rfgen_simulation;
group = { group polariser = {
var spin = { var spin = {
type = text; type = text;
readable = 10; readable = 10;
read_command = 'spin 0 0'; read_command = 'polariser';
read_function = rdValue;
writeable = 1; writeable = 1;
write_command = 'spin '; write_command = 'polariser';
check_function = chkWrite; 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 = {%% code chkWrite = {%%
@ -19,60 +34,40 @@ driver he3_polanal = {
code rdValue = {%% code rdValue = {%%
set dlist [split ${data}] set dlist [split ${data}]
if {[lindex ${dlist} 0] != "Spin"} { if {[llength ${dlist}] < 2} {
sct geterror "Unexpected 'Spin' response '${data}'" sct geterror "Syntax Error: '${data}'"
error "[sct geterror]" error "[sct geterror]"
} }
set idx [lsearch ${dlist} "and"] set my_name [basename [pathname [sct]]]
if { ${idx} < 0 } { if {![string equal -nocase "[lindex ${dlist} 0]" "${my_name}"]} {
sct geterror "Unexpected 'and' response '${data}'" error "[lindex ${dlist} 0] is not ${my_name}"
error "[sct geterror]"
} }
set plist [lrange ${dlist} 1 ${idx}-1] if {[string match "*Not Active*" "${data}"]} {
set alist [lrange ${dlist} ${idx}+1 end] set data 0
if {[lindex ${plist} 0] != "Polariser"} { } elseif {[string match -nocase "*Error:*" "${data}"]} {
sct geterror "Unexpected 'Polariser' response '${data}'" sct geterror "${data}"
error "[sct geterror]" 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 { } else {
sct geterror "Unexpected 'Polariser State' response '${data}'" set data [lindex ${dlist} 1]
error "[sct geterror]"
} }
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 = {%% code setValue = {%%
set geterror "Spin target must be 'x/y', where x,y are 0,+,- and not '[sct target]'" set cmd "${cmd_str}"
set dlist [split [sct target]] if {[string equal -nocase [sct target] "dn"]} {
if {[llength ${dlist}] != 2} { set cmd "${cmd_str} -"
set dlist [split [sct target] /]
if {[llength ${dlist}] != 2} {
sct geterror ${geterror}
error "[sct geterror]"
}
} }
if { [lindex ${dlist} 0] != "+" && [lindex ${dlist} 0] != "-" && [lindex ${dlist} 0] != "0" } { if {[string equal -nocase [sct target] "down"]} {
sct geterror ${geterror} set cmd "${cmd_str} -"
error "[sct geterror]"
} }
if { [lindex ${dlist} 1] != "+" && [lindex ${dlist} 1] != "-" && [lindex ${dlist} 1] != "0" } { if {[sct target] == "-" || [sct target] == -1} {
sct geterror ${geterror} set cmd "${cmd_str} -"
error "[sct geterror]" }
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]"
%%} %%}
} }

View File

@ -3,7 +3,7 @@
# #
namespace eval ::scobj::he3_polanal { 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} { 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 # rdValue hook code starts
set dlist [split ${data}] set dlist [split ${data}]
if {[lindex ${dlist} 0] != "Spin"} { if {[llength ${dlist}] < 2} {
sct geterror "Unexpected 'Spin' response '${data}'" sct geterror "Syntax Error: '${data}'"
error "[sct geterror]" error "[sct geterror]"
} }
set idx [lsearch ${dlist} "and"] set my_name [basename [pathname [sct]]]
if { ${idx} < 0 } { if {![string equal -nocase "[lindex ${dlist} 0]" "${my_name}"]} {
sct geterror "Unexpected 'and' response '${data}'" error "[lindex ${dlist} 0] is not ${my_name}"
error "[sct geterror]"
} }
set plist [lrange ${dlist} 1 ${idx}-1] if {[string match "*Not Active*" "${data}"]} {
set alist [lrange ${dlist} ${idx}+1 end] set data 0
if {[lindex ${plist} 0] != "Polariser"} { } elseif {[string match -nocase "*Error:*" "${data}"]} {
sct geterror "Unexpected 'Polariser' response '${data}'" sct geterror "${data}"
error "[sct geterror]" 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 { } else {
sct geterror "Unexpected 'Polariser State' response '${data}'" set data [lindex ${dlist} 1]
error "[sct geterror]"
} }
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 # rdValue hook code ends
if { [hpropexists [sct] geterror] } { if { [hpropexists [sct] geterror] } {
debug_log ${tc_root} 9 "[sct] error: [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 par [sct target]
set cmd "${cmd_str}${par}" set cmd "${cmd_str}${par}"
# setValue hook code starts # setValue hook code starts
set geterror "Spin target must be 'x/y', where x,y are 0,+,- and not '[sct target]'" set cmd "${cmd_str}"
set dlist [split [sct target]] if {[string equal -nocase [sct target] "dn"]} {
if {[llength ${dlist}] != 2} { set cmd "${cmd_str} -"
set dlist [split [sct target] /]
if {[llength ${dlist}] != 2} {
sct geterror ${geterror}
error "[sct geterror]"
}
} }
if { [lindex ${dlist} 0] != "+" && [lindex ${dlist} 0] != "-" && [lindex ${dlist} 0] != "0" } { if {[string equal -nocase [sct target] "down"]} {
sct geterror ${geterror} set cmd "${cmd_str} -"
error "[sct geterror]"
} }
if { [lindex ${dlist} 1] != "+" && [lindex ${dlist} 1] != "-" && [lindex ${dlist} 1] != "0" } { if {[sct target] == "-" || [sct target] == -1} {
sct geterror ${geterror} set cmd "${cmd_str} -"
error "[sct geterror]" }
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 # setValue hook code ends
if { [hpropexists [sct] geterror] } { if { [hpropexists [sct] geterror] } {
debug_log ${tc_root} 9 "[sct] error: [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} set scobj_hpath /sics/${name}
hfactory ${scobj_hpath}/spin plain user text hfactory ${scobj_hpath}/analyser plain spy none
hsetprop ${scobj_hpath}/spin read ${ns}::getValue ${scobj_hpath} rdValue {spin 0 0} hsetprop ${scobj_hpath}/analyser data "true"
hsetprop ${scobj_hpath}/spin rdValue ${ns}::rdValue ${scobj_hpath} hsetprop ${scobj_hpath}/analyser klass "@none"
hsetprop ${scobj_hpath}/spin write ${ns}::setValue ${scobj_hpath} chkWrite {spin } hsetprop ${scobj_hpath}/analyser type "part"
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"
hsetprop ${scobj_hpath} data "true" hfactory ${scobj_hpath}/analyser/spin plain user text
hsetprop ${scobj_hpath} klass "@none" hsetprop ${scobj_hpath}/analyser/spin read ${ns}::getValue ${scobj_hpath} rdValue {analyser}
hsetprop ${scobj_hpath} type "part" 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"]} { if {[string equal -nocase "${simulation_flag}" "false"]} {
${sct_controller} poll ${scobj_hpath}/spin 10 ${sct_controller} poll ${scobj_hpath}/analyser/spin 10
${sct_controller} write ${scobj_hpath}/spin ${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 { } else {
::scobj::he3_polanal::sics_log 9 "simulation_flag=${simulation_flag} => No poll/write for he3_polanal" ::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} klass ${device_class}
hsetprop ${scobj_hpath} data true hsetprop ${scobj_hpath} data true
hsetprop ${scobj_hpath} debug_threshold 5 hsetprop ${scobj_hpath} debug_threshold 0
# mkDriver hook code goes here # mkDriver hook code goes here
} catch_message ] } catch_message ]
handle_exception ${catch_status} ${catch_message} handle_exception ${catch_status} ${catch_message}