From 2676ab92825fbbd2132af0fb5cb2ec15498de898 Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Wed, 25 Jun 2014 12:19:35 +1000 Subject: [PATCH] Rework the LS-218 driver to make it flexible. --- .../environment/temperature/lakeshore_218.sct | 37 +++--- .../temperature/sct_lakeshore_218.tcl | 110 ++++++++++-------- 2 files changed, 75 insertions(+), 72 deletions(-) diff --git a/site_ansto/instrument/config/environment/temperature/lakeshore_218.sct b/site_ansto/instrument/config/environment/temperature/lakeshore_218.sct index 73ea7e81..f081597b 100644 --- a/site_ansto/instrument/config/environment/temperature/lakeshore_218.sct +++ b/site_ansto/instrument/config/environment/temperature/lakeshore_218.sct @@ -11,33 +11,28 @@ driver lakeshore_218 = { var krdg = { type = text; read_command = "KRDG? 0"; - read_function = read_temps; + value = "0,0,0,0,0,0,0,0"; } } group sensor = { - priv = user; + priv = user; mutable = true; type = float; - mutable = true; - var ch1 = { type = float; units = 'K'; } - var ch2 = { type = float; units = 'K'; } - var ch3 = { type = float; units = 'K'; } - var ch4 = { type = float; units = 'K'; } - var ch5 = { type = float; units = 'K'; } - var ch6 = { type = float; units = 'K'; } - var ch7 = { type = float; units = 'K'; } - var ch8 = { type = float; units = 'K'; } + readable = 1; + fetch_function = getTemp; + var ch1 = { read_command = '0'; } + var ch2 = { read_command = '1'; } + var ch3 = { read_command = '2'; } + var ch4 = { read_command = '3'; } + var ch5 = { read_command = '4'; } + var ch6 = { read_command = '5'; } + var ch7 = { read_command = '6'; } + var ch8 = { read_command = '7'; } } - code read_temps = {%% - set temps [split "${data}" ","] - hupdate ${tc_root}/sensor/ch1 [lindex ${temps} 0] - hupdate ${tc_root}/sensor/ch2 [lindex ${temps} 1] - hupdate ${tc_root}/sensor/ch3 [lindex ${temps} 2] - hupdate ${tc_root}/sensor/ch4 [lindex ${temps} 3] - hupdate ${tc_root}/sensor/ch5 [lindex ${temps} 4] - hupdate ${tc_root}/sensor/ch6 [lindex ${temps} 5] - hupdate ${tc_root}/sensor/ch7 [lindex ${temps} 6] - hupdate ${tc_root}/sensor/ch8 [lindex ${temps} 7] + code fetch_function getTemp = {%% + set temps [split "[hval ${tc_root}/krdg]" ","] + sct result [lindex ${temps} ${cmd_str}] + set cmd "@@NOSEND@@" %%} } 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 5032f8be..5c1db94c 100644 --- a/site_ansto/instrument/config/environment/temperature/sct_lakeshore_218.tcl +++ b/site_ansto/instrument/config/environment/temperature/sct_lakeshore_218.tcl @@ -53,6 +53,32 @@ proc ::scobj::lakeshore_218::checkrange {tc_root} { handle_exception ${catch_status} ${catch_message} } +# function to request the read of a parameter on a device +proc ::scobj::lakeshore_218::getTemp {tc_root nextState cmd_str} { + set catch_status [ catch { + debug_log ${tc_root} 1 "getTemp tc_root=${tc_root} sct=[sct] cmd=${cmd_str}" + if { [hpropexists [sct] geterror] } { + hdelprop [sct] geterror + } + set cmd "${cmd_str}" +# getTemp hook code starts + set temps [split "[hval ${tc_root}/krdg]" ","] + sct result [lindex ${temps} ${cmd_str}] + set cmd "@@NOSEND@@" +# getTemp hook code ends + if { [hpropexists [sct] geterror] } { + debug_log ${tc_root} 9 "[sct] error: [sct geterror]" + error "[sct geterror]" + } + debug_log ${tc_root} 1 "getTemp 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::lakeshore_218::getValue {tc_root nextState cmd_str} { set catch_status [ catch { @@ -107,46 +133,6 @@ proc ::scobj::lakeshore_218::rdValue {tc_root} { handle_exception ${catch_status} ${catch_message} } -# function to parse the read of a parameter on a device -proc ::scobj::lakeshore_218::read_temps {tc_root} { - set catch_status [ catch { - debug_log ${tc_root} 1 "read_temps tc_root=${tc_root} sct=[sct] result=[sct result]" - if { [hpropexists [sct] geterror] } { - hdelprop [sct] geterror - } - set data [sct result] - set nextState "idle" - if {[string equal -nocase -length 7 ${data} "ASCERR:"]} { - # the protocol driver has reported an error - sct geterror "${data}" - error "[sct geterror]" - } -# read_temps hook code starts - set temps [split "${data}" ","] - hupdate ${tc_root}/sensor/ch1 [lindex ${temps} 0] - hupdate ${tc_root}/sensor/ch2 [lindex ${temps} 1] - hupdate ${tc_root}/sensor/ch3 [lindex ${temps} 2] - hupdate ${tc_root}/sensor/ch4 [lindex ${temps} 3] - hupdate ${tc_root}/sensor/ch5 [lindex ${temps} 4] - hupdate ${tc_root}/sensor/ch6 [lindex ${temps} 5] - hupdate ${tc_root}/sensor/ch7 [lindex ${temps} 6] - hupdate ${tc_root}/sensor/ch8 [lindex ${temps} 7] -# read_temps hook code ends - if { [hpropexists [sct] geterror] } { - debug_log ${tc_root} 9 "[sct] error: [sct geterror]" - error "[sct geterror]" - } - if { ${data} != [sct oldval] } { - debug_log ${tc_root} 1 "[sct] changed to new:${data}, from old:[sct oldval]" - sct oldval ${data} - sct update ${data} - sct utime readtime - } - return ${nextState} - } catch_message ] - handle_exception ${catch_status} ${catch_message} -} - # function to write a parameter value on a device proc ::scobj::lakeshore_218::setValue {tc_root nextState cmd_str} { set catch_status [ catch { @@ -184,13 +170,14 @@ proc ::scobj::lakeshore_218::mkDriver { sct_controller name } { set scobj_hpath /sics/${name} hfactory ${scobj_hpath}/krdg plain user text - hsetprop ${scobj_hpath}/krdg read ${ns}::getValue ${scobj_hpath} read_temps {KRDG? 0} - hsetprop ${scobj_hpath}/krdg read_temps ${ns}::read_temps ${scobj_hpath} + hsetprop ${scobj_hpath}/krdg read ${ns}::getValue ${scobj_hpath} rdValue {KRDG? 0} + hsetprop ${scobj_hpath}/krdg rdValue ${ns}::rdValue ${scobj_hpath} hsetprop ${scobj_hpath}/krdg control false hsetprop ${scobj_hpath}/krdg data false hsetprop ${scobj_hpath}/krdg mutable false hsetprop ${scobj_hpath}/krdg nxsave false - hsetprop ${scobj_hpath}/krdg oldval UNKNOWN + hsetprop ${scobj_hpath}/krdg oldval 0,0,0,0,0,0,0,0 + hset ${scobj_hpath}/krdg 0,0,0,0,0,0,0,0 hsetprop ${scobj_hpath}/krdg sdsinfo "::nexus::scobj::sdsinfo" hsetprop ${scobj_hpath}/krdg type "part" hsetprop ${scobj_hpath}/krdg nxalias "${name}_krdg" @@ -204,92 +191,113 @@ proc ::scobj::lakeshore_218::mkDriver { sct_controller name } { hfactory ${scobj_hpath}/sensor plain spy none hfactory ${scobj_hpath}/sensor/ch1 plain user float + hsetprop ${scobj_hpath}/sensor/ch1 read ${ns}::getTemp ${scobj_hpath} rdValue {0} + hsetprop ${scobj_hpath}/sensor/ch1 rdValue ${ns}::rdValue ${scobj_hpath} hsetprop ${scobj_hpath}/sensor/ch1 control true hsetprop ${scobj_hpath}/sensor/ch1 data true hsetprop ${scobj_hpath}/sensor/ch1 mutable true hsetprop ${scobj_hpath}/sensor/ch1 nxsave true - hsetprop ${scobj_hpath}/sensor/ch1 units K hsetprop ${scobj_hpath}/sensor/ch1 oldval 0.0 hsetprop ${scobj_hpath}/sensor/ch1 sdsinfo "::nexus::scobj::sdsinfo" hsetprop ${scobj_hpath}/sensor/ch1 type "part" hsetprop ${scobj_hpath}/sensor/ch1 nxalias "${name}_sensor_ch1" hfactory ${scobj_hpath}/sensor/ch2 plain user float + hsetprop ${scobj_hpath}/sensor/ch2 read ${ns}::getTemp ${scobj_hpath} rdValue {1} + hsetprop ${scobj_hpath}/sensor/ch2 rdValue ${ns}::rdValue ${scobj_hpath} hsetprop ${scobj_hpath}/sensor/ch2 control true hsetprop ${scobj_hpath}/sensor/ch2 data true hsetprop ${scobj_hpath}/sensor/ch2 mutable true hsetprop ${scobj_hpath}/sensor/ch2 nxsave true - hsetprop ${scobj_hpath}/sensor/ch2 units K hsetprop ${scobj_hpath}/sensor/ch2 oldval 0.0 hsetprop ${scobj_hpath}/sensor/ch2 sdsinfo "::nexus::scobj::sdsinfo" hsetprop ${scobj_hpath}/sensor/ch2 type "part" hsetprop ${scobj_hpath}/sensor/ch2 nxalias "${name}_sensor_ch2" hfactory ${scobj_hpath}/sensor/ch3 plain user float + hsetprop ${scobj_hpath}/sensor/ch3 read ${ns}::getTemp ${scobj_hpath} rdValue {2} + hsetprop ${scobj_hpath}/sensor/ch3 rdValue ${ns}::rdValue ${scobj_hpath} hsetprop ${scobj_hpath}/sensor/ch3 control true hsetprop ${scobj_hpath}/sensor/ch3 data true hsetprop ${scobj_hpath}/sensor/ch3 mutable true hsetprop ${scobj_hpath}/sensor/ch3 nxsave true - hsetprop ${scobj_hpath}/sensor/ch3 units K hsetprop ${scobj_hpath}/sensor/ch3 oldval 0.0 hsetprop ${scobj_hpath}/sensor/ch3 sdsinfo "::nexus::scobj::sdsinfo" hsetprop ${scobj_hpath}/sensor/ch3 type "part" hsetprop ${scobj_hpath}/sensor/ch3 nxalias "${name}_sensor_ch3" hfactory ${scobj_hpath}/sensor/ch4 plain user float + hsetprop ${scobj_hpath}/sensor/ch4 read ${ns}::getTemp ${scobj_hpath} rdValue {3} + hsetprop ${scobj_hpath}/sensor/ch4 rdValue ${ns}::rdValue ${scobj_hpath} hsetprop ${scobj_hpath}/sensor/ch4 control true hsetprop ${scobj_hpath}/sensor/ch4 data true hsetprop ${scobj_hpath}/sensor/ch4 mutable true hsetprop ${scobj_hpath}/sensor/ch4 nxsave true - hsetprop ${scobj_hpath}/sensor/ch4 units K hsetprop ${scobj_hpath}/sensor/ch4 oldval 0.0 hsetprop ${scobj_hpath}/sensor/ch4 sdsinfo "::nexus::scobj::sdsinfo" hsetprop ${scobj_hpath}/sensor/ch4 type "part" hsetprop ${scobj_hpath}/sensor/ch4 nxalias "${name}_sensor_ch4" hfactory ${scobj_hpath}/sensor/ch5 plain user float + hsetprop ${scobj_hpath}/sensor/ch5 read ${ns}::getTemp ${scobj_hpath} rdValue {4} + hsetprop ${scobj_hpath}/sensor/ch5 rdValue ${ns}::rdValue ${scobj_hpath} hsetprop ${scobj_hpath}/sensor/ch5 control true hsetprop ${scobj_hpath}/sensor/ch5 data true hsetprop ${scobj_hpath}/sensor/ch5 mutable true hsetprop ${scobj_hpath}/sensor/ch5 nxsave true - hsetprop ${scobj_hpath}/sensor/ch5 units K hsetprop ${scobj_hpath}/sensor/ch5 oldval 0.0 hsetprop ${scobj_hpath}/sensor/ch5 sdsinfo "::nexus::scobj::sdsinfo" hsetprop ${scobj_hpath}/sensor/ch5 type "part" hsetprop ${scobj_hpath}/sensor/ch5 nxalias "${name}_sensor_ch5" hfactory ${scobj_hpath}/sensor/ch6 plain user float + hsetprop ${scobj_hpath}/sensor/ch6 read ${ns}::getTemp ${scobj_hpath} rdValue {5} + hsetprop ${scobj_hpath}/sensor/ch6 rdValue ${ns}::rdValue ${scobj_hpath} hsetprop ${scobj_hpath}/sensor/ch6 control true hsetprop ${scobj_hpath}/sensor/ch6 data true hsetprop ${scobj_hpath}/sensor/ch6 mutable true hsetprop ${scobj_hpath}/sensor/ch6 nxsave true - hsetprop ${scobj_hpath}/sensor/ch6 units K hsetprop ${scobj_hpath}/sensor/ch6 oldval 0.0 hsetprop ${scobj_hpath}/sensor/ch6 sdsinfo "::nexus::scobj::sdsinfo" hsetprop ${scobj_hpath}/sensor/ch6 type "part" hsetprop ${scobj_hpath}/sensor/ch6 nxalias "${name}_sensor_ch6" hfactory ${scobj_hpath}/sensor/ch7 plain user float + hsetprop ${scobj_hpath}/sensor/ch7 read ${ns}::getTemp ${scobj_hpath} rdValue {6} + hsetprop ${scobj_hpath}/sensor/ch7 rdValue ${ns}::rdValue ${scobj_hpath} hsetprop ${scobj_hpath}/sensor/ch7 control true hsetprop ${scobj_hpath}/sensor/ch7 data true hsetprop ${scobj_hpath}/sensor/ch7 mutable true hsetprop ${scobj_hpath}/sensor/ch7 nxsave true - hsetprop ${scobj_hpath}/sensor/ch7 units K hsetprop ${scobj_hpath}/sensor/ch7 oldval 0.0 hsetprop ${scobj_hpath}/sensor/ch7 sdsinfo "::nexus::scobj::sdsinfo" hsetprop ${scobj_hpath}/sensor/ch7 type "part" hsetprop ${scobj_hpath}/sensor/ch7 nxalias "${name}_sensor_ch7" hfactory ${scobj_hpath}/sensor/ch8 plain user float + hsetprop ${scobj_hpath}/sensor/ch8 read ${ns}::getTemp ${scobj_hpath} rdValue {7} + hsetprop ${scobj_hpath}/sensor/ch8 rdValue ${ns}::rdValue ${scobj_hpath} hsetprop ${scobj_hpath}/sensor/ch8 control true hsetprop ${scobj_hpath}/sensor/ch8 data true hsetprop ${scobj_hpath}/sensor/ch8 mutable true hsetprop ${scobj_hpath}/sensor/ch8 nxsave true - hsetprop ${scobj_hpath}/sensor/ch8 units K hsetprop ${scobj_hpath}/sensor/ch8 oldval 0.0 hsetprop ${scobj_hpath}/sensor/ch8 sdsinfo "::nexus::scobj::sdsinfo" hsetprop ${scobj_hpath}/sensor/ch8 type "part" hsetprop ${scobj_hpath}/sensor/ch8 nxalias "${name}_sensor_ch8" + + if {[string equal -nocase [SplitReply [environment_simulation]] "false"]} { + ${sct_controller} poll ${scobj_hpath}/sensor/ch1 1 + ${sct_controller} poll ${scobj_hpath}/sensor/ch2 1 + ${sct_controller} poll ${scobj_hpath}/sensor/ch3 1 + ${sct_controller} poll ${scobj_hpath}/sensor/ch4 1 + ${sct_controller} poll ${scobj_hpath}/sensor/ch5 1 + ${sct_controller} poll ${scobj_hpath}/sensor/ch6 1 + ${sct_controller} poll ${scobj_hpath}/sensor/ch7 1 + ${sct_controller} poll ${scobj_hpath}/sensor/ch8 1 + } else { + ::scobj::lakeshore_218::sics_log 9 "[environment_simulation] => No poll/write for lakeshore_218" + } hsetprop ${scobj_hpath} klass environment hsetprop ${scobj_hpath} debug_threshold 5 # mkDriver hook code goes here