# vim: ts=8 sts=2 sw=2 expandtab autoindent smartindent nocindent driver he3_polanal = { protocol = std; class = instrument; simulation_group = rfgen_simulation; make_args = '{has_pol true} {has_anal true} {has_coil false}'; group polariser = { conditional = '[string equal -nocase ${has_pol} "true"]'; type = float; var spin = { readable = 900; read_command = 'polariser'; read_function = read_spin; writeable = 1; write_command = 'polariser'; check_function = chkWrite; allowed = "-1,0,+1" } var amplitude = { } var freq = { units = 'Hertz'; } var phase = { units = 'Degree'; } var time2 = { units = 'Second'; } var field = { units = 'Oersted'; } var timestamp = { type = int; } } group polariser_start = { conditional = '[string equal -nocase ${has_pol} "true"]'; type = float; var spin = { } var amplitude = { } var freq = { units = 'Hertz'; } var phase = { units = 'Degree'; } var time2 = { units = 'Second'; } var field = { units = 'Oersted'; } var timestamp = { type = int; } } group analyser = { conditional = '[string equal -nocase ${has_anal} "true"]'; type = float; var spin = { readable = 900; read_command = 'analyser'; read_function = read_spin; writeable = 1; write_command = 'analyser'; check_function = chkWrite; allowed = "+,-,Refresh" } var amplitude = { } var freq = { units = 'Hertz'; } var phase = { units = 'Degree'; } var time2 = { units = 'Second'; } var field = { units = 'Oersted'; } var timestamp = { type = int; } } group analyser_start = { conditional = '[string equal -nocase ${has_anal} "true"]'; type = float; var spin = { } var amplitude = { } var freq = { units = 'Hertz'; } var phase = { units = 'Degree'; } var time2 = { units = 'Second'; } var field = { units = 'Oersted'; } var timestamp = { type = int; } } group magnet = { conditional = '[string equal -nocase ${has_coil} "true"]'; type = float; group sense = { var x_voltage = {} var x_current = {} var y_voltage = {} var y_current = {} var z_voltage = {} var z_current = {} var sense = { type = int; data = false; mutable = false; nxsave = false; readable = 30; read_command = 'magnet_xyz'; read_function = read_magnet; writeable = 1; write_function = fetch_magnet; write_command = 'magnet_xyz'; } } group setpoint = { var x_current_sp = {} var y_current_sp = {} var z_current_sp = {} var store = { type = int; data = false; mutable = false; nxsave = false; writeable = 1; write_function = write_magnet; write_command = 'magnet_xyz'; } } } code read_magnet = { @TCL set dlist [split [string trim ${data}]] if {[llength $dlist] != 7} { error "Syntax error: '${data}'" } set index 1 set path [pathname [sct]] set ns [namespace current] foreach node {x_voltage x_current y_voltage y_current z_voltage z_current} { hsetprop ${path}/${node} result [lindex $dlist ${index}] sct with ${path}/${node} "${ns}::rdValue ${tc_root}" incr index } set data 0 @END } code fetch_magnet = { @TCL # Just do a fetch and go on to the read state set cmd "${cmd_str}" set nextState "read_magnet" @END } code write_magnet = { @TCL # Just do a fetch and go on to the read state set path [pathname [sct]] set cmd "${cmd_str}" set cmd "${cmd} [hval ${path}/x_current_sp]" set cmd "${cmd} [hval ${path}/y_current_sp]" set cmd "${cmd} [hval ${path}/z_current_sp]" @END } code chkWrite = {%% [namespace current]::read_spin ${tc_root} clientput [sct result] %%} code read_spin = {%% set dlist [split [string trim ${data}]] if {[llength ${dlist}] < 2} { sct geterror "Syntax Error: '${data}'" error "[sct geterror]" } set my_name [basename [pathname [sct]]] if {![string equal -nocase "[lindex ${dlist} 0]" "${my_name}"]} { error "[lindex ${dlist} 0] is not my name (${my_name})" } if {[string match "*Not Active*" "${data}"]} { set data 0 } elseif {[string match -nocase "*Error:*" "${data}"]} { sct geterror "${data}" error "[sct geterror]" } else { set data [lindex ${dlist} 1] } set path [pathname [sct]] set timestamp [clock seconds] [namespace current]::do_update ${path}/amplitude ${dlist} 2 [namespace current]::do_update ${path}/freq ${dlist} 3 [namespace current]::do_update ${path}/phase ${dlist} 4 [namespace current]::do_update ${path}/time2 ${dlist} 5 [namespace current]::do_update ${path}/field ${dlist} 6 hupdateif ${path}/timestamp ${timestamp} %%} code setValue = {%% set cmd "${cmd_str}" if {[sct target] == "-" || [sct target] == -1} { set cmd "${cmd_str} -" } if {[sct target] == "+" || [sct target] == 1} { set cmd "${cmd_str} +" } %%} code preamble = { @TCL proc do_update { node dlist idx } { if {[llength ${dlist}] > ${idx}} { if {![string is double [lindex ${dlist} ${idx}]]} { hupdateif ${node} 0.0 } else { hupdateif ${node} [lindex ${dlist} ${idx}] } } } @END } code postamble = { @TCL proc stash {node} { foreach arg {spin amplitude freq phase time2 field timestamp} { hupdateif ${node}_start/${arg} [hval ${node}/${arg}] } } @END } }