diff --git a/site_ansto/instrument/config/environment/agilent_33220A.sct b/site_ansto/instrument/config/environment/agilent_33220A.sct index b731a821..35497eaa 100644 --- a/site_ansto/instrument/config/environment/agilent_33220A.sct +++ b/site_ansto/instrument/config/environment/agilent_33220A.sct @@ -3,7 +3,6 @@ driver agilent_33220A = { protocol = std class = environment simulation_group = environment_simulation - code mkDriver = {%% - makesctcontroller $name $ip $port + code mkWrapper = {%% %%} } diff --git a/site_ansto/instrument/config/environment/agilent_33220A_sct.tcl b/site_ansto/instrument/config/environment/agilent_33220A_sct.tcl index d67532f8..86d515bb 100644 --- a/site_ansto/instrument/config/environment/agilent_33220A_sct.tcl +++ b/site_ansto/instrument/config/environment/agilent_33220A_sct.tcl @@ -32,18 +32,8 @@ proc ::scobj::agilent_33220A::mkDriver { sct_controller name } { set ns "[namespace current]" set catch_status [ catch { - MakeSICSObj ${name} SCT_OBJECT - - sicslist setatt ${name} klass environment - sicslist setatt ${name} long_name ${name} - - set scobj_hpath /sics/${name} - hsetprop ${scobj_hpath} klass environment - hsetprop ${scobj_hpath} data true - hsetprop ${scobj_hpath} debug_threshold 5 -# mkDriver hook code starts - makesctcontroller $name $ip $port -# mkDriver hook code ends +# mkWrapper hook code starts +# mkWrapper hook code ends } catch_message ] handle_exception ${catch_status} ${catch_message} } diff --git a/site_ansto/instrument/config/environment/magneticField/green_magnet_labview.sct b/site_ansto/instrument/config/environment/magneticField/green_magnet_labview.sct new file mode 100644 index 00000000..0b042071 --- /dev/null +++ b/site_ansto/instrument/config/environment/magneticField/green_magnet_labview.sct @@ -0,0 +1,19 @@ +# vim: ts=8 sts=2 sw=2 expandtab autoindent smartindent nocindent +driver green_magnet_labview = { + wrapper_property nosctcontroller = true; + protocol = std + class = environment + simulation_group = environment_simulation + code mkWrapper = { +@TCL +# TCL code + ::scobj::green::mkGreen { + name "green_magnet" + IP 137.157.201.88 + PORT 5001 + tuning 1 + interval 3 + } +@END + } +} diff --git a/site_ansto/instrument/config/environment/magneticField/green_magnet_labview_sct.tcl b/site_ansto/instrument/config/environment/magneticField/green_magnet_labview_sct.tcl new file mode 100644 index 00000000..849a437b --- /dev/null +++ b/site_ansto/instrument/config/environment/magneticField/green_magnet_labview_sct.tcl @@ -0,0 +1,135 @@ +# Generated driver for green_magnet_labview +# vim: ft=tcl tabstop=8 softtabstop=2 shiftwidth=2 nocindent smartindent +# + +namespace eval ::scobj::green_magnet_labview { + set debug_threshold 5 +} + +proc ::scobj::green_magnet_labview::debug_log {tc_root debug_level debug_string} { + set catch_status [ catch { + set debug_threshold [hgetpropval ${tc_root} debug_threshold] + if {${debug_level} >= ${debug_threshold}} { + set fd [open "../log/green_magnet_labview_[basename ${tc_root}].log" "a"] + set line "[clock format [clock seconds] -format "%T"] ${debug_string}" + puts ${fd} "${line}" + close ${fd} + } + } catch_message ] +} + +proc ::scobj::green_magnet_labview::sics_log {debug_level debug_string} { + set catch_status [ catch { + set debug_threshold ${::scobj::green_magnet_labview::debug_threshold} + if {${debug_level} >= ${debug_threshold}} { + sicslog "::scobj::green_magnet_labview::${debug_string}" + } + } catch_message ] +} + +proc ::scobj::green_magnet_labview::mkDriver { sct_controller name } { + ::scobj::green_magnet_labview::sics_log 9 "::scobj::green_magnet_labview::mkDriver for ${name}" + set ns "[namespace current]" + set catch_status [ catch { + +# mkWrapper hook code starts +# TCL code + ::scobj::green::mkGreen { + name "green_magnet" + IP 137.157.201.88 + PORT 5001 + tuning 1 + interval 3 + } +# mkWrapper hook code ends + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +namespace eval ::scobj::green_magnet_labview { + namespace export debug_threshold + namespace export debug_log + namespace export sics_log + namespace export mkDriver +} + +proc add_green_magnet_labview {name IP port} { + set catch_status [ catch { + ::scobj::green_magnet_labview::sics_log 9 "add_green_magnet_labview ${name} ${IP} ${port}" + ::scobj::green_magnet_labview::sics_log 9 "No sctcontroller for green_magnet_labview" + ::scobj::green_magnet_labview::sics_log 1 "::scobj::green_magnet_labview::mkDriver sct_${name} ${name}" + ::scobj::green_magnet_labview::mkDriver sct_${name} ${name} + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +clientput "file evaluation of green_magnet_labview_sct.tcl" +::scobj::green_magnet_labview::sics_log 9 "file evaluation of green_magnet_labview_sct.tcl" + +proc ::scobj::green_magnet_labview::read_config {} { + set catch_status [ catch { + set ns "::scobj::green_magnet_labview" + dict for {k u} $::config_dict { + if { [dict exists $u "implementation"] } { + if { !([dict exists $u "name"] && [dict exists $u "enabled"]) } { + continue + } + set enabled [string tolower [dict get $u "enabled"]] + if { ! ([string equal -nocase $enabled "true" ] || [string equal -nocase $enabled "always"]) } { + continue + } + set name [dict get $u name] + set implementation [dict get $u "implementation"] + if { !([dict exists $::config_dict $implementation]) } { + continue + } + set v [dict get $::config_dict $implementation] + if { !([dict exists $v "driver"]) } { + continue + } + if { [string equal -nocase [dict get $v "driver"] "green_magnet_labview"] } { + if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } { + set asyncqueue "null" + ${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue" + } elseif { [dict exists $v "asyncqueue"] } { + set asyncqueue [dict get $v "asyncqueue"] + if { [string equal -nocase ${asyncqueue} "sct"] } { + set IP [dict get $v ip] + set PORT [dict get $v port] + } + } else { + if { [dict exists $v "asyncprotocol"] } { + set asyncprotocol [dict get $v "asyncprotocol"] + } else { + set asyncprotocol ${name}_protocol + MakeAsyncProtocol ${asyncprotocol} + if { [dict exists $v "terminator"] } { + ${asyncprotocol} sendterminator "[dict get $v "terminator"]" + ${asyncprotocol} replyterminator "[dict get $v "terminator"]" + } + } + set asyncqueue ${name}_queue + set IP [dict get $v ip] + set PORT [dict get $v port] + MakeAsyncQueue ${asyncqueue} ${asyncprotocol} ${IP} ${PORT} + if { [dict exists $v "timeout"] } { + ${asyncqueue} timeout "[dict get $v "timeout"]" + } + } + if { [string equal -nocase ${asyncqueue} "sct"] } { + add_green_magnet_labview ${name} ${IP} ${PORT} + } else { + add_green_magnet_labview ${name} "aqadapter" ${asyncqueue} + } + } + } + } + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +if { [info exists ::config_dict] } { + ::scobj::green_magnet_labview::read_config +} else { + ::scobj::green_magnet_labview::sics_log 5 "No config dict" +} diff --git a/site_ansto/instrument/config/environment/magneticField/oxford12tlv.sct b/site_ansto/instrument/config/environment/magneticField/oxford12tlv.sct new file mode 100644 index 00000000..09f685d4 --- /dev/null +++ b/site_ansto/instrument/config/environment/magneticField/oxford12tlv.sct @@ -0,0 +1,16 @@ +# vim: ts=8 sts=2 sw=2 expandtab autoindent smartindent nocindent +driver oxford12tlv = { + protocol = std + class = environment + simulation_group = environment_simulation + add_args = 'id datype interval' + make_args = 'id datype interval' + code mkDriver = {%% + ::scobj::magnetic::mkMagnetic [subst { + NAME $name + SCTCONTROLLER $sct_controller + TUNING 1 + INTERVAL $interval + }] + %%} +} diff --git a/site_ansto/instrument/config/environment/magneticField/oxford12tlv_sct.tcl b/site_ansto/instrument/config/environment/magneticField/oxford12tlv_sct.tcl new file mode 100644 index 00000000..c82dc42c --- /dev/null +++ b/site_ansto/instrument/config/environment/magneticField/oxford12tlv_sct.tcl @@ -0,0 +1,167 @@ +# Generated driver for oxford12tlv +# vim: ft=tcl tabstop=8 softtabstop=2 shiftwidth=2 nocindent smartindent +# + +namespace eval ::scobj::oxford12tlv { + set debug_threshold 5 +} + +proc ::scobj::oxford12tlv::debug_log {tc_root debug_level debug_string} { + set catch_status [ catch { + set debug_threshold [hgetpropval ${tc_root} debug_threshold] + if {${debug_level} >= ${debug_threshold}} { + set fd [open "../log/oxford12tlv_[basename ${tc_root}].log" "a"] + set line "[clock format [clock seconds] -format "%T"] ${debug_string}" + puts ${fd} "${line}" + close ${fd} + } + } catch_message ] +} + +proc ::scobj::oxford12tlv::sics_log {debug_level debug_string} { + set catch_status [ catch { + set debug_threshold ${::scobj::oxford12tlv::debug_threshold} + if {${debug_level} >= ${debug_threshold}} { + sicslog "::scobj::oxford12tlv::${debug_string}" + } + } catch_message ] +} + +proc ::scobj::oxford12tlv::mkDriver { sct_controller name id datype interval } { + ::scobj::oxford12tlv::sics_log 9 "::scobj::oxford12tlv::mkDriver ${sct_controller} ${name} ${id} ${datype} ${interval}" + set ns "[namespace current]" + set catch_status [ catch { + + MakeSICSObj ${name} SCT_OBJECT + + sicslist setatt ${name} klass environment + sicslist setatt ${name} long_name ${name} + + set scobj_hpath /sics/${name} + hsetprop ${scobj_hpath} klass environment + hsetprop ${scobj_hpath} data true + hsetprop ${scobj_hpath} debug_threshold 5 +# mkDriver hook code starts + ::scobj::magnetic::mkMagnetic [subst { + NAME $name + SCTCONTROLLER $sct_controller + TUNING 1 + INTERVAL $interval + }] +# mkDriver hook code ends + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +namespace eval ::scobj::oxford12tlv { + namespace export debug_threshold + namespace export debug_log + namespace export sics_log + namespace export mkDriver +} + +proc add_oxford12tlv {name IP port id datype interval} { + set catch_status [ catch { + ::scobj::oxford12tlv::sics_log 9 "add_oxford12tlv ${name} ${IP} ${port} ${id} ${datype} ${interval}" + if {[string equal -nocase [SplitReply [environment_simulation]] "false"]} { + if {[string equal -nocase "aqadapter" "${IP}"]} { + ::scobj::oxford12tlv::sics_log 9 "makesctcontroller sct_${name} aqadapter ${port}" + makesctcontroller sct_${name} aqadapter ${port} + } else { + ::scobj::oxford12tlv::sics_log 9 "makesctcontroller sct_${name} std ${IP}:${port}" + makesctcontroller sct_${name} std ${IP}:${port} + } + } else { + ::scobj::oxford12tlv::sics_log 9 "[environment_simulation] => No sctcontroller for oxford12tlv" + } + ::scobj::oxford12tlv::sics_log 1 "::scobj::oxford12tlv::mkDriver sct_${name} ${name} ${id} ${datype} ${interval}" + ::scobj::oxford12tlv::mkDriver sct_${name} ${name} ${id} ${datype} ${interval} + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +clientput "file evaluation of oxford12tlv_sct.tcl" +::scobj::oxford12tlv::sics_log 9 "file evaluation of oxford12tlv_sct.tcl" + +proc ::scobj::oxford12tlv::read_config {} { + set catch_status [ catch { + set ns "::scobj::oxford12tlv" + dict for {k u} $::config_dict { + if { [dict exists $u "implementation"] } { + if { !([dict exists $u "name"] && [dict exists $u "enabled"]) } { + continue + } + set enabled [string tolower [dict get $u "enabled"]] + if { ! ([string equal -nocase $enabled "true" ] || [string equal -nocase $enabled "always"]) } { + continue + } + set name [dict get $u name] + set implementation [dict get $u "implementation"] + if { !([dict exists $::config_dict $implementation]) } { + continue + } + set v [dict get $::config_dict $implementation] + if { !([dict exists $v "driver"]) } { + continue + } + if { [string equal -nocase [dict get $v "driver"] "oxford12tlv"] } { + if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } { + set asyncqueue "null" + ${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue" + } elseif { [dict exists $v "asyncqueue"] } { + set asyncqueue [dict get $v "asyncqueue"] + if { [string equal -nocase ${asyncqueue} "sct"] } { + set IP [dict get $v ip] + set PORT [dict get $v port] + } + } else { + if { [dict exists $v "asyncprotocol"] } { + set asyncprotocol [dict get $v "asyncprotocol"] + } else { + set asyncprotocol ${name}_protocol + MakeAsyncProtocol ${asyncprotocol} + if { [dict exists $v "terminator"] } { + ${asyncprotocol} sendterminator "[dict get $v "terminator"]" + ${asyncprotocol} replyterminator "[dict get $v "terminator"]" + } + } + set asyncqueue ${name}_queue + set IP [dict get $v ip] + set PORT [dict get $v port] + MakeAsyncQueue ${asyncqueue} ${asyncprotocol} ${IP} ${PORT} + if { [dict exists $v "timeout"] } { + ${asyncqueue} timeout "[dict get $v "timeout"]" + } + } + set arg_list [list] + set missing_list [list] + foreach arg {id datype interval} { + if {[dict exists $u $arg]} { + lappend arg_list "[dict get $u $arg]" + } elseif {[dict exists $v $arg]} { + lappend arg_list "[dict get $v $arg]" + } else { + ${ns}::sics_log 9 "Missing configuration value $arg" + lappend missing_list $arg + } + } + if { [llength $missing_list] > 0 } { + error "$name is missing configuration values $missing_list" + } + if { [string equal -nocase ${asyncqueue} "sct"] } { + add_oxford12tlv ${name} ${IP} ${PORT} {*}$arg_list + } else { + add_oxford12tlv ${name} "aqadapter" ${asyncqueue} {*}$arg_list + } + } + } + } + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +if { [info exists ::config_dict] } { + ::scobj::oxford12tlv::read_config +} else { + ::scobj::oxford12tlv::sics_log 5 "No config dict" +} diff --git a/site_ansto/instrument/config/environment/magneticField/sct_oxford_labview.tcl b/site_ansto/instrument/config/environment/magneticField/sct_oxford_labview.tcl index d9855ed8..3d99cb1e 100644 --- a/site_ansto/instrument/config/environment/magneticField/sct_oxford_labview.tcl +++ b/site_ansto/instrument/config/environment/magneticField/sct_oxford_labview.tcl @@ -181,7 +181,7 @@ proc ::scobj::magnetic::rdTempStateFunc {basePath field} { array set paraArr $s2 hset $basePath/Temp_s1 $paraArr(T1) hset $basePath/Temp_s2 $paraArr(T2) - hset $basePath/Temp_s3 $paraArr(T3) + hset $basePath/Pressure_s3 $paraArr(T3) set logText "Displayed Temp : $paraArr(T1) $paraArr(T2) $paraArr(T3)" } @@ -239,7 +239,6 @@ proc ::scobj::magnetic::mkMagnetic {argList} { set pa($KEY) $v } - MakeSICSObj $pa(NAME) SCT_OBJECT sicslist setatt $pa(NAME) klass environment sicslist setatt $pa(NAME) long_name $pa(NAME) @@ -255,7 +254,7 @@ proc ::scobj::magnetic::mkMagnetic {argList} { hfactory $hPath/Temp plain user text hfactory $hPath/Temp_s1 plain user float hfactory $hPath/Temp_s2 plain user float - hfactory $hPath/Temp_s3 plain user float + hfactory $hPath/Pressure_s3 plain user float #hfactory $hPath/Set_Sensor_Temp user float #hfactory $hPath/Set_Sensor_Channel user int @@ -306,7 +305,7 @@ proc ::scobj::magnetic::mkMagnetic {argList} { foreach {hdbPath klass control data nxsave mutable priv alias} [subst { /sics/$pa(NAME)/Temp_s1 NXsensor true true true true user magnetic_T1 /sics/$pa(NAME)/Temp_s2 NXsensor true true true true user magnetic_T2 - /sics/$pa(NAME)/Temp_s3 NXsensor true true true true user magnetic_T3 + /sics/$pa(NAME)/Pressure_s3 NXsensor true true true true user magnetic_P3 /sics/$pa(NAME)/magneticFieldCurrent NXsensor true true true true user magnetic_Field_Current /sics/$pa(NAME)/magneticFieldTesla NXsensor true true true true user magnetic_Field_Tesla /sics/$pa(NAME)/fieldSetPoint NXsensor true true true true user fieldSetPoint @@ -331,7 +330,7 @@ proc ::scobj::magnetic::mkMagnetic {argList} { # hset /sics/$fPath/start_temperature_s1 [hval /sics/$fPath/Temp_s1] # hset /sics/$fPath/start_temperature_s2 [hval /sics/$fPath/Temp_s2] -# hset /sics/$fPath/start_temperature_s3 [hval /sics/$fPath/Temp_s3] +# hset /sics/$fPath/start_temperature_s3 [hval /sics/$fPath/Pressure_s3] # } # proc ::histogram_memory::post_count "{fPath $pa(NAME)}" { @@ -339,10 +338,11 @@ proc ::scobj::magnetic::mkMagnetic {argList} { # hset /sics/$fPath/end_temperature_s1 [hval /sics/$fPath/Temp_s1] # hset /sics/$fPath/end_temperature_s2 [hval /sics/$fPath/Temp_s2] -# hset /sics/$fPath/end_temperature_s3 [hval /sics/$fPath/Temp_s3] +# hset /sics/$fPath/end_temperature_s3 [hval /sics/$fPath/Pressure_s3] # } - makesctcontroller sct_magnetic std $pa(IP):$pa(PORT) + set ::scobj::magnetic::sct_name $pa(SCTCONTROLLER) + set ::scobj::magnetic::magname $pa(NAME) hsetprop $hPath/field read ::scobj::magnetic::rqFieldFunc hsetprop $hPath/field rdFieldState ::scobj::magnetic::rdFieldStateFunc $hPath @@ -357,10 +357,10 @@ proc ::scobj::magnetic::mkMagnetic {argList} { hsetprop $hPath/DilutTempReading rdTempState ::scobj::magnetic::rdTempStateFunc $hPath "Dilut" if {[SplitReply [environment_simulation]]=="false"} { - sct_magnetic poll $hPath/field $pa(INTERVAL) - sct_magnetic poll $hPath/Temp $pa(INTERVAL) - sct_magnetic poll $hPath/HelioxTempReading $pa(INTERVAL) - sct_magnetic poll $hPath/DilutTempReading $pa(INTERVAL) + $pa(SCTCONTROLLER) poll $hPath/field $pa(INTERVAL) + $pa(SCTCONTROLLER) poll $hPath/Temp $pa(INTERVAL) + $pa(SCTCONTROLLER) poll $hPath/HelioxTempReading $pa(INTERVAL) + $pa(SCTCONTROLLER) poll $hPath/DilutTempReading $pa(INTERVAL) } hsetprop $hPath tuning $pa(TUNING) @@ -381,11 +381,11 @@ proc ::scobj::magnetic::mkMagnetic {argList} { hsetprop $hPath/set_magneticField checkReply ::scobj::magnetic::checkReplyFunc $hPath if {[SplitReply [environment_simulation]]=="false"} { - sct_magnetic write $hPath/set_rate - sct_magnetic write $hPath/set_magneticField - sct_magnetic write $hPath/set_DiluxTemp - sct_magnetic write $hPath/set_HelioxTemp - sct_magnetic write $hPath/set_HeaterSwitch + $pa(SCTCONTROLLER) write $hPath/set_rate + $pa(SCTCONTROLLER) write $hPath/set_magneticField + $pa(SCTCONTROLLER) write $hPath/set_DiluxTemp + $pa(SCTCONTROLLER) write $hPath/set_HelioxTemp + $pa(SCTCONTROLLER) write $hPath/set_HeaterSwitch } } } @@ -394,7 +394,7 @@ proc ::scobj::magnetic::mkMagnetic {argList} { # command is : OxfordSetField fieldValue P ; where "P" is an optinal parameter and if set will change # to posistent mode after changig the magnetic field proc OxfordSetField {{setPoint ""} {mode ""} args} { - set NAME "magnetic" + set NAME $::scobj::magnetic::magname if {$setPoint == ""} { if {$mode == ""} { broadcast "[hget /sample/$NAME/fieldSetPoint]" @@ -406,10 +406,10 @@ proc OxfordSetField {{setPoint ""} {mode ""} args} { if {$mode == ""} { set comm "setF $setPoint\r\n" - sct_magnetic send $comm + $::scobj::magnetic::sct_name send $comm } elseif {$mode == "P"} { set comm "setF $setPoint Pers\r\n" - sct_magnetic send $comm + $::scobj::magnetic::sct_name send $comm } else { broadcast "Wrong parameters being provided, check!" return @@ -429,27 +429,27 @@ proc OxfordSetField {{setPoint ""} {mode ""} args} { # Assign the rate of the changing magnetic field; # This needs only to be set once unless required proc OxfordSetRate {{setRate ""} args} { - set NAME "magnetic" + set NAME $::scobj::magnetic::magname if {$setRate == ""} { broadcast "[hget /sample/$NAME/fieldSetRate]" } else { hset /sample/$NAME/fieldSetRate $setRate set comm "setR $setRate\r\n" - sct_magnetic send $comm + $::scobj::magnetic::sct_name send $comm } } # Querying/Setting the Heliox sample temperature proc OxfordSetHTemp {{temp ""} args} { - set NAME "magnetic" + set NAME $::scobj::magnetic::magname if {$temp == ""} { broadcast "[hget /sample/$NAME/HelioxTempSetPoint]" } else { #hset /sample/$NAME/HelioxTempSetPoint $temp set comm "setHelioxTemp $temp\r\n" - sct_magnetic send $comm + $::scobj::magnetic::sct_name send $comm #set num 0 #while { $num <= 40 && [expr abs([hval /sample/$NAME/HelioxTempSetPoint] - [hval /sample/$NAME/HelioxTempReading]) ] >= 0.001 } { @@ -463,14 +463,14 @@ proc OxfordSetHTemp {{temp ""} args} { # Querying/Setting the Diluxtion Sample temperature proc OxfordSetDTemp {{temp ""} args} { - set NAME "magnetic" + set NAME $::scobj::magnetic::magname if {$temp == ""} { broadcast "[hget /sample/$NAME/DilutTempSetPoint]" } else { hset /sample/$NAME/DilutTempSetPoint $temp set comm "setDilutTemp $temp\r\n" - sct_magnetic send $comm + $::scobj::magnetic::sct_name send $comm } } @@ -485,7 +485,7 @@ proc OxfordSetHS {mode} { } set comm "setHS [string toupper $mode]\r\n" - sct_magnetic send $comm + $::scobj::magnetic::sct_name send $comm broadcast "Wait 60 seconds for the operation to complete before reset the mode" } @@ -494,101 +494,3 @@ publish OxfordSetRate user publish OxfordSetHTemp user publish OxfordSetDTemp user publish OxfordSetHS user - -proc add_oxford_labview { name IP PORT {interval 5} } { - ::scobj::magnetic::mkMagnetic [subst { - name $name - IP $IP - PORT $PORT - tuning 1 - interval $interval - }] -} - -namespace eval ::scobj::oxford_labview { -set debug_threshold 5 -} -proc ::scobj::oxford_labview::sics_log {debug_level debug_string} { - set catch_status [ catch { - set debug_threshold ${::scobj::oxford_labview::debug_threshold} - if {${debug_level} >= ${debug_threshold}} { - sicslog "::scobj::oxford_labview::${debug_string}" - } - } catch_message ] -} - -clientput "file evaluation of sct_oxford_labview.tcl" -::scobj::oxford_labview::sics_log 9 "file evaluation of sct_oxford_labview.tcl" - -proc ::scobj::oxford_labview::read_config {} { - set catch_status [ catch { - set ns "::scobj::oxford_labview" - dict for {k v} $::config_dict { - if { [dict exists $v "implementation"] } { - if { !([dict exists $v "name"] && [dict exists $v "enabled"]) } { - continue - } - set name [dict get $v name] - set enabled [string tolower [dict get $v "enabled"]] - set implementation [dict get $v "implementation"] - if { !([dict exists $::config_dict $implementation]) } { - continue - } - set v [dict get $::config_dict $implementation] - if { !([dict exists $v "driver"]) } { - continue - } - if { [string equal -nocase [dict get $v "driver"] "oxford_labview"] } { - set driver [dict get $v driver] - ${ns}::sics_log 9 "Found ${name}: $driver" - if { [string equal -nocase $enabled "true" ] || [string equal -nocase $enabled "always"] } { - if { ![string equal -nocase [SplitReply [environment_simulation]] "false"] } { - set asyncqueue "null" - ${ns}::sics_log 9 "[environment_simulation] => using null asyncqueue" - } elseif { [dict exists $v "asyncqueue"] } { - set asyncqueue [dict get $v "asyncqueue"] - } else { - if { [dict exists $v "asyncprotocol"] } { - set asyncprotocol [dict get $v "asyncprotocol"] - } else { - set asyncprotocol ${name}_protocol - ${ns}::sics_log 9 "${name}:${driver}: MakeAsyncProtocol ${asyncprotocol}" - MakeAsyncProtocol ${asyncprotocol} - if { [dict exists $v "terminator"] } { - ${asyncprotocol} sendterminator "[dict get $v "terminator"]" - ${asyncprotocol} replyterminator "[dict get $v "terminator"]" - } - } - set asyncqueue ${name}_queue - set IP [dict get $v ip] - set PORT [dict get $v port] - ${ns}::sics_log 9 "${name}:${driver}: MakeAsyncQueue ${asyncqueue} ${asyncprotocol} ${IP} ${PORT}" - MakeAsyncQueue ${asyncqueue} ${asyncprotocol} ${IP} ${PORT} - if { [dict exists $v "timeout"] } { - ${asyncqueue} timeout "[dict get $v "timeout"]" - } - } - set arg_list [list] -# foreach arg {interval} { -# if {[dict exists $v $arg]} { -# lappend arg_list "[dict get $v $arg]" -# } else { -# ${ns}::sics_log 9 "Missing configuration value $arg" -# error "Missing configuration value $arg" -# } -# } - ${ns}::sics_log 9 "add_oxford_labview ${name} aqadapter ${asyncqueue} {*}$arg_list" - add_oxford_labview ${name} "aqadapter" ${asyncqueue} {*}$arg_list - } - } - } - } - } catch_message ] - handle_exception ${catch_status} ${catch_message} -} - -if { [info exists ::config_dict] } { - ::scobj::oxford_labview::read_config -} else { - ::scobj::oxford_labview::sics_log 5 "No config dict" -} diff --git a/site_ansto/instrument/hipd/util/sics_config.ini b/site_ansto/instrument/hipd/util/sics_config.ini index b51987bf..6e3403e8 100644 --- a/site_ansto/instrument/hipd/util/sics_config.ini +++ b/site_ansto/instrument/hipd/util/sics_config.ini @@ -103,6 +103,7 @@ implementation = normal_sample_stage name = sample_stage optype = motion_axis [12tmagnet_oxford] +asyncqueue = sct desc = "12 Tesla Oxford Magnet" driver = "oxford_labview" imptype = magnetic_field diff --git a/site_ansto/instrument/hipd/wombat_configuration.tcl b/site_ansto/instrument/hipd/wombat_configuration.tcl index b3d61f26..210c4308 100644 --- a/site_ansto/instrument/hipd/wombat_configuration.tcl +++ b/site_ansto/instrument/hipd/wombat_configuration.tcl @@ -53,6 +53,7 @@ fileeval $cfPath(environment)/temperature/sct_qlink.tcl fileeval $cfPath(environment)/temperature/west400.tcl fileeval $cfPath(environment)/temperature/west4100_sct.tcl fileeval $cfPath(environment)/magneticField/sct_oxford_labview.tcl +fileeval $cfPath(environment)/magneticField/oxford12tlv_sct.tcl fileeval $cfPath(environment)/he3/sct_he3.tcl fileeval $cfPath(environment)/magneticField/sct_green_magnet.tcl fileeval $cfPath(hmm)/hmm_configuration.tcl diff --git a/site_ansto/instrument/hrpd/echidna_configuration.tcl b/site_ansto/instrument/hrpd/echidna_configuration.tcl index 9735a669..8b9c4234 100644 --- a/site_ansto/instrument/hrpd/echidna_configuration.tcl +++ b/site_ansto/instrument/hrpd/echidna_configuration.tcl @@ -30,6 +30,7 @@ fileeval $cfPath(environment)/temperature/sct_eurotherm_2000.tcl fileeval $cfPath(environment)/sct_keithley_2700.tcl fileeval $cfPath(environment)/magneticField/sct_green_magnet.tcl fileeval $cfPath(environment)/magneticField/sct_oxford_labview.tcl +fileeval $cfPath(environment)/magneticField/oxford12tlv_sct.tcl fileeval $cfPath(environment)/sct_keithley_2700.tcl fileeval $cfPath(environment)/temperature/sct_lakeshore_336.tcl fileeval $cfPath(environment)/temperature/sct_lakeshore_340.tcl diff --git a/site_ansto/instrument/hrpd/util/sics_config.ini b/site_ansto/instrument/hrpd/util/sics_config.ini index 23c74376..3a98c09f 100644 --- a/site_ansto/instrument/hrpd/util/sics_config.ini +++ b/site_ansto/instrument/hrpd/util/sics_config.ini @@ -100,6 +100,7 @@ implementation = normal_sample_stage name = sample_stage optype = motion_axis [12tmagnet_oxford] +asyncqueue = sct desc = "12 Tesla Oxford Magnet" driver = "oxford_labview" imptype = magnetic_field diff --git a/site_ansto/instrument/pelican/pelican_configuration.tcl b/site_ansto/instrument/pelican/pelican_configuration.tcl index e94fd300..10815556 100644 --- a/site_ansto/instrument/pelican/pelican_configuration.tcl +++ b/site_ansto/instrument/pelican/pelican_configuration.tcl @@ -56,6 +56,7 @@ fileeval $cfPath(environment)/temperature/sct_qlink.tcl fileeval $cfPath(environment)/temperature/west400.tcl fileeval $cfPath(environment)/temperature/west4100_sct.tcl fileeval $cfPath(environment)/magneticField/sct_oxford_labview.tcl +fileeval $cfPath(environment)/magneticField/oxford12tlv_sct.tcl fileeval $cfPath(environment)/he3/sct_he3.tcl fileeval $cfPath(environment)/magneticField/sct_green_magnet.tcl fileeval $cfPath(hmm)/hmm_configuration.tcl diff --git a/site_ansto/instrument/pelican/util/sics_config.ini b/site_ansto/instrument/pelican/util/sics_config.ini index 6ecdb579..53dfc3e2 100644 --- a/site_ansto/instrument/pelican/util/sics_config.ini +++ b/site_ansto/instrument/pelican/util/sics_config.ini @@ -89,9 +89,11 @@ implementation = normal_sample_stage name = sample_stage optype = motion_axis [12tmagnet_oxford] +asyncqueue = sct desc = "12 Tesla Oxford Magnet" -driver = "oxford_labview" +driver = "oxford12tlv" imptype = magnetic_field +interval = 5 ip = 10.157.205.3 port = 55001 diff --git a/site_ansto/instrument/rsd/kowari_configuration.tcl b/site_ansto/instrument/rsd/kowari_configuration.tcl index dd71e99f..fbbd6489 100644 --- a/site_ansto/instrument/rsd/kowari_configuration.tcl +++ b/site_ansto/instrument/rsd/kowari_configuration.tcl @@ -29,9 +29,8 @@ fileeval $cfPath(environment)/temperature/sct_lakeshore_336.tcl fileeval $cfPath(environment)/temperature/sct_lakeshore_340.tcl fileeval $cfPath(environment)/temperature/sct_eurotherm_2000.tcl fileeval $cfPath(environment)/sct_protek_common.tcl -fileeval $cfPath(environment)/temperature/sct_oxford_itc.tcl -fileeval $cfPath(environment)/magneticField/sct_oxford_ips.tcl fileeval $cfPath(environment)/magneticField/sct_oxford_labview.tcl +fileeval $cfPath(environment)/magneticField/oxford12tlv_sct.tcl fileeval $cfPath(hmm)/hmm_configuration.tcl fileeval $cfPath(nexus)/nxscripts.tcl fileeval $cfPath(scan)/scan.tcl diff --git a/site_ansto/instrument/sans/util/sics_config.ini b/site_ansto/instrument/sans/util/sics_config.ini index 8a3356b0..7257c7a3 100644 --- a/site_ansto/instrument/sans/util/sics_config.ini +++ b/site_ansto/instrument/sans/util/sics_config.ini @@ -156,6 +156,7 @@ desc = "Load the ten position sample changer configuration" imptype = motion_axis [12tmagnet_oxford] +asyncqueue = sct desc = "12 Tesla Oxford Magnet" driver = "oxford_labview" imptype = magnetic_field diff --git a/site_ansto/instrument/util/gen_sct.py b/site_ansto/instrument/util/gen_sct.py index c8b45372..e39e983a 100755 --- a/site_ansto/instrument/util/gen_sct.py +++ b/site_ansto/instrument/util/gen_sct.py @@ -80,6 +80,7 @@ reserved = { 'DEVICE' : 'DEVICE', 'PROTOCOL' : 'PROTOCOL', 'DRIVER_PROPERTY' : 'DRIVER_PROPERTY', + 'WRAPPER_PROPERTY' : 'WRAPPER_PROPERTY', 'CLASS' : 'CLASS', 'SIMULATION_GROUP' : 'SIMULATION_GROUP', 'DEBUG_THRESHOLD' : 'DEBUG_THRESHOLD', @@ -155,6 +156,8 @@ tokens = [ 'ID', 'TCL_BEG', 'TCL_END', + 'AT_TCL', + 'AT_END', ] + list(reserved.values()) # @@ -166,6 +169,20 @@ t_LBRACE = r'{' t_RBRACE = r'}' t_SLASH = r'/' +def t_AT_TCL(t): + r'@TCL' + if Verbose: + print 'AT_TCL' + t.lexer.begin('tcl') + #return t + +def t_tcl_AT_END(t): + r'[ \t]*@END' + if Verbose: + print 'AT_END' + t.lexer.begin('INITIAL') + #return t + def t_TCL_BEG(t): r'{%%' if Verbose: @@ -303,6 +320,7 @@ def p_driver_statement(p): | group | code | driver_property + | wrapper_property ''' p[0] = p[1] @@ -446,6 +464,12 @@ def p_driver_property(p): ''' p[0] = { 'DriverProperty' : ( p[2], p[4] ) } +def p_wrapper_property(p): + ''' + wrapper_property : WRAPPER_PROPERTY id_or_str EQUALS value + ''' + p[0] = { 'WrapperProperty' : ( p[2], p[4] ) } + def p_group_property(p): ''' group_property : GROUP_PROPERTY id_or_str EQUALS value @@ -505,6 +529,7 @@ def p_true_false(p): def p_code(p): ''' code : CODE code_type id_or_str EQUALS LBRACE code_block RBRACE + | CODE code_type id_or_str EQUALS LBRACE tcl_code_block RBRACE | CODE code_type id_or_str EQUALS TCL_BEG code_block TCL_END ''' p[0] = { 'Code' : { 'name' : p[3], 'type' : p[2], 'text' : p[6] }} @@ -524,6 +549,12 @@ def p_code_type(p): ''' p[0] = p[1] +def p_tcl_code_block(p): + ''' + tcl_code_block : AT_TCL code_block AT_END + ''' + p[0] = p[2] + def p_code_block(p): '''code_block : empty | code_block CODE_STRING @@ -794,6 +825,11 @@ def build_driver(MyDriver, TheTree): MyDriver['DriverProperty'] = {} MyDriver['DriverProperty'][item['DriverProperty'][0]] = item['DriverProperty'][1] continue + if 'WrapperProperty' in item: + if 'WrapperProperty' not in MyDriver: + MyDriver['WrapperProperty'] = {} + MyDriver['WrapperProperty'][item['WrapperProperty'][0]] = item['WrapperProperty'][1] + continue for key in item: MyDriver[key] = item[key] for item in MyDriver['Permlink']: @@ -1368,45 +1404,51 @@ def put_mkDriver(MyDriver): txt += [' set ns "[namespace current]"'] txt += [' set catch_status [ catch {'] txt += [''] - if len(MyDriver['Permlink']) > 0: - if 'make_args' in MyDriver and 'id' in MyDriver['make_args'].split(): - pass - else: - txt += [' set permlink_device_number [format "%02d" [incr ::scobj::permlink_device_counter]]'] - txt += [''] - if 'sobj_priv_type' in MyDriver: - priv_type = MyDriver['sobj_priv_type'].split() - ms_line = ' MakeSICSObj ${name} SCT_OBJECT %s %s' % (priv_type[0], priv_type[1]) - else: - ms_line = ' MakeSICSObj ${name} SCT_OBJECT' - txt += [ms_line] - txt += [''] - txt += [' sicslist setatt ${name} klass %s' % MyDriver['class']] - txt += [' sicslist setatt ${name} long_name ${name}'] - if 'DriverProperty' in MyDriver: - for key in MyDriver['DriverProperty']: - txt += [' sicslist setatt ${name} %s "%s"' % (key, MyDriver['DriverProperty'][key])] - txt += [''] - txt += [' set scobj_hpath /sics/${name}'] - - for group in sorted(MyDriver['Groups']): - txt += put_group(MyDriver, MyDriver['Groups'][group]) - - txt += [' hsetprop ${scobj_hpath} klass %s' % MyDriver['class']] - txt += [' hsetprop ${scobj_hpath} data true'] - txt += [' hsetprop ${scobj_hpath} debug_threshold %s' % str(MyDriver['debug_threshold'])] - if len(MyDriver['Deferred']) > 0: - txt += [' if {[string equal -nocase [SplitReply [%s]] "false"]} {' % MyDriver['simulation_group']] - for line in MyDriver['Deferred']: - txt += [' ' + line] - txt += [' }'] - func = 'mkDriver' + func = 'mkWrapper' if func in MyDriver['Funcs']: txt += ['# %s hook code starts' % func] txt += MyDriver['Funcs'][func]['text'] txt += ['# %s hook code ends' % func] else: - txt += ['# %s hook code goes here' % func] + if len(MyDriver['Permlink']) > 0: + if 'make_args' in MyDriver and 'id' in MyDriver['make_args'].split(): + pass + else: + txt += [' set permlink_device_number [format "%02d" [incr ::scobj::permlink_device_counter]]'] + txt += [''] + if 'sobj_priv_type' in MyDriver: + priv_type = MyDriver['sobj_priv_type'].split() + ms_line = ' MakeSICSObj ${name} SCT_OBJECT %s %s' % (priv_type[0], priv_type[1]) + else: + ms_line = ' MakeSICSObj ${name} SCT_OBJECT' + txt += [ms_line] + txt += [''] + txt += [' sicslist setatt ${name} klass %s' % MyDriver['class']] + txt += [' sicslist setatt ${name} long_name ${name}'] + if 'DriverProperty' in MyDriver: + for key in MyDriver['DriverProperty']: + txt += [' sicslist setatt ${name} %s "%s"' % (key, MyDriver['DriverProperty'][key])] + txt += [''] + txt += [' set scobj_hpath /sics/${name}'] + + for group in sorted(MyDriver['Groups']): + txt += put_group(MyDriver, MyDriver['Groups'][group]) + + txt += [' hsetprop ${scobj_hpath} klass %s' % MyDriver['class']] + txt += [' hsetprop ${scobj_hpath} data true'] + txt += [' hsetprop ${scobj_hpath} debug_threshold %s' % str(MyDriver['debug_threshold'])] + if len(MyDriver['Deferred']) > 0: + txt += [' if {[string equal -nocase [SplitReply [%s]] "false"]} {' % MyDriver['simulation_group']] + for line in MyDriver['Deferred']: + txt += [' ' + line] + txt += [' }'] + func = 'mkDriver' + if func in MyDriver['Funcs']: + txt += ['# %s hook code starts' % func] + txt += MyDriver['Funcs'][func]['text'] + txt += ['# %s hook code ends' % func] + else: + txt += ['# %s hook code goes here' % func] txt += [' } catch_message ]'] txt += [' handle_exception ${catch_status} ${catch_message}'] txt += ['}'] @@ -1432,22 +1474,25 @@ def put_postamble(MyDriver): txt += [' %s::sics_log 9 "add_%s ${name} ${IP} ${port} %s"' % (MyDriver['namespace'], MyDriver['name'], make_args)] else: txt += [' %s::sics_log 9 "add_%s ${name} ${IP} ${port}"' % (MyDriver['namespace'], MyDriver['name'])] - txt += [' if {[string equal -nocase [SplitReply [%s]] "false"]} {' % MyDriver['simulation_group']] - txt += [' if {[string equal -nocase "aqadapter" "${IP}"]} {'] - txt += [' %s::sics_log 9 "makesctcontroller sct_${name} aqadapter ${port}"' % MyDriver['namespace']] - txt += [' makesctcontroller sct_${name} aqadapter ${port}'] - txt += [' } else {'] - if 'protocol_args' in MyDriver: - protocol_args = MyDriver['protocol_args'].replace('\\', '\\\\').replace('"', '\\"') - txt += [' %s::sics_log 9 "makesctcontroller sct_${name} %s ${IP}:${port} %s"' % (MyDriver['namespace'], MyDriver['protocol'], protocol_args)] - txt += [' makesctcontroller sct_${name} %s ${IP}:${port} %s' % (MyDriver['protocol'], MyDriver['protocol_args'])] + if ('WrapperProperty' in MyDriver) and ('nosctcontroller' in MyDriver['WrapperProperty']): + txt += [' %s::sics_log 9 "No sctcontroller for %s"' % (MyDriver['namespace'], MyDriver['name'])] else: - txt += [' %s::sics_log 9 "makesctcontroller sct_${name} %s ${IP}:${port}"' % (MyDriver['namespace'], MyDriver['protocol'])] - txt += [' makesctcontroller sct_${name} %s ${IP}:${port}' % MyDriver['protocol']] - txt += [' }'] - txt += [' } else {'] - txt += [' %s::sics_log 9 "[%s] => No sctcontroller for %s"' % (MyDriver['namespace'], MyDriver['simulation_group'], MyDriver['name'])] - txt += [' }'] + txt += [' if {[string equal -nocase [SplitReply [%s]] "false"]} {' % MyDriver['simulation_group']] + txt += [' if {[string equal -nocase "aqadapter" "${IP}"]} {'] + txt += [' %s::sics_log 9 "makesctcontroller sct_${name} aqadapter ${port}"' % MyDriver['namespace']] + txt += [' makesctcontroller sct_${name} aqadapter ${port}'] + txt += [' } else {'] + if 'protocol_args' in MyDriver: + protocol_args = MyDriver['protocol_args'].replace('\\', '\\\\').replace('"', '\\"') + txt += [' %s::sics_log 9 "makesctcontroller sct_${name} %s ${IP}:${port} %s"' % (MyDriver['namespace'], MyDriver['protocol'], protocol_args)] + txt += [' makesctcontroller sct_${name} %s ${IP}:${port} %s' % (MyDriver['protocol'], MyDriver['protocol_args'])] + else: + txt += [' %s::sics_log 9 "makesctcontroller sct_${name} %s ${IP}:${port}"' % (MyDriver['namespace'], MyDriver['protocol'])] + txt += [' makesctcontroller sct_${name} %s ${IP}:${port}' % MyDriver['protocol']] + txt += [' }'] + txt += [' } else {'] + txt += [' %s::sics_log 9 "[%s] => No sctcontroller for %s"' % (MyDriver['namespace'], MyDriver['simulation_group'], MyDriver['name'])] + txt += [' }'] if 'make_args' in MyDriver: make_args = ' '.join(["${%s}"%arg for arg in MyDriver['make_args'].split()]) txt += [' %s::sics_log 1 "%s::mkDriver sct_${name} ${name} %s"' % (MyDriver['namespace'], MyDriver['namespace'], make_args)]