Files
sics/site_ansto/instrument/config/environment/temperature/west400.tcl
Ferdi Franceschini 5ee2634d30 Modified some more old drivers to use config_dict as in gen_sct.py
TODO
environment/sct_keithley_2700.tcl
environment/sct_protek_common.tcl
2014-07-01 20:12:42 +10:00

134 lines
4.7 KiB
Tcl

# Author: Ferdi Franceschini (ffr@ansto.gov.au)
namespace eval ::environment::temperature { }
# @brief Make a simulated temperature controller object.
#
# @param temp_sobj, name for temperature controller object.
proc ::environment::temperature::mkwest400sim {temp_sobj} {
EvFactory new $temp_sobj sim
sicslist setatt $temp_sobj numsensors 1
sicslist setatt $temp_sobj controlsensor sensora
sicslist setatt $temp_sobj sensorlist sensora
sicslist setatt $temp_sobj units kelvin
sicslist setatt $temp_sobj klass @none
}
#WEST4100 tempcontroller creation
proc ::environment::temperature::mkwest400 {temp_sobj IP ID} {
MakeRS232Controller sertemp $IP 502
sertemp timeout 300
sertemp sendterminator 0x0
sertemp replyterminator 0x0
EvFactory new tc1 west4100 sertemp $ID 2
sicslist setatt tc1 units kelvin
sicslist setatt tc1 klass @none
}
# @brief Adds a west400 temperature controller object.
#
# 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_west4100 {IP ID} {
set sim_mode [SplitReply [environment_simulation]]
if {$sim_mode == "true"} {
::environment::temperature::mkwest400sim tc1
} else {
::environment::temperature::mkwest400 tc1 $IP $ID
tc1 Upperlimit 1500
tc1 Lowerlimit 0
tc1 tolerance 10
}
sicslist setatt tc1 environment_name tc1
sicslist setatt tc1 long_name control_sensor_reading
::environment::mkenvinfo tc1 {ramprate {priv user} powerlimit {priv manager} }
#::environment::mkenvinfo tc1 {heateron {priv user} range {priv manager} }
}
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"
}