Files
sics/site_ansto/instrument/bilby/config/motors/sct_tank.tcl
2014-02-19 14:33:19 +11:00

209 lines
7.2 KiB
Tcl

# Generated driver for tank
# vim: tabstop=8 softtabstop=2 shiftwidth=2 nocindent smartindent
#
namespace eval ::scobj::tank {
set debug_threshold 0
}
proc ::scobj::tank::debug_log {debug_level debug_string} {
if {${debug_level} >= ${::scobj::tank::debug_threshold}} {
set fd [open "/tmp/tank.log" "a"]
set line "[clock format [clock seconds] -format "%T"] ${debug_string}"
puts ${fd} "${line}"
close ${fd}
}
}
# check function for hset change
proc ::scobj::tank::checkrange {tc_root} {
debug_log 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]
}
if { ${setpoint} < ${lolimit} || ${setpoint} > ${hilimit} } {
error "setpoint ${setpoint} violates limits (${lolimit}..${hilimit}) on [sct]"
}
return OK
}
# function to request the read of a parameter on a device
proc ::scobj::tank::getValue {tc_root nextState cmd_str} {
debug_log 1 "getValue tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
if { [hpropexists [sct] geterror] } {
hdelprop [sct] geterror
}
set cmd "${cmd_str}"
debug_log 1 "getValue sct send ${cmd}"
sct send "${cmd}"
return ${nextState}
}
# function to check the write parameter on a device
proc ::scobj::tank::noResponse {tc_root} {
debug_log 1 "noResponse tc_root=${tc_root} sct=[sct] resp=[sct result]"
return "idle"
}
# function to parse the read of a parameter on a device
proc ::scobj::tank::read_switch {tc_root} {
debug_log 1 "read_switch 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}"
return -code error "[sct geterror]"
}
# hook code starts
if { [string equal -nocase -length 1 "${data}" "?"] } {
sct geterror "Galil error in: '${data}'"
} else {
set data_list [split [string trim "${data}"]]
if { [llength ${data_list}] > 1 && [lindex ${data_list} end] == ":" } {
set data_list [lrange ${data_list} 0 0]
}
if { [llength ${data_list}] == 1 } {
set left [expr [lindex ${data_list} 0]]
if { ${left} == 1 } { # open
set data "open"
} else { # closed
set data "closed"
}
} else {
sct geterror "Syntax error in: '${data}'=>'${data_list}'"
}
}
# hook code ends
if { [hpropexists [sct] geterror] } {
debug_log 1 "[sct] error: [sct geterror]"
return -code error "[sct geterror]"
}
if { ${data} != [sct oldval] } {
debug_log 1 "[sct] changed to new:${data}, from old:[sct oldval]"
sct oldval ${data}
sct update ${data}
sct utime readtime
}
return ${nextState}
}
# function to write a parameter value on a device
proc ::scobj::tank::setValue {tc_root nextState cmd_str} {
debug_log 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}"
debug_log 1 "setValue sct send ${cmd}"
sct send "${cmd}"
return ${nextState}
}
proc ::scobj::tank::mk_sct_tank { sct_controller name } {
debug_log 1 "mk_sct_tank for ${name}"
set ns "[namespace current]"
set catch_status [ catch {
MakeSICSObj ${name} SCT_OBJECT
sicslist setatt ${name} klass instrument
sicslist setatt ${name} long_name ${name}
set scobj_hpath /sics/${name}
hfactory ${scobj_hpath}/limits plain spy none
hfactory ${scobj_hpath}/limits/forward plain user text
hsetprop ${scobj_hpath}/limits/forward read ${ns}::getValue ${scobj_hpath} read_switch {MG _LFH}
hsetprop ${scobj_hpath}/limits/forward read_switch ${ns}::read_switch ${scobj_hpath}
hsetprop ${scobj_hpath}/limits/forward control true
hsetprop ${scobj_hpath}/limits/forward data true
hsetprop ${scobj_hpath}/limits/forward mutable false
hsetprop ${scobj_hpath}/limits/forward nxsave true
hsetprop ${scobj_hpath}/limits/forward oldval UNKNOWN
hfactory ${scobj_hpath}/limits/reverse plain user text
hsetprop ${scobj_hpath}/limits/reverse read ${ns}::getValue ${scobj_hpath} read_switch {MG _LRH}
hsetprop ${scobj_hpath}/limits/reverse read_switch ${ns}::read_switch ${scobj_hpath}
hsetprop ${scobj_hpath}/limits/reverse control true
hsetprop ${scobj_hpath}/limits/reverse data true
hsetprop ${scobj_hpath}/limits/reverse mutable false
hsetprop ${scobj_hpath}/limits/reverse nxsave true
hsetprop ${scobj_hpath}/limits/reverse oldval UNKNOWN
if {[SplitReply [motor_simulation]]=="false"} {
${sct_controller} poll ${scobj_hpath}/limits/forward 1
${sct_controller} poll ${scobj_hpath}/limits/reverse 1
}
hfactory ${scobj_hpath}/switches plain spy none
hfactory ${scobj_hpath}/switches/forward plain user text
hsetprop ${scobj_hpath}/switches/forward read ${ns}::getValue ${scobj_hpath} read_switch {MG @IN[5]}
hsetprop ${scobj_hpath}/switches/forward read_switch ${ns}::read_switch ${scobj_hpath}
hsetprop ${scobj_hpath}/switches/forward control true
hsetprop ${scobj_hpath}/switches/forward data true
hsetprop ${scobj_hpath}/switches/forward mutable false
hsetprop ${scobj_hpath}/switches/forward nxsave true
hsetprop ${scobj_hpath}/switches/forward oldval UNKNOWN
hfactory ${scobj_hpath}/switches/reverse plain user text
hsetprop ${scobj_hpath}/switches/reverse read ${ns}::getValue ${scobj_hpath} read_switch {MG @IN[6]}
hsetprop ${scobj_hpath}/switches/reverse read_switch ${ns}::read_switch ${scobj_hpath}
hsetprop ${scobj_hpath}/switches/reverse control true
hsetprop ${scobj_hpath}/switches/reverse data true
hsetprop ${scobj_hpath}/switches/reverse mutable false
hsetprop ${scobj_hpath}/switches/reverse nxsave true
hsetprop ${scobj_hpath}/switches/reverse oldval UNKNOWN
if {[SplitReply [motor_simulation]]=="false"} {
${sct_controller} poll ${scobj_hpath}/switches/forward 1
${sct_controller} poll ${scobj_hpath}/switches/reverse 1
}
hsetprop ${scobj_hpath} klass instrument
# hook code starts
# hook code ends
} catch_message ]
handle_exception ${catch_status} ${catch_message} "in ${ns}::mk_sct_tank"
}
namespace eval ::scobj::tank {
namespace export debug_log
namespace export mk_sct_tank
}
proc add_tank {name IP port} {
set ns "::scobj::tank"
${ns}::debug_log 1 "add_tank ${name} ${IP} ${port}"
if {[SplitReply [motor_simulation]]=="false"} {
if {[string equal -nocase "aqadapter" "${IP}"]} {
${ns}::debug_log 1 "makesctcontroller sct_${name} aqadapter ${port}"
makesctcontroller sct_${name} aqadapter ${port}
} else {
${ns}::debug_log 1 "makesctcontroller sct_${name} dmc2280 ${IP}:${port}"
makesctcontroller sct_${name} dmc2280 ${IP}:${port}
}
}
${ns}::debug_log 1 "mk_sct_tank sct_${name} ${name}"
${ns}::mk_sct_tank sct_${name} ${name}
close ${fd}
}
puts stdout "file evaluation of sct_tank.tcl"
::scobj::tank::debug_log 1 "file evaluation of sct_tank.tcl"