Perform the rename
This commit is contained in:
406
site_ansto/instrument/bilby/config/motors/tank_sct.tcl
Normal file
406
site_ansto/instrument/bilby/config/motors/tank_sct.tcl
Normal file
@@ -0,0 +1,406 @@
|
||||
# Generated driver for tank
|
||||
# vim: ft=tcl tabstop=8 softtabstop=2 shiftwidth=2 nocindent smartindent
|
||||
#
|
||||
|
||||
namespace eval ::scobj::tank {
|
||||
set debug_threshold 5
|
||||
}
|
||||
|
||||
proc ::scobj::tank::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/tank_[basename ${tc_root}].log" "a"]
|
||||
set line "[clock format [clock seconds] -format "%T"] ${debug_string}"
|
||||
puts ${fd} "${line}"
|
||||
close ${fd}
|
||||
}
|
||||
} catch_message ]
|
||||
}
|
||||
|
||||
proc ::scobj::tank::sics_log {debug_level debug_string} {
|
||||
set catch_status [ catch {
|
||||
set debug_threshold ${::scobj::tank::debug_threshold}
|
||||
if {${debug_level} >= ${debug_threshold}} {
|
||||
sicslog "::scobj::tank::${debug_string}"
|
||||
}
|
||||
} catch_message ]
|
||||
}
|
||||
|
||||
# check function for hset change
|
||||
proc ::scobj::tank::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}
|
||||
}
|
||||
|
||||
# function to request the read of a parameter on a device
|
||||
proc ::scobj::tank::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}
|
||||
}
|
||||
|
||||
# function to check the write parameter on a device
|
||||
proc ::scobj::tank::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::tank::read_pos {tc_root} {
|
||||
set catch_status [ catch {
|
||||
debug_log ${tc_root} 1 "read_pos 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]"
|
||||
}
|
||||
# read_pos hook code starts
|
||||
global tank_absenchome tank_cnts_per_x tank_home
|
||||
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 absenc [unpad [lindex ${data_list} 0]]
|
||||
set data [expr {($absenc - $tank_absenchome) / $tank_cnts_per_x + $tank_home}]
|
||||
vessel_y $data
|
||||
} else {
|
||||
sct geterror "Syntax error in: '${data}'=>'${data_list}'"
|
||||
}
|
||||
}
|
||||
# read_pos 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::tank::read_switch {tc_root} {
|
||||
set catch_status [ catch {
|
||||
debug_log ${tc_root} 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}"
|
||||
error "[sct geterror]"
|
||||
}
|
||||
# read_switch 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}'"
|
||||
}
|
||||
}
|
||||
# read_switch 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::tank::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::tank::mkDriver { sct_controller name } {
|
||||
::scobj::tank::sics_log 9 "::scobj::tank::mkDriver 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}/pos plain spy float
|
||||
hsetprop ${scobj_hpath}/pos read ${ns}::getValue ${scobj_hpath} read_pos {MG _TPH}
|
||||
hsetprop ${scobj_hpath}/pos read_pos ${ns}::read_pos ${scobj_hpath}
|
||||
hsetprop ${scobj_hpath}/pos control true
|
||||
hsetprop ${scobj_hpath}/pos data true
|
||||
hsetprop ${scobj_hpath}/pos mutable true
|
||||
hsetprop ${scobj_hpath}/pos nxsave true
|
||||
hsetprop ${scobj_hpath}/pos oldval 0.0
|
||||
hsetprop ${scobj_hpath}/pos sdsinfo "::nexus::scobj::sdsinfo"
|
||||
hsetprop ${scobj_hpath}/pos type "part"
|
||||
hsetprop ${scobj_hpath}/pos nxalias "${name}_pos"
|
||||
|
||||
if {[string equal -nocase [SplitReply [motor_simulation]] "false"]} {
|
||||
${sct_controller} poll ${scobj_hpath}/pos 1
|
||||
} else {
|
||||
::scobj::tank::sics_log 9 "[motor_simulation] => No poll/write for tank"
|
||||
}
|
||||
|
||||
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
|
||||
hsetprop ${scobj_hpath}/limits/forward sdsinfo "::nexus::scobj::sdsinfo"
|
||||
hsetprop ${scobj_hpath}/limits/forward type "part"
|
||||
hsetprop ${scobj_hpath}/limits/forward nxalias "${name}_limits_forward"
|
||||
|
||||
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
|
||||
hsetprop ${scobj_hpath}/limits/reverse sdsinfo "::nexus::scobj::sdsinfo"
|
||||
hsetprop ${scobj_hpath}/limits/reverse type "part"
|
||||
hsetprop ${scobj_hpath}/limits/reverse nxalias "${name}_limits_reverse"
|
||||
|
||||
if {[string equal -nocase [SplitReply [motor_simulation]] "false"]} {
|
||||
${sct_controller} poll ${scobj_hpath}/limits/forward 1
|
||||
${sct_controller} poll ${scobj_hpath}/limits/reverse 1
|
||||
} else {
|
||||
::scobj::tank::sics_log 9 "[motor_simulation] => No poll/write for tank"
|
||||
}
|
||||
|
||||
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
|
||||
hsetprop ${scobj_hpath}/switches/forward sdsinfo "::nexus::scobj::sdsinfo"
|
||||
hsetprop ${scobj_hpath}/switches/forward type "part"
|
||||
hsetprop ${scobj_hpath}/switches/forward nxalias "${name}_switches_forward"
|
||||
|
||||
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
|
||||
hsetprop ${scobj_hpath}/switches/reverse sdsinfo "::nexus::scobj::sdsinfo"
|
||||
hsetprop ${scobj_hpath}/switches/reverse type "part"
|
||||
hsetprop ${scobj_hpath}/switches/reverse nxalias "${name}_switches_reverse"
|
||||
|
||||
if {[string equal -nocase [SplitReply [motor_simulation]] "false"]} {
|
||||
${sct_controller} poll ${scobj_hpath}/switches/forward 1
|
||||
${sct_controller} poll ${scobj_hpath}/switches/reverse 1
|
||||
} else {
|
||||
::scobj::tank::sics_log 9 "[motor_simulation] => No poll/write for tank"
|
||||
}
|
||||
hsetprop ${scobj_hpath} klass instrument
|
||||
hsetprop ${scobj_hpath} debug_threshold 5
|
||||
# mkDriver hook code starts
|
||||
::utility::mkVar vessel_y float user vessel_y true instrument true true
|
||||
sicslist setatt vessel_y klass instrument
|
||||
sicslist setatt vessel_y mutable true
|
||||
# mkDriver hook code ends
|
||||
} catch_message ]
|
||||
handle_exception ${catch_status} ${catch_message}
|
||||
}
|
||||
|
||||
namespace eval ::scobj::tank {
|
||||
namespace export debug_threshold
|
||||
namespace export debug_log
|
||||
namespace export sics_log
|
||||
namespace export mkDriver
|
||||
}
|
||||
|
||||
proc add_tank {name IP port} {
|
||||
set catch_status [ catch {
|
||||
::scobj::tank::sics_log 9 "add_tank ${name} ${IP} ${port}"
|
||||
if {[string equal -nocase [SplitReply [motor_simulation]] "false"]} {
|
||||
if {[string equal -nocase "aqadapter" "${IP}"]} {
|
||||
::scobj::tank::sics_log 9 "makesctcontroller sct_${name} aqadapter ${port}"
|
||||
makesctcontroller sct_${name} aqadapter ${port}
|
||||
} else {
|
||||
::scobj::tank::sics_log 9 "makesctcontroller sct_${name} dmc2280 ${IP}:${port}"
|
||||
makesctcontroller sct_${name} dmc2280 ${IP}:${port}
|
||||
}
|
||||
} else {
|
||||
::scobj::tank::sics_log 9 "[motor_simulation] => No sctcontroller for tank"
|
||||
}
|
||||
::scobj::tank::sics_log 1 "::scobj::tank::mkDriver sct_${name} ${name}"
|
||||
::scobj::tank::mkDriver sct_${name} ${name}
|
||||
} catch_message ]
|
||||
handle_exception ${catch_status} ${catch_message}
|
||||
}
|
||||
|
||||
clientput "file evaluation of sct_tank.tcl"
|
||||
::scobj::tank::sics_log 9 "file evaluation of sct_tank.tcl"
|
||||
|
||||
proc ::scobj::tank::read_config {} {
|
||||
set catch_status [ catch {
|
||||
set ns "::scobj::tank"
|
||||
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"] "tank"] } {
|
||||
if { ![string equal -nocase [SplitReply [motor_simulation]] "false"] } {
|
||||
set asyncqueue "null"
|
||||
${ns}::sics_log 9 "[motor_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"]"
|
||||
}
|
||||
}
|
||||
if { [string equal -nocase ${asyncqueue} "sct"] } {
|
||||
add_tank ${name} ${IP} ${PORT}
|
||||
} else {
|
||||
add_tank ${name} "aqadapter" ${asyncqueue}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch_message ]
|
||||
handle_exception ${catch_status} ${catch_message}
|
||||
}
|
||||
|
||||
if { [info exists ::config_dict] } {
|
||||
::scobj::tank::read_config
|
||||
} else {
|
||||
::scobj::tank::sics_log 5 "No config dict"
|
||||
}
|
||||
Reference in New Issue
Block a user