Bilby Script Context drivers for galil-attached devices

This commit is contained in:
Douglas Clowes
2014-02-19 14:33:19 +11:00
parent 0ea068cc31
commit 54e217af78
5 changed files with 621 additions and 1 deletions

View File

@@ -0,0 +1,245 @@
# Generated driver for shutters
# vim: tabstop=8 softtabstop=2 shiftwidth=2 nocindent smartindent
#
namespace eval ::scobj::shutters {
set debug_threshold 0
}
proc ::scobj::shutters::debug_log {debug_level debug_string} {
if {${debug_level} >= ${::scobj::shutters::debug_threshold}} {
set fd [open "/tmp/shutters.log" "a"]
set line "[clock format [clock seconds] -format "%T"] ${debug_string}"
puts ${fd} "${line}"
close ${fd}
}
}
# check function for hset change
proc ::scobj::shutters::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::shutters::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::shutters::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::shutters::read_switch_pair {tc_root} {
debug_log 1 "read_switch_pair 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}] > 2 && [lindex ${data_list} end] == ":" } {
set data_list [lrange ${data_list} 0 1]
}
if { [llength ${data_list}] == 2 } {
set left [expr [lindex ${data_list} 0]]
set right [expr [lindex ${data_list} 1]]
if { ${left} == 1 && ${right} == 0 } { # open
set data "out"
} elseif { ${left} == 0 && ${right} == 1 } { # closed
set data "in"
} else { # indeterminate
set data "moving"
}
} 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::shutters::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}
}
# function to write a parameter value on a device
proc ::scobj::shutters::write_switch {tc_root nextState cmd_str} {
debug_log 1 "write_switch 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}"
# hook code starts
if { [string equal -nocase -length 2 "${par}" "in"] } {
set cmd "SB${cmd_str}"
} elseif { [string equal -nocase -length 2 "${par}" "out"] } {
set cmd "CB${cmd_str}"
} else {
sct geterror "Value error: '${par}' not in ('in', 'out')"
}
# hook code ends
if { [hpropexists [sct] geterror] } {
debug_log 1 "[sct] error: [sct geterror]"
return -code error "[sct geterror]"
}
debug_log 1 "write_switch sct send ${cmd}"
sct send "${cmd}"
return ${nextState}
}
proc ::scobj::shutters::mk_sct_shutters { sct_controller name } {
debug_log 1 "mk_sct_shutters for ${name}"
set ns "[namespace current]"
set catch_status [ catch {
MakeSICSObj ${name} SCT_OBJECT
sicslist setatt ${name} klass collimator
sicslist setatt ${name} long_name ${name}
set scobj_hpath /sics/${name}
hfactory ${scobj_hpath}/fast_shutter plain user text
hsetprop ${scobj_hpath}/fast_shutter read ${ns}::getValue ${scobj_hpath} read_switch_pair {MG @IN[5], @IN[6]}
hsetprop ${scobj_hpath}/fast_shutter read_switch_pair ${ns}::read_switch_pair ${scobj_hpath}
hsetprop ${scobj_hpath}/fast_shutter control true
hsetprop ${scobj_hpath}/fast_shutter data true
hsetprop ${scobj_hpath}/fast_shutter mutable false
hsetprop ${scobj_hpath}/fast_shutter nxsave true
hsetprop ${scobj_hpath}/fast_shutter oldval UNKNOWN
hsetprop ${scobj_hpath}/fast_shutter klass "collimator"
hsetprop ${scobj_hpath}/fast_shutter nxalias "fast_shutter"
hsetprop ${scobj_hpath}/fast_shutter sdsinfo "::nexus::scobj::sdsinfo"
hsetprop ${scobj_hpath}/fast_shutter type "part"
hfactory ${scobj_hpath}/rough_20 plain user text
hsetprop ${scobj_hpath}/rough_20 read ${ns}::getValue ${scobj_hpath} read_switch_pair {MG @IN[15], @IN[16]}
hsetprop ${scobj_hpath}/rough_20 read_switch_pair ${ns}::read_switch_pair ${scobj_hpath}
hsetprop ${scobj_hpath}/rough_20 write ${ns}::write_switch ${scobj_hpath} noResponse {11}
hsetprop ${scobj_hpath}/rough_20 noResponse ${ns}::noResponse ${scobj_hpath}
hsetprop ${scobj_hpath}/rough_20 check ${ns}::checkrange ${scobj_hpath}
hsetprop ${scobj_hpath}/rough_20 control true
hsetprop ${scobj_hpath}/rough_20 data true
hsetprop ${scobj_hpath}/rough_20 mutable false
hsetprop ${scobj_hpath}/rough_20 nxsave true
hsetprop ${scobj_hpath}/rough_20 values in,out
hsetprop ${scobj_hpath}/rough_20 oldval UNKNOWN
hsetprop ${scobj_hpath}/rough_20 klass "collimator"
hsetprop ${scobj_hpath}/rough_20 nxalias "rough_20"
hsetprop ${scobj_hpath}/rough_20 sdsinfo "::nexus::scobj::sdsinfo"
hsetprop ${scobj_hpath}/rough_20 type "part"
hfactory ${scobj_hpath}/rough_40 plain user text
hsetprop ${scobj_hpath}/rough_40 read ${ns}::getValue ${scobj_hpath} read_switch_pair {MG @IN[13], @IN[14]}
hsetprop ${scobj_hpath}/rough_40 read_switch_pair ${ns}::read_switch_pair ${scobj_hpath}
hsetprop ${scobj_hpath}/rough_40 write ${ns}::write_switch ${scobj_hpath} noResponse {10}
hsetprop ${scobj_hpath}/rough_40 noResponse ${ns}::noResponse ${scobj_hpath}
hsetprop ${scobj_hpath}/rough_40 check ${ns}::checkrange ${scobj_hpath}
hsetprop ${scobj_hpath}/rough_40 control true
hsetprop ${scobj_hpath}/rough_40 data true
hsetprop ${scobj_hpath}/rough_40 mutable false
hsetprop ${scobj_hpath}/rough_40 nxsave true
hsetprop ${scobj_hpath}/rough_40 values in,out
hsetprop ${scobj_hpath}/rough_40 oldval UNKNOWN
hsetprop ${scobj_hpath}/rough_40 klass "collimator"
hsetprop ${scobj_hpath}/rough_40 nxalias "rough_40"
hsetprop ${scobj_hpath}/rough_40 sdsinfo "::nexus::scobj::sdsinfo"
hsetprop ${scobj_hpath}/rough_40 type "part"
hsetprop ${scobj_hpath} data "true"
hsetprop ${scobj_hpath} nxsave "true"
if {[SplitReply [motor_simulation]]=="false"} {
${sct_controller} poll ${scobj_hpath}/fast_shutter 1
${sct_controller} poll ${scobj_hpath}/rough_20 1
${sct_controller} poll ${scobj_hpath}/rough_40 1
${sct_controller} write ${scobj_hpath}/rough_20
${sct_controller} write ${scobj_hpath}/rough_40
}
hsetprop ${scobj_hpath} klass collimator
# hook code starts
# hook code ends
} catch_message ]
handle_exception ${catch_status} ${catch_message} "in ${ns}::mk_sct_shutters"
}
namespace eval ::scobj::shutters {
namespace export debug_log
namespace export mk_sct_shutters
}
proc add_shutters {name IP port} {
set ns "::scobj::shutters"
${ns}::debug_log 1 "add_shutters ${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_shutters sct_${name} ${name}"
${ns}::mk_sct_shutters sct_${name} ${name}
close ${fd}
}
puts stdout "file evaluation of sct_shutters.tcl"
::scobj::shutters::debug_log 1 "file evaluation of sct_shutters.tcl"