Add sct driver for New Zealand magnet

This commit is contained in:
Douglas Clowes
2014-07-15 18:46:35 +10:00
parent 22b34395c1
commit db24e03106
2 changed files with 659 additions and 0 deletions

View File

@ -0,0 +1,580 @@
# Generated driver for tsi_smc
# vim: ft=tcl tabstop=8 softtabstop=2 shiftwidth=2 nocindent smartindent
#
namespace eval ::scobj::tsi_smc {
set debug_threshold 5
}
proc ::scobj::tsi_smc::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/tsi_smc_[basename ${tc_root}].log" "a"]
set line "[clock format [clock seconds] -format "%T"] ${debug_string}"
puts ${fd} "${line}"
close ${fd}
}
} catch_message ]
}
proc ::scobj::tsi_smc::sics_log {debug_level debug_string} {
set catch_status [ catch {
set debug_threshold ${::scobj::tsi_smc::debug_threshold}
if {${debug_level} >= ${debug_threshold}} {
sicslog "::scobj::tsi_smc::${debug_string}"
}
} catch_message ]
}
# checklimits function for driveable interface
proc ::scobj::tsi_smc::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::tsi_smc::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::tsi_smc::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::tsi_smc::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::tsi_smc::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::tsi_smc::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::tsi_smc::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
if {[basename [sct]] == "G"} {
set value [expr {[string range ${data} 1 8]}]
set value [expr {${value} * 2.5177E+02 - 1.6116E+01}]
if {[hpropexists [sct] offset]} {
set value [expr {${value} + [hgetpropval [sct] offset]}]
}
if {${value} != [hgetpropval ${tc_root}/value oldval]} {
debug_log ${tc_root} 1 "${tc_root}/value changed to new:${value}, from old:[hgetpropval ${tc_root}/value oldval]"
hupdate ${tc_root}/value ${value}
hsetprop ${tc_root}/value oldval ${value}
hsetprop ${tc_root}/value readtime [sct utime]
}
}
if {[basename [sct]] == "S"} {
set value [expr {[string range ${data} 11 17]}]
set value [expr {${value} * 2.5177E+02 - 1.6116E+01}]
if {${value} != [hgetpropval ${tc_root}/value oldval]} {
debug_log ${tc_root} 1 "${tc_root}/setpoint changed to new:${value}, from old:[hgetpropval ${tc_root}/setpoint oldval]"
hupdate ${tc_root}/setpoint ${value}
hsetprop ${tc_root}/setpoint oldval ${value}
hsetprop ${tc_root}/setpoint readtime [sct utime]
}
}
# 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::tsi_smc::setGauss {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log ${tc_root} 1 "setGauss 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}"
# setGauss hook code starts
set amps [expr {(${par} + 1.6116E+01) / 2.5177E+02}]
hset ${tc_root}/b/Lower ${amps}
# setGauss 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 "setGauss 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::tsi_smc::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::tsi_smc::mkDriver { sct_controller name } {
::scobj::tsi_smc::sics_log 9 "::scobj::tsi_smc::mkDriver for ${name}"
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}/setpoint plain user float
hsetprop ${scobj_hpath}/setpoint write ${ns}::setGauss ${scobj_hpath} noResponse {}
hsetprop ${scobj_hpath}/setpoint noResponse ${ns}::noResponse ${scobj_hpath}
hsetprop ${scobj_hpath}/setpoint check ${ns}::checkrange ${scobj_hpath}
hsetprop ${scobj_hpath}/setpoint driving 0
hsetprop ${scobj_hpath}/setpoint checklimits ${ns}::checklimits ${scobj_hpath}
hsetprop ${scobj_hpath}/setpoint checkstatus ${ns}::checkstatus ${scobj_hpath}
hsetprop ${scobj_hpath}/setpoint halt ${ns}::halt ${scobj_hpath}
hsetprop ${scobj_hpath}/setpoint driveable value
hsetprop ${scobj_hpath}/setpoint control true
hsetprop ${scobj_hpath}/setpoint data true
hsetprop ${scobj_hpath}/setpoint mutable false
hsetprop ${scobj_hpath}/setpoint nxsave true
hsetprop ${scobj_hpath}/setpoint lowerlimit 0
hsetprop ${scobj_hpath}/setpoint upperlimit 500.0
hsetprop ${scobj_hpath}/setpoint tolerance 10
hsetprop ${scobj_hpath}/setpoint oldval 0.0
hsetprop ${scobj_hpath}/setpoint sdsinfo "::nexus::scobj::sdsinfo"
hsetprop ${scobj_hpath}/setpoint settle_time "5"
hsetprop ${scobj_hpath}/setpoint type "drivable"
hsetprop ${scobj_hpath}/setpoint units "G"
hsetprop ${scobj_hpath}/setpoint nxalias "${name}_setpoint"
hfactory ${scobj_hpath}/value plain user float
hsetprop ${scobj_hpath}/value control true
hsetprop ${scobj_hpath}/value data true
hsetprop ${scobj_hpath}/value mutable false
hsetprop ${scobj_hpath}/value nxsave true
hsetprop ${scobj_hpath}/value oldval 0.0
hsetprop ${scobj_hpath}/value sdsinfo "::nexus::scobj::sdsinfo"
hsetprop ${scobj_hpath}/value type "part"
hsetprop ${scobj_hpath}/value units "G"
hsetprop ${scobj_hpath}/value nxalias "${name}_value"
if {[string equal -nocase [SplitReply [environment_simulation]] "false"]} {
${sct_controller} write ${scobj_hpath}/setpoint
} else {
::scobj::tsi_smc::sics_log 9 "[environment_simulation] => No poll/write for tsi_smc"
}
hfactory ${scobj_hpath}/a plain spy none
hfactory ${scobj_hpath}/a/G plain user text
hsetprop ${scobj_hpath}/a/G read ${ns}::getValue ${scobj_hpath} rdValue {G}
hsetprop ${scobj_hpath}/a/G rdValue ${ns}::rdValue ${scobj_hpath}
hsetprop ${scobj_hpath}/a/G control false
hsetprop ${scobj_hpath}/a/G data false
hsetprop ${scobj_hpath}/a/G mutable false
hsetprop ${scobj_hpath}/a/G nxsave true
hsetprop ${scobj_hpath}/a/G oldval UNKNOWN
hsetprop ${scobj_hpath}/a/G offset "16.116"
hsetprop ${scobj_hpath}/a/G sdsinfo "::nexus::scobj::sdsinfo"
hsetprop ${scobj_hpath}/a/G type "part"
hsetprop ${scobj_hpath}/a/G nxalias "${name}_a_G"
hfactory ${scobj_hpath}/a/J plain user text
hsetprop ${scobj_hpath}/a/J read ${ns}::getValue ${scobj_hpath} rdValue {J}
hsetprop ${scobj_hpath}/a/J rdValue ${ns}::rdValue ${scobj_hpath}
hsetprop ${scobj_hpath}/a/J control false
hsetprop ${scobj_hpath}/a/J data false
hsetprop ${scobj_hpath}/a/J mutable false
hsetprop ${scobj_hpath}/a/J nxsave true
hsetprop ${scobj_hpath}/a/J oldval UNKNOWN
hsetprop ${scobj_hpath}/a/J sdsinfo "::nexus::scobj::sdsinfo"
hsetprop ${scobj_hpath}/a/J type "part"
hsetprop ${scobj_hpath}/a/J nxalias "${name}_a_J"
hfactory ${scobj_hpath}/a/K plain user text
hsetprop ${scobj_hpath}/a/K read ${ns}::getValue ${scobj_hpath} rdValue {K}
hsetprop ${scobj_hpath}/a/K rdValue ${ns}::rdValue ${scobj_hpath}
hsetprop ${scobj_hpath}/a/K control false
hsetprop ${scobj_hpath}/a/K data false
hsetprop ${scobj_hpath}/a/K mutable false
hsetprop ${scobj_hpath}/a/K nxsave true
hsetprop ${scobj_hpath}/a/K oldval UNKNOWN
hsetprop ${scobj_hpath}/a/K sdsinfo "::nexus::scobj::sdsinfo"
hsetprop ${scobj_hpath}/a/K type "part"
hsetprop ${scobj_hpath}/a/K nxalias "${name}_a_K"
hfactory ${scobj_hpath}/a/N plain user text
hsetprop ${scobj_hpath}/a/N read ${ns}::getValue ${scobj_hpath} rdValue {N}
hsetprop ${scobj_hpath}/a/N rdValue ${ns}::rdValue ${scobj_hpath}
hsetprop ${scobj_hpath}/a/N control false
hsetprop ${scobj_hpath}/a/N data false
hsetprop ${scobj_hpath}/a/N mutable false
hsetprop ${scobj_hpath}/a/N nxsave true
hsetprop ${scobj_hpath}/a/N oldval UNKNOWN
hsetprop ${scobj_hpath}/a/N sdsinfo "::nexus::scobj::sdsinfo"
hsetprop ${scobj_hpath}/a/N type "part"
hsetprop ${scobj_hpath}/a/N nxalias "${name}_a_N"
hfactory ${scobj_hpath}/a/O plain user text
hsetprop ${scobj_hpath}/a/O read ${ns}::getValue ${scobj_hpath} rdValue {O}
hsetprop ${scobj_hpath}/a/O rdValue ${ns}::rdValue ${scobj_hpath}
hsetprop ${scobj_hpath}/a/O control false
hsetprop ${scobj_hpath}/a/O data false
hsetprop ${scobj_hpath}/a/O mutable false
hsetprop ${scobj_hpath}/a/O nxsave true
hsetprop ${scobj_hpath}/a/O oldval UNKNOWN
hsetprop ${scobj_hpath}/a/O sdsinfo "::nexus::scobj::sdsinfo"
hsetprop ${scobj_hpath}/a/O type "part"
hsetprop ${scobj_hpath}/a/O nxalias "${name}_a_O"
hfactory ${scobj_hpath}/a/S plain user text
hsetprop ${scobj_hpath}/a/S read ${ns}::getValue ${scobj_hpath} rdValue {S}
hsetprop ${scobj_hpath}/a/S rdValue ${ns}::rdValue ${scobj_hpath}
hsetprop ${scobj_hpath}/a/S control false
hsetprop ${scobj_hpath}/a/S data false
hsetprop ${scobj_hpath}/a/S mutable false
hsetprop ${scobj_hpath}/a/S nxsave true
hsetprop ${scobj_hpath}/a/S oldval UNKNOWN
hsetprop ${scobj_hpath}/a/S sdsinfo "::nexus::scobj::sdsinfo"
hsetprop ${scobj_hpath}/a/S type "part"
hsetprop ${scobj_hpath}/a/S nxalias "${name}_a_S"
if {[string equal -nocase [SplitReply [environment_simulation]] "false"]} {
${sct_controller} poll ${scobj_hpath}/a/G 1
${sct_controller} poll ${scobj_hpath}/a/J 1
${sct_controller} poll ${scobj_hpath}/a/K 1
${sct_controller} poll ${scobj_hpath}/a/N 1
${sct_controller} poll ${scobj_hpath}/a/O 1
${sct_controller} poll ${scobj_hpath}/a/S 1
} else {
::scobj::tsi_smc::sics_log 9 "[environment_simulation] => No poll/write for tsi_smc"
}
hfactory ${scobj_hpath}/b plain spy none
hfactory ${scobj_hpath}/b/Lower plain user float
hsetprop ${scobj_hpath}/b/Lower write ${ns}::setValue ${scobj_hpath} noResponse {L}
hsetprop ${scobj_hpath}/b/Lower noResponse ${ns}::noResponse ${scobj_hpath}
hsetprop ${scobj_hpath}/b/Lower check ${ns}::checkrange ${scobj_hpath}
hsetprop ${scobj_hpath}/b/Lower control true
hsetprop ${scobj_hpath}/b/Lower data true
hsetprop ${scobj_hpath}/b/Lower mutable false
hsetprop ${scobj_hpath}/b/Lower nxsave true
hsetprop ${scobj_hpath}/b/Lower lowerlimit 0
hsetprop ${scobj_hpath}/b/Lower upperlimit 2
hsetprop ${scobj_hpath}/b/Lower oldval 0.0
hsetprop ${scobj_hpath}/b/Lower sdsinfo "::nexus::scobj::sdsinfo"
hsetprop ${scobj_hpath}/b/Lower type "part"
hsetprop ${scobj_hpath}/b/Lower nxalias "${name}_b_Lower"
hfactory ${scobj_hpath}/b/Pause plain user int
hsetprop ${scobj_hpath}/b/Pause write ${ns}::setValue ${scobj_hpath} noResponse {P}
hsetprop ${scobj_hpath}/b/Pause noResponse ${ns}::noResponse ${scobj_hpath}
hsetprop ${scobj_hpath}/b/Pause check ${ns}::checkrange ${scobj_hpath}
hsetprop ${scobj_hpath}/b/Pause control true
hsetprop ${scobj_hpath}/b/Pause data true
hsetprop ${scobj_hpath}/b/Pause mutable false
hsetprop ${scobj_hpath}/b/Pause nxsave true
hsetprop ${scobj_hpath}/b/Pause lowerlimit 0
hsetprop ${scobj_hpath}/b/Pause upperlimit 1
hsetprop ${scobj_hpath}/b/Pause values 0,1
hsetprop ${scobj_hpath}/b/Pause oldval 0
hsetprop ${scobj_hpath}/b/Pause sdsinfo "::nexus::scobj::sdsinfo"
hsetprop ${scobj_hpath}/b/Pause type "part"
hsetprop ${scobj_hpath}/b/Pause nxalias "${name}_b_Pause"
hfactory ${scobj_hpath}/b/Ramp plain user int
hsetprop ${scobj_hpath}/b/Ramp write ${ns}::setValue ${scobj_hpath} noResponse {R}
hsetprop ${scobj_hpath}/b/Ramp noResponse ${ns}::noResponse ${scobj_hpath}
hsetprop ${scobj_hpath}/b/Ramp check ${ns}::checkrange ${scobj_hpath}
hsetprop ${scobj_hpath}/b/Ramp control true
hsetprop ${scobj_hpath}/b/Ramp data true
hsetprop ${scobj_hpath}/b/Ramp mutable false
hsetprop ${scobj_hpath}/b/Ramp nxsave true
hsetprop ${scobj_hpath}/b/Ramp lowerlimit 0
hsetprop ${scobj_hpath}/b/Ramp upperlimit 1
hsetprop ${scobj_hpath}/b/Ramp values 0,1
hsetprop ${scobj_hpath}/b/Ramp oldval 0
hsetprop ${scobj_hpath}/b/Ramp sdsinfo "::nexus::scobj::sdsinfo"
hsetprop ${scobj_hpath}/b/Ramp type "part"
hsetprop ${scobj_hpath}/b/Ramp nxalias "${name}_b_Ramp"
hfactory ${scobj_hpath}/b/Rate plain user float
hsetprop ${scobj_hpath}/b/Rate write ${ns}::setValue ${scobj_hpath} noResponse {A}
hsetprop ${scobj_hpath}/b/Rate noResponse ${ns}::noResponse ${scobj_hpath}
hsetprop ${scobj_hpath}/b/Rate check ${ns}::checkrange ${scobj_hpath}
hsetprop ${scobj_hpath}/b/Rate control true
hsetprop ${scobj_hpath}/b/Rate data true
hsetprop ${scobj_hpath}/b/Rate mutable false
hsetprop ${scobj_hpath}/b/Rate nxsave true
hsetprop ${scobj_hpath}/b/Rate oldval 0.0
hsetprop ${scobj_hpath}/b/Rate sdsinfo "::nexus::scobj::sdsinfo"
hsetprop ${scobj_hpath}/b/Rate type "part"
hsetprop ${scobj_hpath}/b/Rate nxalias "${name}_b_Rate"
if {[string equal -nocase [SplitReply [environment_simulation]] "false"]} {
${sct_controller} write ${scobj_hpath}/b/Lower
${sct_controller} write ${scobj_hpath}/b/Pause
${sct_controller} write ${scobj_hpath}/b/Ramp
${sct_controller} write ${scobj_hpath}/b/Rate
} else {
::scobj::tsi_smc::sics_log 9 "[environment_simulation] => No poll/write for tsi_smc"
}
hsetprop ${scobj_hpath} klass environment
hsetprop ${scobj_hpath} debug_threshold 5
if {[string equal -nocase [SplitReply [environment_simulation]] "false"]} {
ansto_makesctdrive ${name}_setpoint ${scobj_hpath}/setpoint ${scobj_hpath}/value ${sct_controller}
}
# mkDriver hook code goes here
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
namespace eval ::scobj::tsi_smc {
namespace export debug_threshold
namespace export debug_log
namespace export sics_log
namespace export mkDriver
}
proc add_tsi_smc {name IP port} {
set catch_status [ catch {
::scobj::tsi_smc::sics_log 9 "add_tsi_smc ${name} ${IP} ${port}"
if {[string equal -nocase [SplitReply [environment_simulation]] "false"]} {
if {[string equal -nocase "aqadapter" "${IP}"]} {
::scobj::tsi_smc::sics_log 9 "makesctcontroller sct_${name} aqadapter ${port}"
makesctcontroller sct_${name} aqadapter ${port}
} else {
::scobj::tsi_smc::sics_log 9 "makesctcontroller sct_${name} std ${IP}:${port}"
makesctcontroller sct_${name} std ${IP}:${port}
}
} else {
::scobj::tsi_smc::sics_log 9 "[environment_simulation] => No sctcontroller for tsi_smc"
}
::scobj::tsi_smc::sics_log 1 "::scobj::tsi_smc::mkDriver sct_${name} ${name}"
::scobj::tsi_smc::mkDriver sct_${name} ${name}
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
clientput "file evaluation of sct_tsi_smc.tcl"
::scobj::tsi_smc::sics_log 9 "file evaluation of sct_tsi_smc.tcl"
proc ::scobj::tsi_smc::read_config {} {
set catch_status [ catch {
set ns "::scobj::tsi_smc"
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"] "tsi_smc"] } {
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"]
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_tsi_smc ${name} ${IP} ${PORT}
} else {
add_tsi_smc ${name} "aqadapter" ${asyncqueue}
}
}
}
}
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
if { [info exists ::config_dict] } {
::scobj::tsi_smc::read_config
} else {
::scobj::tsi_smc::sics_log 5 "No config dict"
}

View File

@ -0,0 +1,79 @@
# Script Context Driver for the Twickenham Scientific Instruments Superconducting Magnet Controller
driver tsi_smc = {
vendor = Twickenham_Scientific_Instruments;
device = Superconducting_Magnet_Controller;
protocol = std;
class = environment; simulation_group = environment_simulation;
group = {
priv = user;
type = float;
property 'units' = 'G';
control = true;
data = true;
nxsave = true;
var 'value';
var setpoint = {
writeable = 1;
write_function = setGauss;
lowerlimit = 0; upperlimit = 500.0; tolerance = 10;
property settle_time = 5;
driveable = 'value';
};
};
group a = {
readable = 1;
priv = user;
type = text;
control = false;
data = false;
var G = { read_command = "G"; property offset = 16.116; };
var J = { read_command = "J"; };
var K = { read_command = "K"; };
var N = { read_command = "N"; };
var O = { read_command = "O"; };
var S = { read_command = "S"; };
};
group b = {
writeable = 1;
priv = user;
type = text;
var Rate = { type = float; write_command = "A"; };
var Lower = { type = float; write_command = "L"; lowerlimit = 0; upperlimit = 2; property 'units' = "A"; };
var Ramp = { type = int; write_command = "R"; allowed = "0,1"; lowerlimit = 0; upperlimit = 1; };
var Pause = { type = int; write_command = "P"; allowed = "0,1"; lowerlimit = 0; upperlimit = 1; };
};
code rdValue = {%%
if {[basename [sct]] == "G"} {
set value [expr {[string range ${data} 1 8]}]
set value [expr {${value} * 2.5177E+02 - 1.6116E+01}]
if {[hpropexists [sct] offset]} {
set value [expr {${value} + [hgetpropval [sct] offset]}]
}
if {${value} != [hgetpropval ${tc_root}/value oldval]} {
debug_log ${tc_root} 1 "${tc_root}/value changed to new:${value}, from old:[hgetpropval ${tc_root}/value oldval]"
hupdate ${tc_root}/value ${value}
hsetprop ${tc_root}/value oldval ${value}
hsetprop ${tc_root}/value readtime [sct utime]
}
}
if {[basename [sct]] == "S"} {
set value [expr {[string range ${data} 11 17]}]
set value [expr {${value} * 2.5177E+02 - 1.6116E+01}]
if {${value} != [hgetpropval ${tc_root}/value oldval]} {
debug_log ${tc_root} 1 "${tc_root}/setpoint changed to new:${value}, from old:[hgetpropval ${tc_root}/setpoint oldval]"
hupdate ${tc_root}/setpoint ${value}
hsetprop ${tc_root}/setpoint oldval ${value}
hsetprop ${tc_root}/setpoint readtime [sct utime]
}
}
%%}
code setGauss = {%%
set amps [expr {(${par} + 1.6116E+01) / 2.5177E+02}]
hset ${tc_root}/b/Lower ${amps}
%%}
};