Perform the rename
This commit is contained in:
411
site_ansto/instrument/config/environment/isotech_ps_sct.tcl
Normal file
411
site_ansto/instrument/config/environment/isotech_ps_sct.tcl
Normal file
@@ -0,0 +1,411 @@
|
||||
# Generated driver for isotech_ps
|
||||
# vim: ft=tcl tabstop=8 softtabstop=2 shiftwidth=2 nocindent smartindent
|
||||
#
|
||||
|
||||
namespace eval ::scobj::isotech_ps {
|
||||
set debug_threshold 5
|
||||
}
|
||||
|
||||
proc ::scobj::isotech_ps::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/isotech_ps_[basename ${tc_root}].log" "a"]
|
||||
set line "[clock format [clock seconds] -format "%T"] ${debug_string}"
|
||||
puts ${fd} "${line}"
|
||||
close ${fd}
|
||||
}
|
||||
} catch_message ]
|
||||
}
|
||||
|
||||
proc ::scobj::isotech_ps::sics_log {debug_level debug_string} {
|
||||
set catch_status [ catch {
|
||||
set debug_threshold ${::scobj::isotech_ps::debug_threshold}
|
||||
if {${debug_level} >= ${debug_threshold}} {
|
||||
sicslog "::scobj::isotech_ps::${debug_string}"
|
||||
}
|
||||
} catch_message ]
|
||||
}
|
||||
|
||||
# check function for hset change
|
||||
proc ::scobj::isotech_ps::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::isotech_ps::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::isotech_ps::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::isotech_ps::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
|
||||
set data [string range [sct result] 1 end]
|
||||
# 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 parse the read of a parameter on a device
|
||||
proc ::scobj::isotech_ps::read_relay {tc_root} {
|
||||
set catch_status [ catch {
|
||||
debug_log ${tc_root} 1 "read_relay 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_relay hook code starts
|
||||
if { [string equal -nocase -length 2 "F1" "${data}"] } {
|
||||
set data 1
|
||||
} elseif { [string equal -nocase -length 2 "F0" "${data}"] } {
|
||||
set data 0
|
||||
} else {
|
||||
sct geterror "Unexpected response '${data}' not 'F1' nor 'F0'"
|
||||
}
|
||||
# read_relay 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::isotech_ps::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}
|
||||
}
|
||||
|
||||
# function to write a parameter value on a device
|
||||
proc ::scobj::isotech_ps::write_relay {tc_root nextState cmd_str} {
|
||||
set catch_status [ catch {
|
||||
debug_log ${tc_root} 1 "write_relay 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}"
|
||||
# write_relay hook code starts
|
||||
if { ${par} == 0 } {
|
||||
set cmd "KOD"
|
||||
} else {
|
||||
set cmd "KOE"
|
||||
}
|
||||
# write_relay 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 "write_relay 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::isotech_ps::write_voltage {tc_root nextState cmd_str} {
|
||||
set catch_status [ catch {
|
||||
debug_log ${tc_root} 1 "write_voltage 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}"
|
||||
# write_voltage hook code starts
|
||||
set par "[format "%05.2f" [sct target]]"
|
||||
set cmd "SV ${par}"
|
||||
# write_voltage 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 "write_voltage 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::isotech_ps::mkDriver { sct_controller name } {
|
||||
::scobj::isotech_ps::sics_log 9 "::scobj::isotech_ps::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}/amps plain user float
|
||||
hsetprop ${scobj_hpath}/amps read ${ns}::getValue ${scobj_hpath} rdValue {A}
|
||||
hsetprop ${scobj_hpath}/amps rdValue ${ns}::rdValue ${scobj_hpath}
|
||||
hsetprop ${scobj_hpath}/amps control true
|
||||
hsetprop ${scobj_hpath}/amps data true
|
||||
hsetprop ${scobj_hpath}/amps mutable true
|
||||
hsetprop ${scobj_hpath}/amps nxsave true
|
||||
hsetprop ${scobj_hpath}/amps units A
|
||||
hsetprop ${scobj_hpath}/amps oldval 0.0
|
||||
hsetprop ${scobj_hpath}/amps sdsinfo "::nexus::scobj::sdsinfo"
|
||||
hsetprop ${scobj_hpath}/amps type "part"
|
||||
hsetprop ${scobj_hpath}/amps nxalias "${name}_amps"
|
||||
|
||||
hfactory ${scobj_hpath}/relay plain user int
|
||||
hsetprop ${scobj_hpath}/relay read ${ns}::getValue ${scobj_hpath} read_relay {F}
|
||||
hsetprop ${scobj_hpath}/relay read_relay ${ns}::read_relay ${scobj_hpath}
|
||||
hsetprop ${scobj_hpath}/relay write ${ns}::write_relay ${scobj_hpath} noResponse {KO}
|
||||
hsetprop ${scobj_hpath}/relay noResponse ${ns}::noResponse ${scobj_hpath}
|
||||
hsetprop ${scobj_hpath}/relay check ${ns}::checkrange ${scobj_hpath}
|
||||
hsetprop ${scobj_hpath}/relay control true
|
||||
hsetprop ${scobj_hpath}/relay data true
|
||||
hsetprop ${scobj_hpath}/relay mutable true
|
||||
hsetprop ${scobj_hpath}/relay nxsave true
|
||||
hsetprop ${scobj_hpath}/relay oldval 0
|
||||
hsetprop ${scobj_hpath}/relay sdsinfo "::nexus::scobj::sdsinfo"
|
||||
hsetprop ${scobj_hpath}/relay type "part"
|
||||
hsetprop ${scobj_hpath}/relay nxalias "${name}_relay"
|
||||
|
||||
hfactory ${scobj_hpath}/volts plain user float
|
||||
hsetprop ${scobj_hpath}/volts read ${ns}::getValue ${scobj_hpath} rdValue {V}
|
||||
hsetprop ${scobj_hpath}/volts rdValue ${ns}::rdValue ${scobj_hpath}
|
||||
hsetprop ${scobj_hpath}/volts write ${ns}::write_voltage ${scobj_hpath} noResponse {SV}
|
||||
hsetprop ${scobj_hpath}/volts noResponse ${ns}::noResponse ${scobj_hpath}
|
||||
hsetprop ${scobj_hpath}/volts check ${ns}::checkrange ${scobj_hpath}
|
||||
hsetprop ${scobj_hpath}/volts control true
|
||||
hsetprop ${scobj_hpath}/volts data true
|
||||
hsetprop ${scobj_hpath}/volts mutable true
|
||||
hsetprop ${scobj_hpath}/volts nxsave true
|
||||
hsetprop ${scobj_hpath}/volts units V
|
||||
hsetprop ${scobj_hpath}/volts oldval 0.0
|
||||
hsetprop ${scobj_hpath}/volts sdsinfo "::nexus::scobj::sdsinfo"
|
||||
hsetprop ${scobj_hpath}/volts type "part"
|
||||
hsetprop ${scobj_hpath}/volts nxalias "${name}_volts"
|
||||
|
||||
if {[string equal -nocase [SplitReply [environment_simulation]] "false"]} {
|
||||
${sct_controller} poll ${scobj_hpath}/amps 5
|
||||
${sct_controller} poll ${scobj_hpath}/relay 5
|
||||
${sct_controller} poll ${scobj_hpath}/volts 5
|
||||
${sct_controller} write ${scobj_hpath}/relay
|
||||
${sct_controller} write ${scobj_hpath}/volts
|
||||
} else {
|
||||
::scobj::isotech_ps::sics_log 9 "[environment_simulation] => No poll/write for isotech_ps"
|
||||
}
|
||||
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::isotech_ps {
|
||||
namespace export debug_threshold
|
||||
namespace export debug_log
|
||||
namespace export sics_log
|
||||
namespace export mkDriver
|
||||
}
|
||||
|
||||
proc add_isotech_ps {name IP port} {
|
||||
set catch_status [ catch {
|
||||
::scobj::isotech_ps::sics_log 9 "add_isotech_ps ${name} ${IP} ${port}"
|
||||
if {[string equal -nocase [SplitReply [environment_simulation]] "false"]} {
|
||||
if {[string equal -nocase "aqadapter" "${IP}"]} {
|
||||
::scobj::isotech_ps::sics_log 9 "makesctcontroller sct_${name} aqadapter ${port}"
|
||||
makesctcontroller sct_${name} aqadapter ${port}
|
||||
} else {
|
||||
::scobj::isotech_ps::sics_log 9 "makesctcontroller sct_${name} std ${IP}:${port} \"\\r\""
|
||||
makesctcontroller sct_${name} std ${IP}:${port} "\r"
|
||||
}
|
||||
} else {
|
||||
::scobj::isotech_ps::sics_log 9 "[environment_simulation] => No sctcontroller for isotech_ps"
|
||||
}
|
||||
::scobj::isotech_ps::sics_log 1 "::scobj::isotech_ps::mkDriver sct_${name} ${name}"
|
||||
::scobj::isotech_ps::mkDriver sct_${name} ${name}
|
||||
} catch_message ]
|
||||
handle_exception ${catch_status} ${catch_message}
|
||||
}
|
||||
|
||||
clientput "file evaluation of sct_isotech_ps.tcl"
|
||||
::scobj::isotech_ps::sics_log 9 "file evaluation of sct_isotech_ps.tcl"
|
||||
|
||||
proc ::scobj::isotech_ps::read_config {} {
|
||||
set catch_status [ catch {
|
||||
set ns "::scobj::isotech_ps"
|
||||
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"] "isotech_ps"] } {
|
||||
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_isotech_ps ${name} ${IP} ${PORT}
|
||||
} else {
|
||||
add_isotech_ps ${name} "aqadapter" ${asyncqueue}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch_message ]
|
||||
handle_exception ${catch_status} ${catch_message}
|
||||
}
|
||||
|
||||
if { [info exists ::config_dict] } {
|
||||
::scobj::isotech_ps::read_config
|
||||
} else {
|
||||
::scobj::isotech_ps::sics_log 5 "No config dict"
|
||||
}
|
||||
Reference in New Issue
Block a user