Updated wombat sics_config.ini and gen_sct.py Generated new tcl files from sct templates and modified some old sct_*.tcl drivers. TODO sct_keithley_2700.tcl magneticField/sct_oxford_labview.tcl magneticField/sct_bruker_BEC1.tcl temperature/sct_watlow_st4.tcl temperature/sct_oxford_mercury.tcl temperature/sct_mercury_pres.tcl temperature/sct_julabo_lh45.tcl temperature/sct_lakeshore_340.tcl temperature/sct_julabo_lh45_gen.tcl temperature/sct_watlow_rm.tcl temperature/sct_eurotherm_2000.tcl temperature/sct_lakeshore_336.tcl temperature/sct_watlow_pm.tcl temperature/sct_oxford_itc.tcl temperature/sct_lakeshore_370.tcl temperature/west400.tcl
447 lines
17 KiB
Tcl
447 lines
17 KiB
Tcl
# Generated driver for mercury_pres
|
|
# vim: ft=tcl tabstop=8 softtabstop=2 shiftwidth=2 nocindent smartindent
|
|
#
|
|
|
|
namespace eval ::scobj::mercury_pres {
|
|
set debug_threshold 5
|
|
}
|
|
|
|
proc ::scobj::mercury_pres::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/mercury_pres_[basename ${tc_root}].log" "a"]
|
|
set line "[clock format [clock seconds] -format "%T"] ${debug_string}"
|
|
puts ${fd} "${line}"
|
|
close ${fd}
|
|
}
|
|
} catch_message ]
|
|
}
|
|
|
|
proc ::scobj::mercury_pres::sics_log {debug_level debug_string} {
|
|
set catch_status [ catch {
|
|
set debug_threshold ${::scobj::mercury_pres::debug_threshold}
|
|
if {${debug_level} >= ${debug_threshold}} {
|
|
sicslog "::scobj::mercury_pres::${debug_string}"
|
|
}
|
|
} catch_message ]
|
|
}
|
|
|
|
# checklimits function for driveable interface
|
|
proc ::scobj::mercury_pres::checklimits {tc_root} {
|
|
set catch_status [ catch {
|
|
debug_log ${tc_root} 1 "checklimits tc_root=${tc_root} sct=[sct] target=[sct target]"
|
|
set setpoint [sct target]
|
|
if { [hpropexists [sct] lowerlimit] } {
|
|
set lolimit [sct lowerlimit]
|
|
} else {
|
|
# lowerlimit not set, use target
|
|
set lolimit [sct target]
|
|
}
|
|
if { [hpropexists [sct] upperlimit] } {
|
|
set hilimit [sct upperlimit]
|
|
} else {
|
|
# upperlimit not set, use target
|
|
set hilimit [sct target]
|
|
}
|
|
# checklimits hook code goes here
|
|
if { ${setpoint} < ${lolimit} || ${setpoint} > ${hilimit} } {
|
|
sct driving 0
|
|
error "setpoint ${setpoint} violates limits (${lolimit}..${hilimit}) on [sct]"
|
|
}
|
|
return OK
|
|
} catch_message ]
|
|
handle_exception ${catch_status} ${catch_message}
|
|
}
|
|
|
|
# check function for hset change
|
|
proc ::scobj::mercury_pres::checkrange {tc_root} {
|
|
set catch_status [ catch {
|
|
debug_log ${tc_root} 1 "checkrange tc_root=${tc_root} sct=[sct] target=[sct target]"
|
|
set setpoint [sct target]
|
|
if { [hpropexists [sct] lowerlimit] } {
|
|
set lolimit [sct lowerlimit]
|
|
} else {
|
|
# lowerlimit not set, use target
|
|
set lolimit [sct target]
|
|
}
|
|
if { [hpropexists [sct] upperlimit] } {
|
|
set hilimit [sct upperlimit]
|
|
} else {
|
|
# upperlimit not set, use target
|
|
set hilimit [sct target]
|
|
}
|
|
# checkrange hook code goes here
|
|
if { ${setpoint} < ${lolimit} || ${setpoint} > ${hilimit} } {
|
|
error "setpoint ${setpoint} violates limits (${lolimit}..${hilimit}) on [sct]"
|
|
}
|
|
return OK
|
|
} catch_message ]
|
|
handle_exception ${catch_status} ${catch_message}
|
|
}
|
|
|
|
# checkstatus function for driveable interface
|
|
proc ::scobj::mercury_pres::checkstatus {tc_root} {
|
|
set catch_status [ catch {
|
|
# checkstatus hook code goes here
|
|
if {[sct driving]} {
|
|
set sp "[sct target]"
|
|
set pv "[hval ${tc_root}/[sct driveable]]"
|
|
if { abs(${pv} - ${sp}) <= [sct tolerance] } {
|
|
if { [hpropexists [sct] settle_time] } {
|
|
if { [hpropexists [sct] settle_time_start] } {
|
|
if { [sct utime] - [sct settle_time_start] >= [sct settle_time]} {
|
|
sct driving 0
|
|
return "idle"
|
|
}
|
|
return "busy"
|
|
} else {
|
|
sct utime settle_time_start
|
|
return "busy"
|
|
}
|
|
}
|
|
sct driving 0
|
|
return "idle"
|
|
}
|
|
if { [hpropexists [sct] settle_time_start] } {
|
|
hdelprop [sct] settle_time_start
|
|
}
|
|
return "busy"
|
|
} else {
|
|
return "idle"
|
|
}
|
|
} catch_message ]
|
|
handle_exception ${catch_status} ${catch_message}
|
|
}
|
|
|
|
# function to request the read of a parameter on a device
|
|
proc ::scobj::mercury_pres::getValue {tc_root nextState cmd_str} {
|
|
set catch_status [ catch {
|
|
debug_log ${tc_root} 1 "getValue tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
|
|
if { [hpropexists [sct] geterror] } {
|
|
hdelprop [sct] geterror
|
|
}
|
|
set cmd "${cmd_str}"
|
|
# getValue hook code goes here
|
|
debug_log ${tc_root} 1 "getValue sct send ${cmd}"
|
|
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
|
|
sct send "${cmd}"
|
|
}
|
|
return ${nextState}
|
|
} catch_message ]
|
|
handle_exception ${catch_status} ${catch_message}
|
|
}
|
|
|
|
# halt function for driveable interface
|
|
proc ::scobj::mercury_pres::halt {tc_root} {
|
|
set catch_status [ catch {
|
|
debug_log ${tc_root} 1 "halt tc_root=${tc_root} sct=[sct] driving=[sct driving]"
|
|
### TODO hset [sct] [hval [sct]]
|
|
# halt hook code goes here
|
|
sct driving 0
|
|
return "idle"
|
|
} catch_message ]
|
|
handle_exception ${catch_status} ${catch_message}
|
|
}
|
|
|
|
# function to check the write parameter on a device
|
|
proc ::scobj::mercury_pres::noResponse {tc_root} {
|
|
set catch_status [ catch {
|
|
debug_log ${tc_root} 1 "noResponse tc_root=${tc_root} sct=[sct] resp=[sct result]"
|
|
# noResponse hook code goes here
|
|
return "idle"
|
|
} catch_message ]
|
|
handle_exception ${catch_status} ${catch_message}
|
|
}
|
|
|
|
# function to parse the read of a parameter on a device
|
|
proc ::scobj::mercury_pres::rdText {tc_root} {
|
|
set catch_status [ catch {
|
|
debug_log ${tc_root} 1 "rdText 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]"
|
|
}
|
|
# rdText hook code starts
|
|
scan [lindex [split "$data" ":"] end] "%s" data
|
|
# rdText 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 parse the read of a parameter on a device
|
|
proc ::scobj::mercury_pres::rdValue {tc_root} {
|
|
set catch_status [ catch {
|
|
debug_log ${tc_root} 1 "rdValue 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]"
|
|
}
|
|
# rdValue hook code starts
|
|
scan [lindex [split "$data" ":"] end] "%g" data
|
|
# rdValue 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::mercury_pres::setPoint {tc_root nextState cmd_str} {
|
|
set catch_status [ catch {
|
|
debug_log ${tc_root} 1 "setPoint tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
|
|
if { [hpropexists [sct] geterror] } {
|
|
hdelprop [sct] geterror
|
|
}
|
|
set par [sct target]
|
|
set cmd "${cmd_str}${par}"
|
|
# setPoint hook code starts
|
|
# TODO: Check if we can/must put the "mB" on this line
|
|
# setPoint hook code ends
|
|
if { [hpropexists [sct] geterror] } {
|
|
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
|
|
error "[sct geterror]"
|
|
}
|
|
if { [hpropexists [sct] driving] } {
|
|
if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } {
|
|
sct driving 1
|
|
}
|
|
}
|
|
debug_log ${tc_root} 1 "setPoint 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 write a parameter value on a device
|
|
proc ::scobj::mercury_pres::setValue {tc_root nextState cmd_str} {
|
|
set catch_status [ catch {
|
|
debug_log ${tc_root} 1 "setValue tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
|
|
if { [hpropexists [sct] geterror] } {
|
|
hdelprop [sct] geterror
|
|
}
|
|
set par [sct target]
|
|
set cmd "${cmd_str}${par}"
|
|
# setValue hook code goes here
|
|
if { [hpropexists [sct] driving] } {
|
|
if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } {
|
|
sct driving 1
|
|
}
|
|
}
|
|
debug_log ${tc_root} 1 "setValue sct send ${cmd}"
|
|
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
|
|
sct send "${cmd}"
|
|
}
|
|
return ${nextState}
|
|
} catch_message ]
|
|
handle_exception ${catch_status} ${catch_message}
|
|
}
|
|
|
|
proc ::scobj::mercury_pres::mkDriver { sct_controller name id tol } {
|
|
::scobj::mercury_pres::sics_log 9 "::scobj::mercury_pres::mkDriver ${sct_controller} ${name} ${id} ${tol}"
|
|
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}
|
|
|
|
hfactory ${scobj_hpath}/Loop8 plain spy none
|
|
|
|
hfactory ${scobj_hpath}/Loop8/nick plain user text
|
|
hsetprop ${scobj_hpath}/Loop8/nick read ${ns}::getValue ${scobj_hpath} rdText {READ:DEV:DB8.P1:PRES:NICK}
|
|
hsetprop ${scobj_hpath}/Loop8/nick rdText ${ns}::rdText ${scobj_hpath}
|
|
hsetprop ${scobj_hpath}/Loop8/nick control true
|
|
hsetprop ${scobj_hpath}/Loop8/nick data true
|
|
hsetprop ${scobj_hpath}/Loop8/nick mutable false
|
|
hsetprop ${scobj_hpath}/Loop8/nick nxsave true
|
|
hsetprop ${scobj_hpath}/Loop8/nick oldval UNKNOWN
|
|
hsetprop ${scobj_hpath}/Loop8/nick sdsinfo "::nexus::scobj::sdsinfo"
|
|
hsetprop ${scobj_hpath}/Loop8/nick type "part"
|
|
hsetprop ${scobj_hpath}/Loop8/nick nxalias "${name}_Loop8_nick"
|
|
|
|
hfactory ${scobj_hpath}/Loop8/sensor plain user float
|
|
hsetprop ${scobj_hpath}/Loop8/sensor read ${ns}::getValue ${scobj_hpath} rdValue {READ:DEV:DB8.P1:PRES:SIG:PRES}
|
|
hsetprop ${scobj_hpath}/Loop8/sensor rdValue ${ns}::rdValue ${scobj_hpath}
|
|
hsetprop ${scobj_hpath}/Loop8/sensor control true
|
|
hsetprop ${scobj_hpath}/Loop8/sensor data true
|
|
hsetprop ${scobj_hpath}/Loop8/sensor mutable false
|
|
hsetprop ${scobj_hpath}/Loop8/sensor nxsave true
|
|
hsetprop ${scobj_hpath}/Loop8/sensor units mB
|
|
hsetprop ${scobj_hpath}/Loop8/sensor permlink data_set "P[format "%02d" ${id}]S08"
|
|
hsetprop ${scobj_hpath}/Loop8/sensor @description "P[format "%02d" ${id}]S08"
|
|
hsetprop ${scobj_hpath}/Loop8/sensor oldval 0.0
|
|
hsetprop ${scobj_hpath}/Loop8/sensor sdsinfo "::nexus::scobj::sdsinfo"
|
|
hsetprop ${scobj_hpath}/Loop8/sensor type "part"
|
|
hsetprop ${scobj_hpath}/Loop8/sensor nxalias "${name}_Loop8_sensor"
|
|
|
|
hfactory ${scobj_hpath}/Loop8/setpoint plain user float
|
|
hsetprop ${scobj_hpath}/Loop8/setpoint read ${ns}::getValue ${scobj_hpath} rdValue {READ:DEV:DB8.P1:PRES:LOOP:TSET}
|
|
hsetprop ${scobj_hpath}/Loop8/setpoint rdValue ${ns}::rdValue ${scobj_hpath}
|
|
hsetprop ${scobj_hpath}/Loop8/setpoint write ${ns}::setPoint ${scobj_hpath} noResponse {SET:DEV:DB8.P1:PRES:LOOP:TSET:}
|
|
hsetprop ${scobj_hpath}/Loop8/setpoint noResponse ${ns}::noResponse ${scobj_hpath}
|
|
hsetprop ${scobj_hpath}/Loop8/setpoint check ${ns}::checkrange ${scobj_hpath}
|
|
hsetprop ${scobj_hpath}/Loop8/setpoint driving 0
|
|
hsetprop ${scobj_hpath}/Loop8/setpoint checklimits ${ns}::checklimits ${scobj_hpath}
|
|
hsetprop ${scobj_hpath}/Loop8/setpoint checkstatus ${ns}::checkstatus ${scobj_hpath}
|
|
hsetprop ${scobj_hpath}/Loop8/setpoint halt ${ns}::halt ${scobj_hpath}
|
|
hsetprop ${scobj_hpath}/Loop8/setpoint driveable Loop8/sensor
|
|
hsetprop ${scobj_hpath}/Loop8/setpoint control true
|
|
hsetprop ${scobj_hpath}/Loop8/setpoint data true
|
|
hsetprop ${scobj_hpath}/Loop8/setpoint mutable false
|
|
hsetprop ${scobj_hpath}/Loop8/setpoint nxsave true
|
|
hsetprop ${scobj_hpath}/Loop8/setpoint lowerlimit 0
|
|
hsetprop ${scobj_hpath}/Loop8/setpoint upperlimit 333
|
|
hsetprop ${scobj_hpath}/Loop8/setpoint tolerance ${tol}
|
|
hsetprop ${scobj_hpath}/Loop8/setpoint units mB
|
|
hsetprop ${scobj_hpath}/Loop8/setpoint permlink data_set "P[format "%02d" ${id}]SP08"
|
|
hsetprop ${scobj_hpath}/Loop8/setpoint @description "P[format "%02d" ${id}]SP08"
|
|
hsetprop ${scobj_hpath}/Loop8/setpoint oldval 0.0
|
|
hsetprop ${scobj_hpath}/Loop8/setpoint sdsinfo "::nexus::scobj::sdsinfo"
|
|
hsetprop ${scobj_hpath}/Loop8/setpoint settle_time "15"
|
|
hsetprop ${scobj_hpath}/Loop8/setpoint type "drivable"
|
|
hsetprop ${scobj_hpath}/Loop8/setpoint nxalias "${name}_Loop8_setpoint"
|
|
|
|
if {[string equal -nocase [SplitReply [environment_simulation]] "false"]} {
|
|
${sct_controller} poll ${scobj_hpath}/Loop8/nick 15
|
|
${sct_controller} poll ${scobj_hpath}/Loop8/sensor 1
|
|
${sct_controller} poll ${scobj_hpath}/Loop8/setpoint 5
|
|
${sct_controller} write ${scobj_hpath}/Loop8/setpoint
|
|
ansto_makesctdrive ${name}_Loop8_setpoint ${scobj_hpath}/Loop8/setpoint ${scobj_hpath}/Loop8/sensor ${sct_controller}
|
|
} else {
|
|
::scobj::mercury_pres::sics_log 9 "[environment_simulation] => No poll/write for mercury_pres"
|
|
}
|
|
hsetprop ${scobj_hpath} klass environment
|
|
hsetprop ${scobj_hpath} debug_threshold 5
|
|
# mkDriver hook code goes here
|
|
} catch_message ]
|
|
handle_exception ${catch_status} ${catch_message}
|
|
}
|
|
|
|
namespace eval ::scobj::mercury_pres {
|
|
namespace export debug_threshold
|
|
namespace export debug_log
|
|
namespace export sics_log
|
|
namespace export mkDriver
|
|
}
|
|
|
|
proc add_mercury_pres {name IP port {id 99} {tol 1}} {
|
|
set catch_status [ catch {
|
|
::scobj::mercury_pres::sics_log 9 "add_mercury_pres ${name} ${IP} ${port} ${id} ${tol}"
|
|
if {[string equal -nocase [SplitReply [environment_simulation]] "false"]} {
|
|
if {[string equal -nocase "aqadapter" "${IP}"]} {
|
|
::scobj::mercury_pres::sics_log 9 "makesctcontroller sct_${name} aqadapter ${port}"
|
|
makesctcontroller sct_${name} aqadapter ${port}
|
|
} else {
|
|
::scobj::mercury_pres::sics_log 9 "makesctcontroller sct_${name} std ${IP}:${port}"
|
|
makesctcontroller sct_${name} std ${IP}:${port}
|
|
}
|
|
} else {
|
|
::scobj::mercury_pres::sics_log 9 "[environment_simulation] => No sctcontroller for mercury_pres"
|
|
}
|
|
::scobj::mercury_pres::sics_log 1 "::scobj::mercury_pres::mkDriver sct_${name} ${name} ${id} ${tol}"
|
|
::scobj::mercury_pres::mkDriver sct_${name} ${name} ${id} ${tol}
|
|
} catch_message ]
|
|
handle_exception ${catch_status} ${catch_message}
|
|
}
|
|
|
|
clientput "file evaluation of sct_mercury_pres.tcl"
|
|
::scobj::mercury_pres::sics_log 9 "file evaluation of sct_mercury_pres.tcl"
|
|
|
|
proc ::scobj::mercury_pres::read_config {} {
|
|
set catch_status [ catch {
|
|
set ns "::scobj::mercury_pres"
|
|
dict for {k v} $::config_dict {
|
|
if { [dict exists $v "implementation"] } {
|
|
set name [dict get $v name]
|
|
set enabled [string tolower [dict get $v "enabled"]]
|
|
set implementation [dict get $v "implementation"]
|
|
set v [dict get $::config_dict $implementation]
|
|
if { [dict get $v "driver"] == "mercury_pres" } {
|
|
if { [dict get $v enabled] } {
|
|
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 tol} {
|
|
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_mercury_pres ${name} "aqadapter" ${asyncqueue} {*}$arg_list
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} catch_message ]
|
|
handle_exception ${catch_status} ${catch_message}
|
|
}
|
|
|
|
if { [info exists ::config_dict] } {
|
|
::scobj::mercury_pres::read_config
|
|
} else {
|
|
::scobj::mercury_pres::sics_log 5 "No config dict"
|
|
}
|