Files
sics/site_ansto/instrument/config/environment/temperature/oxford_mercury.sct

266 lines
12 KiB
Tcl

#
# Oxford Mercury with all devices as conditional groups
# vim: ft=tcl ts=8 sts=2 sw=2 expandtab autoindent smartindent nocindent
#
# Douglas Clowes (Douglas.Clowes@ansto.gov.au) November 2014
#
driver oxford_mercury = {
vendor = oxford;
device = mercury;
protocol = std;
class = environment;
simulation_group = environment_simulation;
# cards is the cards in the mercury slots 12345678
# H=Heater(1-3), V=Valve(4), L=Level(5), T=Temp(1-8), P=Pres(5,8), N=None(1-8)
# assoc is the associated actuator (H,V) for the controller (T,P) in the slot
add_args = 'id {cards NNNNNNNN} {assoc 00000000} {ttol 1} {ptol 5} {vtol 5}';
make_args = 'id {cards NNNNNNNN} {assoc 00000000} {ttol 1} {ptol 5} {vtol 5}';
group = {
group_property 'cards' = '${cards}';
group_property 'assoc' = '${assoc}';
group temp0 = {
# Always the motherboard, always there
priv = user; type = float; readable = 5;
var sensor = { readable = 1; read_command = 'READ:DEV:MB1.T1:TEMP:SIG:TEMP'; permlink = 'T.S00'; }
var nick = { type=text; readable = 15; read_command = 'READ:DEV:MB1.T1:TEMP:NICK'; read_function = rdText; }
var auto = {
type = int; allowed = '0,1';
read_function = rdOnOff; read_command = 'READ:DEV:MB1.T1:TEMP:LOOP:ENAB';
writeable = 1; write_function = wrOnOff; write_command = 'SET:DEV:MB1.T1:TEMP:LOOP:ENAB:';
}
var setpoint = { read_command = 'READ:DEV:MB1.T1:TEMP:LOOP:TSET';
driveable = temp0/sensor; lowerlimit = 0; upperlimit = 333; tolerance = '${ttol}'; property settle_time = 15;
writeable = 1; write_function = setPoint; write_command = 'SET:DEV:MB1.T1:TEMP:LOOP:TSET:';
permlink = 'T.SP00';
}
group heater = {
var power = { read_command = 'READ:DEV:MB0.H1:HTR:SIG:POWR'; }
var perc = { read_command = 'READ:DEV:MB0.H1:HTR:SIG:PERC'; }
var hset = {
read_command = 'READ:DEV:MB1.T1:TEMP:LOOP:HSET';
lowerlimit = 0; upperlimit = 100;
writeable = 1; write_command = 'SET:DEV:MB1.T1:TEMP:LOOP:HSET:';
}
}
}
%exec
exec_output = []
for i in range(8):
exec_output += [""]
exec_output += [" group temp%d = {" % (i+1)]
exec_output += [" conditional = '[string equal -nocase [string index ${cards} %d] T]';" % i]
exec_output += [" priv = user; type = float; readable = 5;"]
exec_output += [" var sensor = { readable = 1; read_command = 'READ:DEV:DB%d.T1:TEMP:SIG:TEMP'; permlink = 'T.S%02d'; }" % (i+1,i+1)]
exec_output += [" var nick = { type=text; readable = 15; read_command = 'READ:DEV:DB%d.T1:TEMP:NICK'; read_function = rdText; }" % (i+1)]
if i > 4:
exec_output += [" var auto = {"]
exec_output += [" conditional = '[string equal -nocase [string index ${cards} %d] H] && [string equal -nocase [string index ${assoc} %d] %d]';" % (i-5, i, i-4)]
exec_output += [" type = int; allowed = '0,1'; read_command = 'READ:DEV:DB%d.T1:TEMP:LOOP:ENAB';" % (i + 1)]
exec_output += [" read_function = rdOnOff; read_command = 'READ:DEV:DB%d.T1:TEMP:LOOP:ENAB';" % (i + 1)]
exec_output += [" writeable = 1; write_function = wrOnOff; write_command = 'SET:DEV:DB%d.T1:TEMP:LOOP:ENAB:';" % (i + 1)]
exec_output += [" }"]
exec_output += [" var setpoint = {"]
exec_output += [" conditional = '[string equal -nocase [string index ${cards} %d] H] && [string equal -nocase [string index ${assoc} %d] %d]';" % (i-5, i, i-4)]
exec_output += [" read_command = 'READ:DEV:DB%d.T1:TEMP:LOOP:TSET';" % (i + 1)]
exec_output += [" driveable = temp%d/sensor; lowerlimit = 0; upperlimit = 333; tolerance = '${ttol}'; property settle_time = 15;" % (i + 1)]
exec_output += [" writeable = 1; write_function = setPoint; write_command = 'SET:DEV:DB%d.T1:TEMP:LOOP:TSET:';" % (i + 1)]
exec_output += [" permlink = 'T.SP%02d';" % (i + 1)]
exec_output += [" }"]
exec_output += [" group heater = {"]
exec_output += [" conditional = '[string equal -nocase [string index ${cards} %d] H] && [string equal -nocase [string index ${assoc} %d] %d]';" % (i-5, i, i-4)]
exec_output += [" var power = { read_command = 'READ:DEV:DB%d.H1:HTR:SIG:POWR'; }" % (i - 4)]
exec_output += [" var perc = { read_command = 'READ:DEV:DB%d.H1:HTR:SIG:PERC'; }" % (i - 4)]
exec_output += [" var hset = {"]
exec_output += [" read_command = 'READ:DEV:DB%d.T1:TEMP:LOOP:HSET';" % (i + 1)]
exec_output += [" lowerlimit = 0; upperlimit = 100;"]
exec_output += [" writeable = 1; write_command = 'SET:DEV:DB%d.T1:TEMP:LOOP:HSET:';" % (i + 1)]
exec_output += [" }"]
exec_output += [" }"]
exec_output += [" }"]
%end
group pres5 = {
conditional = '[string equal -nocase [string index ${cards} 4] P]';
priv = user; type = float; readable = 5;
var sensor = { readable = 1; read_command = 'READ:DEV:DB5.P1:PRES:SIG:PRES'; permlink = 'P.PS05'; units = "mB"; }
var nick = { type=text; readable = 15; read_command = 'READ:DEV:DB5.P1:PRES:NICK'; read_function = rdText; }
var valve = {
conditional = '[string equal -nocase [string index ${cards} 3] V] && [string equal -nocase [string index ${assoc} 4] 4]';
read_command = 'READ:DEV:DB4.G1:AUX:SIG:PERC';
}
var enab = {
conditional = '[string equal -nocase [string index ${cards} 3] V] && [string equal -nocase [string index ${assoc} 4] 4]';
type = int; allowed = '0,1';
read_function = rdOnOff; read_command = 'READ:DEV:DB5.P1:PRES:LOOP:ENAB';
writeable = 1; write_function = wrOnOff; write_command = 'SET:DEV:DB5.P1:PRES:LOOP:ENAB:';
}
var auto = {
conditional = '[string equal -nocase [string index ${cards} 3] V] && [string equal -nocase [string index ${assoc} 4] 4]';
type = int; allowed = '0,1';
read_function = rdOnOff; read_command = 'READ:DEV:DB5.P1:PRES:LOOP:FAUT';
writeable = 1; write_function = wrOnOff; write_command = 'SET:DEV:DB5.P1:PRES:LOOP:FAUT:';
}
var setpoint = {
conditional = '[string equal -nocase [string index ${cards} 3] V] && [string equal -nocase [string index ${assoc} 4] 4]';
read_command = 'READ:DEV:DB5.P1:PRES:LOOP:TSET';
driveable = pres5/sensor; lowerlimit = 0; upperlimit = 333; tolerance = '${ptol}'; property settle_time = 15;
writeable = 1; write_function = setPoint; write_command = 'SET:DEV:DB8.P1:PRES:LOOP:TSET:';
permlink = 'P.PSP05'; units = "mB";
}
var fset = {
read_command = 'READ:DEV:DB5.P1:PRES:LOOP:FSET';
lowerlimit = 0; upperlimit = 100;
writeable = 1; write_command = 'SET:DEV:DB5.P1:PRES:LOOP:FSET:';
}
}
group pres8 = {
conditional = '[string equal -nocase [string index ${cards} 7] P]';
priv = user; type = float; readable = 5;
var sensor = { readable = 1; read_command = 'READ:DEV:DB8.P1:PRES:SIG:PRES'; permlink = 'P.PS08'; units = "mB"; }
var nick = { type=text; readable = 15; read_command = 'READ:DEV:DB8.P1:PRES:NICK'; read_function = rdText; }
var valve = {
conditional = '[string equal -nocase [string index ${cards} 3] V] && [string equal -nocase [string index ${assoc} 7] 4]';
read_command = 'READ:DEV:DB4.G1:AUX:SIG:PERC';
}
var enab = {
conditional = '[string equal -nocase [string index ${cards} 3] V] && [string equal -nocase [string index ${assoc} 7] 4]';
type = int; allowed = '0,1';
read_function = rdOnOff; read_command = 'READ:DEV:DB8.P1:PRES:LOOP:ENAB';
writeable = 1; write_function = wrOnOff; write_command = 'SET:DEV:DB8.P1:PRES:LOOP:ENAB:';
}
var auto = {
conditional = '[string equal -nocase [string index ${cards} 3] V] && [string equal -nocase [string index ${assoc} 7] 4]';
type = int; allowed = '0,1';
read_function = rdOnOff; read_command = 'READ:DEV:DB8.P1:PRES:LOOP:FAUT';
writeable = 1; write_function = wrOnOff; write_command = 'SET:DEV:DB8.P1:PRES:LOOP:FAUT:';
}
var setpoint = {
conditional = '[string equal -nocase [string index ${cards} 3] V] && [string equal -nocase [string index ${assoc} 7] 4]';
read_command = 'READ:DEV:DB8.P1:PRES:LOOP:TSET';
driveable = pres8/sensor; lowerlimit = 0; upperlimit = 333; tolerance = '${ptol}'; property settle_time = 15;
writeable = 1; write_function = setPoint; write_command = 'SET:DEV:DB8.P1:PRES:LOOP:TSET:';
permlink = 'P.PSP08'; units = "mB";
}
var fset = {
read_command = 'READ:DEV:DB8.P1:PRES:LOOP:FSET';
lowerlimit = 0; upperlimit = 100;
writeable = 1; write_command = 'SET:DEV:DB8.P1:PRES:LOOP:FSET:';
}
}
group valve = {
conditional = '[string equal -nocase [string index ${cards} 3] V]';
priv = user; type = float;
var sensor = {
readable = 5; read_command = 'READ:DEV:DB4.G1:AUX:SIG:PERC';
}
var nick = { type=text; readable = 15; read_command = 'READ:DEV:DB4.G1:AUX:NICK'; read_function = rdText; }
}
group level = {
conditional = '[string equal -nocase [string index ${cards} 4] L]';
priv = user; type = float; readable = 15;
var nitrogen = { read_command = 'READ:DEV:DB5.L1:LVL:SIG:NIT:LEV'; permlink = 'T.N2'; }
var helium = { read_command = 'READ:DEV:DB5.L1:LVL:SIG:HEL:LEV'; permlink = 'T.He'; }
var nick = { type=text; readable = 15; read_command = 'READ:DEV:DB5.L1:LVL:NICK'; read_function = rdText; }
}
}
code read_function rdValue = {
@TCL
set value [lindex [split "${data}" ":"] end]
if {[string equal -nocase -length 3 ${value} NaN]} {
set value 0
}
if {[string equal -nocase -length 3 ${value} inf] || [string equal -nocase -length 4 ${value} -inf]} {
set value 0
}
if {![string is digit [string index ${value} 0]]} {
set value 0
}
debug_log ${tc_root} 1 "rdValue tc_root=${tc_root} sct=[sct] result=[sct result]"
debug_log ${tc_root} 1 "rdValue tc_root=${tc_root} data=${data} value=${value}"
scan ${value} "%g" data
@END
}
code read_function rdText = {
@ scan [lindex [split "$data" ":"] end] "%s" data
}
code write_function setPoint = {
}
code write_function setValve = {
}
code read_function rdOnOff = {
@TCL
scan [lindex [split "$data" ":"] end] "%s" data
if {[string equal -nocase ${data} "ON"]} {
set data 1
} else {
set data 0
}
@END
}
code write_function wrOnOff = {
@TCL
if { ${par} == 1 } {
set cmd "${cmd_str}ON"
} else {
set cmd "${cmd_str}OFF"
}
@END
}
code preamble = {
@TCL
proc make_config {sct_controller} {
set syscat [${sct_controller} transact READ:SYS:CAT]
set result ""
set devs [regexp -inline -all {DEV:[DM][[:alnum:]\.]*:[[:alnum:]]*} ${syscat}]
foreach dev [lsort ${devs}] {
set typ [string index [lindex [split ${dev} :] end] 0]
set typ [string map {A V} ${typ}]
clientput "${dev} ${typ}"
set result "${result}${typ}"
}
clientput "Result: ${result}"
return ${result}
}
proc read_all {sct_controller} {
set syscat [${sct_controller} transact READ:SYS:CAT]
set devs [regexp -inline -all {DEV:[DM][[:alnum:]\.]*:[[:alnum:]]*} ${syscat}]
foreach dev [lsort ${devs}] {
set response [${sct_controller} transact READ:${dev}]
clientput "Device: ${response}"
}
}
proc read_loop {sct_controller} {
set pat {\m[A-Z]{1,}:[^:]{1,}}
set syscat [${sct_controller} transact READ:SYS:CAT]
set devs [regexp -inline -all {DEV:[DM][[:alnum:]\.]*:[[:alnum:]]*} ${syscat}]
foreach dev [lsort ${devs}] {
set response [${sct_controller} transact READ:${dev}:LOOP]
clientput "Device: ${response}"
clientput " Loop: [regexp -inline -all $pat [string trim ${response}]]"
}
}
proc read_sig {sct_controller} {
set pat {\m[A-Z]{1,}:[^:]{1,}}
set syscat [${sct_controller} transact READ:SYS:CAT]
set devs [regexp -inline -all {DEV:[DM][[:alnum:]\.]*:[[:alnum:]]*} ${syscat}]
foreach dev [lsort ${devs}] {
set response [${sct_controller} transact READ:${dev}:SIG]
clientput "Device: ${response}"
clientput " Sig: [regexp -inline -all $pat [string trim ${response}]]"
}
}
@END
}
}