diff --git a/site_ansto/instrument/util/script_context_util.tcl b/site_ansto/instrument/util/script_context_util.tcl index d15993ae..041a3a39 100644 --- a/site_ansto/instrument/util/script_context_util.tcl +++ b/site_ansto/instrument/util/script_context_util.tcl @@ -59,3 +59,46 @@ proc ::scobj::hinitprops {scobj args} { } } } + +## +# @brief find the node with property 'sicsdev' matching the given name +# start at top (or path) and work down +# @param name, the name of the device we are looking for (e.g. 'tc1') +# @param path, optional starting path (e.g. '/sample') +proc ::scobj::find_sicsdev {name {path "/"}} { + foreach node [hlist ${path}] { + if { [hpropexists ${path}/${node} sicsdev] } { + if { [string match -nocase "${name}" "[hgetpropval ${path}/${node} sicsdev]" } { + return [string map {// /} ${path}/${node}] + } + } + set result [find_dev ${name} ${path}/${node}] + if { ${result} != "" } { + return [string map {// /} ${result}] + } + } + return "" +} + +## +# @brief find the node with the property 'type' matching 'sct_object' +# start at the bottom and work up +# @param path, the path of the node where we start looking (e.g. '[sct]') +proc ::scobj::find_myobject {{path ""}} { + if { [string length "${path}"] == 0 } { + if { [catch { + set path "[sct]" + } catch_message] } { + set path "" + } + } + while { [string length ${path}] > 1 } { + if { [hpropexists ${path} type] } { + if { [string match -nocase "sct_object" "[hgetpropval ${path} type]"] } { + return [string map {// /} ${path}] + } + } + set path [pathname ${path}] + } + return "" +}