Files
sics/site_ansto/instrument/config/environment/temperature/sct_ls336.tcl
2014-07-15 08:59:18 +10:00

162 lines
5.9 KiB
Tcl

# Generated driver for ls336
# vim: ft=tcl tabstop=8 softtabstop=2 shiftwidth=2 nocindent smartindent
#
namespace eval ::scobj::ls336 {
set debug_threshold 5
}
proc ::scobj::ls336::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/ls336_[basename ${tc_root}].log" "a"]
set line "[clock format [clock seconds] -format "%T"] ${debug_string}"
puts ${fd} "${line}"
close ${fd}
}
} catch_message ]
}
proc ::scobj::ls336::sics_log {debug_level debug_string} {
set catch_status [ catch {
set debug_threshold ${::scobj::ls336::debug_threshold}
if {${debug_level} >= ${debug_threshold}} {
sicslog "::scobj::ls336::${debug_string}"
}
} catch_message ]
}
proc ::scobj::ls336::mkDriver { sct_controller name id datype tol1 tol2 } {
::scobj::ls336::sics_log 9 "::scobj::ls336::mkDriver ${sct_controller} ${name} ${id} ${datype} ${tol1} ${tol2}"
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} debug_threshold 5
# mkDriver hook code starts
::scobj::ls336::mk_sct_lakeshore_336 $sct_controller environment $name $id $datype $tol1 $tol2 0
# mkDriver hook code ends
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
namespace eval ::scobj::ls336 {
namespace export debug_threshold
namespace export debug_log
namespace export sics_log
namespace export mkDriver
}
proc add_ls336 {name IP port id datype {tol1 1.0} {tol2 1.0}} {
set catch_status [ catch {
::scobj::ls336::sics_log 9 "add_ls336 ${name} ${IP} ${port} ${id} ${datype} ${tol1} ${tol2}"
if {[string equal -nocase [SplitReply [environment_simulation]] "false"]} {
if {[string equal -nocase "aqadapter" "${IP}"]} {
::scobj::ls336::sics_log 9 "makesctcontroller sct_${name} aqadapter ${port}"
makesctcontroller sct_${name} aqadapter ${port}
} else {
::scobj::ls336::sics_log 9 "makesctcontroller sct_${name} std ${IP}:${port}"
makesctcontroller sct_${name} std ${IP}:${port}
}
} else {
::scobj::ls336::sics_log 9 "[environment_simulation] => No sctcontroller for ls336"
}
::scobj::ls336::sics_log 1 "::scobj::ls336::mkDriver sct_${name} ${name} ${id} ${datype} ${tol1} ${tol2}"
::scobj::ls336::mkDriver sct_${name} ${name} ${id} ${datype} ${tol1} ${tol2}
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
clientput "file evaluation of sct_ls336.tcl"
::scobj::ls336::sics_log 9 "file evaluation of sct_ls336.tcl"
proc ::scobj::ls336::read_config {} {
set catch_status [ catch {
set ns "::scobj::ls336"
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"] "ls336"] } {
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 tol1 tol2} {
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_ls336 ${name} ${IP} ${PORT} {*}$arg_list
} else {
add_ls336 ${name} "aqadapter" ${asyncqueue} {*}$arg_list
}
}
}
}
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
if { [info exists ::config_dict] } {
::scobj::ls336::read_config
} else {
::scobj::ls336::sics_log 5 "No config dict"
}