diff --git a/site_ansto/instrument/config/environment/magneticField/sct_bruker_BEC1.tcl b/site_ansto/instrument/config/environment/magneticField/sct_bruker_BEC1.tcl index 6dd5f31f..fa1dc6fd 100644 --- a/site_ansto/instrument/config/environment/magneticField/sct_bruker_BEC1.tcl +++ b/site_ansto/instrument/config/environment/magneticField/sct_bruker_BEC1.tcl @@ -1341,14 +1341,14 @@ namespace export mk_sct_bruker_BEC1 ## -# @brief add_bruker_BEC1() adds a scriptcontext object for a Bruker BEC1 power supply (1T magnet) +# @brief add_bruker_bec1() adds a scriptcontext object for a Bruker BEC1 power supply (1T magnet) # and makes it available to SICServer # @param name short name for the temperature controller scriptcontext object (typ. ma1 or ma2) # @param IP IP address of the device (e.g. IP of moxabox that hooks up to the BEC1) # @param port port number on the moxabox (typ. 4001, 4002, 4003, or 4004) # @param tol magnetic field strength tolerance in Tesla (default 0.1T) # @return nothing (well, the sct object) -proc add_bruker_BEC1 {name IP port {_tol 0.1} {CID 1} {CTYPE B} } { +proc add_bruker_bec1 {name IP port {_tol 0.1} {CID 1} {CTYPE B} } { # Don't create a magnet controller for the script validator, this may cause the # the BEC1 to lock up. # NOTE: This is placed outside the catch block because "return" raises an exception @@ -1363,27 +1363,91 @@ proc add_bruker_BEC1 {name IP port {_tol 0.1} {CID 1} {CTYPE B} } { mk_sct_bruker_BEC1 sct_bruker_BEC1_$name environment $name $_tol $CID $CTYPE makesctemon $name /sics/$name/emon/mon_mode /sics/$name/emon/is_in_tolerance /sics/$name/emon/errhandler } message ] - handle_exception $catch_status $message "In subroutine add_bruker_BEC1()." + handle_exception $catch_status $message "In subroutine add_bruker_bec1()." } -if {[ catch { - if { [ info exists ::config_dict ] } { - dict for {secname secinfo} $::config_dict { - if { [dict exists $secinfo "driver"] && ([dict get $secinfo "driver"] == "bruker_bec1") } { - if { [ dict get $::secinfo enabled ] } { - set name [dict get $::secinfo name] - set IP [dict get $::secinfo ip] - set PORT [dict get $::secinfo port] - set tol [dict get $::secinfo tol] - set cid [dict get $::secinfo id] - set ctype [dict get $::secinfo type] - add_bruker_BEC1 $name $IP $PORT $tol $cid $ctype +namespace eval ::scobj::bruker_bec1 { +set debug_threshold 5 +} +proc ::scobj::bruker_bec1::sics_log {debug_level debug_string} { + set catch_status [ catch { + set debug_threshold ${::scobj::bruker_bec1::debug_threshold} + if {${debug_level} >= ${debug_threshold}} { + sicslog "::scobj::bruker_bec1::${debug_string}" + } + } catch_message ] +} + +clientput "file evaluation of sct_bruker_bec1.tcl" +::scobj::bruker_bec1::sics_log 9 "file evaluation of sct_bruker_bec1.tcl" + +proc ::scobj::bruker_bec1::read_config {} { + set catch_status [ catch { + set ns "::scobj::bruker_bec1" + 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"] "bruker_bec1"] } { + 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 + 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] + foreach arg {tol id type} { + 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" + } + } + add_bruker_bec1 ${name} "aqadapter" ${asyncqueue} {*}$arg_list + } } } } - } -} message ]} { - clientput "ERROR: $message" + } catch_message ] + handle_exception ${catch_status} ${catch_message} } +if { [info exists ::config_dict] } { + ::scobj::bruker_bec1::read_config +} else { + ::scobj::bruker_bec1::sics_log 5 "No config dict" +} + + namespace import ::scobj::bruker_BEC1::* diff --git a/site_ansto/instrument/config/environment/temperature/sct_eurotherm_2000.tcl b/site_ansto/instrument/config/environment/temperature/sct_eurotherm_2000.tcl index 8b18c8fd..d6c2e1a7 100644 --- a/site_ansto/instrument/config/environment/temperature/sct_eurotherm_2000.tcl +++ b/site_ansto/instrument/config/environment/temperature/sct_eurotherm_2000.tcl @@ -348,7 +348,7 @@ debug_log "halt $tc_root" # @param IP, the IP address of the device, this can be a hostname, (eg ca5-kowari) # @param port, the IP protocol port number of the device (502 for modbus) # @param _tol (optional), this is the initial tolerance setting -proc add_et2000 {name IP port dev_id {_tol 5.0} {CID 1} {CTYPE T}} { +proc add_eurotherm_2000 {name IP port dev_id {_tol 5.0} {CID 1} {CTYPE T}} { set fd [open "../log/et2000.log" a] if {[SplitReply [environment_simulation]]=="false"} { puts $fd "makesctcontroller sct_${name} modbus ${IP}:$port" @@ -366,27 +366,90 @@ set fd [open "../log/et2000.log" w] puts $fd "file evaluation of sct_eurotherm_2000.tcl" close $fd -if {[ catch { - if { [ info exists ::config_dict ] } { - dict for {secname secinfo} $::config_dict { - if { [dict exists $secinfo "driver"] && ([dict get $secinfo "driver"] == "et2000") } { - if { [ dict get $::secinfo enabled ] } { - set name [dict get $::secinfo name] - set IP [dict get $::secinfo ip] - set PORT [dict get $::secinfo port] - set devid [dict get $::secinfo devid] - set tol [dict get $::secinfo tol] - set cid [dict get $::secinfo id] - set ctype [dict get $::secinfo type] - add_et2000 $name $IP $PORT $devid $tol $cid $ctype +namespace eval ::scobj::eurotherm_2000 { +set debug_threshold 5 +} +proc ::scobj::eurotherm_2000::sics_log {debug_level debug_string} { + set catch_status [ catch { + set debug_threshold ${::scobj::eurotherm_2000::debug_threshold} + if {${debug_level} >= ${debug_threshold}} { + sicslog "::scobj::eurotherm_2000::${debug_string}" + } + } catch_message ] +} + +clientput "file evaluation of sct_eurotherm_2000.tcl" +::scobj::eurotherm_2000::sics_log 9 "file evaluation of sct_eurotherm_2000.tcl" + +proc ::scobj::eurotherm_2000::read_config {} { + set catch_status [ catch { + set ns "::scobj::eurotherm_2000" + 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"] "eurotherm_2000"] } { + 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 + 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] + foreach arg {devid tol id type} { + 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" + } + } + add_eurotherm_2000 ${name} "aqadapter" ${asyncqueue} {*}$arg_list + } } } } - } -} message ]} { - clientput "ERROR: $message" + } catch_message ] + handle_exception ${catch_status} ${catch_message} } +if { [info exists ::config_dict] } { + ::scobj::eurotherm_2000::read_config +} else { + ::scobj::eurotherm_2000::sics_log 5 "No config dict" +} + + namespace import ::scobj::et2000::* #add_et2000 et2000 137.157.201.213 502 1 5 diff --git a/site_ansto/instrument/config/environment/temperature/sct_julabo_lh45.tcl b/site_ansto/instrument/config/environment/temperature/sct_julabo_lh45.tcl index bdd74746..cd5649a6 100644 --- a/site_ansto/instrument/config/environment/temperature/sct_julabo_lh45.tcl +++ b/site_ansto/instrument/config/environment/temperature/sct_julabo_lh45.tcl @@ -414,7 +414,7 @@ namespace eval ::scobj::lh45 { # @param port, the IP protocol port number of the device # @param sensor (optional), select the 'bath' sensor or an external sensor 'ext' # @param _tol (optional), this is the initial tolerance setting -proc add_lh45 { name IP port {sensor "bath"} {_tol 5.0} {CID 1} {CTYPE T} } { +proc add_julabo_lh45 { name IP port {sensor "bath"} {_tol 5.0} {CID 1} {CTYPE T} } { if {[SplitReply [environment_simulation]]=="false"} { makesctcontroller sct_lh45 std ${IP}:$port "\r" } @@ -434,25 +434,88 @@ proc add_lh45 { name IP port {sensor "bath"} {_tol 5.0} {CID 1} {CTYPE T} } { makesctemon $name /sics/$name/emon/monmode /sics/$name/emon/isintol /sics/$name/emon/errhandler } -if {[ catch { - if { [ info exists ::config_dict ] } { - dict for {secname secinfo} $::config_dict { - if { [dict exists $secinfo "driver"] && ([dict get $secinfo "driver"] == "lh45") } { - if { [ dict get $::secinfo enabled ] } { - set name [dict get $::secinfo name] - set IP [dict get $::secinfo ip] - set PORT [dict get $::secinfo port] - set sensor [dict get $::secinfo sensor] - set tol [dict get $::secinfo tol] - set cid [dict get $::secinfo id] - set ctype [dict get $::secinfo type] - add_lh45 $name $IP $PORT $sensor $tol $cid $ctype +namespace eval ::scobj::julabo_lh45 { +set debug_threshold 5 +} +proc ::scobj::julabo_lh45::sics_log {debug_level debug_string} { + set catch_status [ catch { + set debug_threshold ${::scobj::julabo_lh45::debug_threshold} + if {${debug_level} >= ${debug_threshold}} { + sicslog "::scobj::julabo_lh45::${debug_string}" + } + } catch_message ] +} + +clientput "file evaluation of sct_julabo_lh45.tcl" +::scobj::julabo_lh45::sics_log 9 "file evaluation of sct_julabo_lh45.tcl" + +proc ::scobj::julabo_lh45::read_config {} { + set catch_status [ catch { + set ns "::scobj::julabo_lh45" + 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"] "julabo_lh45"] } { + 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 + 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] + foreach arg {ctrl_sensor tol id type} { + 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" + } + } + add_julabo_lh45 ${name} "aqadapter" ${asyncqueue} {*}$arg_list + } } } } - } -} message ]} { - puts "ERROR: $message" + } catch_message ] + handle_exception ${catch_status} ${catch_message} } +if { [info exists ::config_dict] } { + ::scobj::julabo_lh45::read_config +} else { + ::scobj::julabo_lh45::sics_log 5 "No config dict" +} + + namespace import ::scobj::lh45::* diff --git a/site_ansto/instrument/config/environment/temperature/sct_watlow_pm.tcl b/site_ansto/instrument/config/environment/temperature/sct_watlow_pm.tcl index 38a76359..0661bc98 100644 --- a/site_ansto/instrument/config/environment/temperature/sct_watlow_pm.tcl +++ b/site_ansto/instrument/config/environment/temperature/sct_watlow_pm.tcl @@ -540,25 +540,87 @@ set fd [open "../log/watlow_pm.log" w] puts $fd "file evaluation of sct_watlow_pm.tcl" close $fd -if {[ catch { - if { [ info exists ::config_dict ] } { - dict for {secname secinfo} $::config_dict { - if { [dict exists $secinfo "driver"] && ([dict get $secinfo "driver"] == "watlow_pm") } { - if { [ dict get $::secinfo enabled ] } { - set name [dict get $::secinfo name] - set IP [dict get $::secinfo ip] - set PORT [dict get $::secinfo port] - set sensor [dict get $::secinfo sensor] - set tol [dict get $::secinfo tol] - set cid [dict get $::secinfo id] - set ctype [dict get $::secinfo type] - add_watlow_pm $name $IP $PORT $devid $tol $cid $ctype +namespace eval ::scobj::watlow_pm { +set debug_threshold 5 +} +proc ::scobj::watlow_pm::sics_log {debug_level debug_string} { + set catch_status [ catch { + set debug_threshold ${::scobj::watlow_pm::debug_threshold} + if {${debug_level} >= ${debug_threshold}} { + sicslog "::scobj::watlow_pm::${debug_string}" + } + } catch_message ] +} + +clientput "file evaluation of sct_watlow_pm.tcl" +::scobj::watlow_pm::sics_log 9 "file evaluation of sct_watlow_pm.tcl" + +proc ::scobj::watlow_pm::read_config {} { + set catch_status [ catch { + set ns "::scobj::watlow_pm" + 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"] "watlow_pm"] } { + 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 + 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] + foreach arg {devid tol id type} { + 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" + } + } + add_watlow_pm ${name} "aqadapter" ${asyncqueue} {*}$arg_list + } } } } - } -} message ]} { - clientput "ERROR: $message" + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +if { [info exists ::config_dict] } { + ::scobj::watlow_pm::read_config +} else { + ::scobj::watlow_pm::sics_log 5 "No config dict" } namespace import ::scobj::watlow_pm::* diff --git a/site_ansto/instrument/config/environment/temperature/sct_watlow_rm.tcl b/site_ansto/instrument/config/environment/temperature/sct_watlow_rm.tcl index 55f571d4..b94b82bf 100644 --- a/site_ansto/instrument/config/environment/temperature/sct_watlow_rm.tcl +++ b/site_ansto/instrument/config/environment/temperature/sct_watlow_rm.tcl @@ -570,25 +570,87 @@ set fd [open "../log/watlow_rm.log" w] puts $fd "file evaluation of sct_watlow_rm.tcl" close $fd -if {[ catch { - if { [ info exists ::config_dict ] } { - dict for {secname secinfo} $::config_dict { - if { [dict exists $secinfo "driver"] && ([dict get $secinfo "driver"] == "watlow_rm") } { - if { [ dict get $::secinfo enabled ] } { - set name [dict get $::secinfo name] - set IP [dict get $::secinfo ip] - set PORT [dict get $::secinfo port] - set sensor [dict get $::secinfo sensor] - set tol [dict get $::secinfo tol] - set cid [dict get $::secinfo id] - set ctype [dict get $::secinfo type] - add_watlow_rm $name $IP $PORT $devid $tol $cid $ctype +namespace eval ::scobj::watlow_rm { +set debug_threshold 5 +} +proc ::scobj::watlow_rm::sics_log {debug_level debug_string} { + set catch_status [ catch { + set debug_threshold ${::scobj::watlow_rm::debug_threshold} + if {${debug_level} >= ${debug_threshold}} { + sicslog "::scobj::watlow_rm::${debug_string}" + } + } catch_message ] +} + +clientput "file evaluation of sct_watlow_rm.tcl" +::scobj::watlow_rm::sics_log 9 "file evaluation of sct_watlow_rm.tcl" + +proc ::scobj::watlow_rm::read_config {} { + set catch_status [ catch { + set ns "::scobj::watlow_rm" + 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"] "watlow_rm"] } { + 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 + 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] + foreach arg {devid tol id type} { + 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" + } + } + add_watlow_rm ${name} "aqadapter" ${asyncqueue} {*}$arg_list + } } } } - } -} message ]} { - clientput "ERROR: $message" + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +if { [info exists ::config_dict] } { + ::scobj::watlow_rm::read_config +} else { + ::scobj::watlow_rm::sics_log 5 "No config dict" } namespace import ::scobj::watlow_rm::* diff --git a/site_ansto/instrument/config/environment/temperature/sct_watlow_st4.tcl b/site_ansto/instrument/config/environment/temperature/sct_watlow_st4.tcl index 452bf46b..be23a751 100644 --- a/site_ansto/instrument/config/environment/temperature/sct_watlow_st4.tcl +++ b/site_ansto/instrument/config/environment/temperature/sct_watlow_st4.tcl @@ -763,7 +763,7 @@ proc createNode {scobj_hpath sct_controller cmdGroup varName readable writable\ # @param IP, the IP address of the device, this can be a hostname, (eg ca5-kowari) # @param port, the IP protocol port number of the device (502 for modbus) # @param _tol (optional), this is the initial tolerance setting -proc add_watlow_st {name IP port dev_id {_tol 5.0} {CID 1} {CTYPE T}} { +proc add_watlow_st4 {name IP port dev_id {_tol 5.0} {CID 1} {CTYPE T}} { set fd [open "../log/watlow_st.log" a] if {[SplitReply [environment_simulation]]=="false"} { puts $fd "makesctcontroller sct_${name} modbus ${IP}:$port" @@ -781,25 +781,89 @@ set fd [open "../log/watlow_st.log" w] puts $fd "file evaluation of sct_watlow_st4.tcl" close $fd -if {[ catch { - if { [ info exists ::config_dict ] } { - dict for {secname secinfo} $::config_dict { - if { [dict exists $secinfo "driver"] && ([dict get $secinfo "driver"] == "watlow_st") } { - if { [ dict get $::secinfo enabled ] } { - set name [dict get $::secinfo name] - set IP [dict get $::secinfo ip] - set PORT [dict get $::secinfo port] - set sensor [dict get $::secinfo sensor] - set tol [dict get $::secinfo tol] - set cid [dict get $::secinfo id] - set ctype [dict get $::secinfo type] - add_watlow_st $name $IP $PORT $devid $tol $cid $ctype +namespace eval ::scobj::watlow_st4 { +set debug_threshold 5 +} +proc ::scobj::watlow_st4::sics_log {debug_level debug_string} { + set catch_status [ catch { + set debug_threshold ${::scobj::watlow_st4::debug_threshold} + if {${debug_level} >= ${debug_threshold}} { + sicslog "::scobj::watlow_st4::${debug_string}" + } + } catch_message ] +} + +clientput "file evaluation of sct_watlow_st4.tcl" +::scobj::watlow_st4::sics_log 9 "file evaluation of sct_watlow_st4.tcl" + +proc ::scobj::watlow_st4::read_config {} { + set catch_status [ catch { + set ns "::scobj::watlow_st4" + 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"] "watlow_st4"] } { + 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 + 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] + foreach arg {devid tol id type} { + 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" + } + } + add_watlow_st4 ${name} "aqadapter" ${asyncqueue} {*}$arg_list + } } } } - } -} message ]} { - clientput "ERROR: $message" + } catch_message ] + handle_exception ${catch_status} ${catch_message} } +if { [info exists ::config_dict] } { + ::scobj::watlow_st4::read_config +} else { + ::scobj::watlow_st4::sics_log 5 "No config dict" +} + + + namespace import ::scobj::watlow_st::* diff --git a/site_ansto/instrument/config/environment/temperature/west400.tcl b/site_ansto/instrument/config/environment/temperature/west400.tcl index 3b7b3717..53223d0f 100644 --- a/site_ansto/instrument/config/environment/temperature/west400.tcl +++ b/site_ansto/instrument/config/environment/temperature/west400.tcl @@ -31,7 +31,7 @@ sicslist setatt tc1 klass @none # This must be called when the instrument configuration is loaded and before\n # the buildHDB function is called. Currently there is no way to add and remove\n # environment controllers and their hdb paths at runtime. -proc ::environment::temperature::add_west400 {IP ID} { +proc ::environment::temperature::add_west4100 {IP ID} { set sim_mode [SplitReply [environment_simulation]] if {$sim_mode == "true"} { ::environment::temperature::mkwest400sim tc1 @@ -48,15 +48,86 @@ proc ::environment::temperature::add_west400 {IP ID} { #::environment::mkenvinfo tc1 {heateron {priv user} range {priv manager} } } -if { [ info exists ::config_dict ] } { - if { [ dict get $::config_dict vf1-west4100 enabled ] } { - set IP [dict get $::config_dict vf1-west4100 ip] - set ID [dict get $::config_dict vf1-west4100 id] - ::environment::temperature::add_west400 $IP $ID - } - if { [ dict get $::config_dict vf2-west4100 enabled ] } { - set IP [dict get $::config_dict vf2-west4100 ip] - set ID [dict get $::config_dict vf2-west4100 id] - ::environment::temperature::add_west400 $IP $ID - } + +namespace eval ::scobj::west4100 { +set debug_threshold 5 +} +proc ::scobj::west4100::sics_log {debug_level debug_string} { + set catch_status [ catch { + set debug_threshold ${::scobj::west4100::debug_threshold} + if {${debug_level} >= ${debug_threshold}} { + sicslog "::scobj::west4100::${debug_string}" + } + } catch_message ] +} + +clientput "file evaluation of sct_west4100.tcl" +::scobj::west4100::sics_log 9 "file evaluation of sct_west4100.tcl" + +proc ::scobj::west4100::read_config {} { + set catch_status [ catch { + set ns "::scobj::west4100" + 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"] "west4100"] } { + 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 + 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] + foreach arg {id} { + 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" + } + } + add_west4100 ${name} "aqadapter" ${asyncqueue} {*}$arg_list + } + } + } + } + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +if { [info exists ::config_dict] } { + ::scobj::west4100::read_config +} else { + ::scobj::west4100::sics_log 5 "No config dict" }