From f14b2c0a82a9d744182e085c6f6e248adda3c8b1 Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Mon, 3 Feb 2014 11:04:06 +1100 Subject: [PATCH] Script Context driver generator files for Hiden XCS and Isotech Power Supply --- .../config/environment/hiden_xcs.sct | 132 ++++++++++++++++++ .../config/environment/isotech_ps.sct | 57 ++++++++ 2 files changed, 189 insertions(+) create mode 100644 site_ansto/instrument/config/environment/hiden_xcs.sct create mode 100644 site_ansto/instrument/config/environment/isotech_ps.sct diff --git a/site_ansto/instrument/config/environment/hiden_xcs.sct b/site_ansto/instrument/config/environment/hiden_xcs.sct new file mode 100644 index 00000000..6a6e9f2d --- /dev/null +++ b/site_ansto/instrument/config/environment/hiden_xcs.sct @@ -0,0 +1,132 @@ +# +# Simple driver generator for the Hiden Isochema XCS vapour delivery system +# vim: ts=8 sts=2 sw=2 expandtab autoindent smartindent +# +driver hiden_xcs_gen = { + usecreatenode = false + vendor = hiden; device = xcs; protocol = std; + class = environment + simulation_group = environment_simulation + add_args = 'terminator {tol 0.5}'; + make_args = 'tol'; + protocol_args = '${terminator}'; +# +# Unnamed group has variables at device level +# + group = { + type = float + priv = user + var temperature + var flow1 + var flow2 + var flow3 + var humidity = { + driveable = humidity + readable = 1 + read_command = '?ALL DATA' + read_function = read_all_data + value = 50 + lowerlimit = 10 + upperlimit = 90 + tolerance = 5 + } + } +# +# The named group is at the device level, variables below that +# + group analog = { + type = float; + priv = user; + readable = 1; + read_function = read_sixteen; + var ain0 = { read_command = '?AIN,0'; }; + var ain1 = { read_command = '?AIN,1'; }; + var ain2 = { read_command = '?AIN,2'; }; + var ain8 = { read_command = '?AIN,8'; }; + var ain9 = { read_command = '?AIN,9'; }; + var ain12 = { read_command = '?AIN,12'; }; + writeable = 1; + read_function = read_twelve; + write_function = write_twelve; + var aout0 = { read_command = '?AOUT,0'; write_command = '!AOUT,0,'; } + var aout1 = { read_command = '?AOUT,1'; write_command = '!AOUT,1,'; } + var aout2 = { read_command = '?AOUT,2'; write_command = '!AOUT,2,'; } + }; + group digital = { + type = int; + priv = user; + readable = 1; + writeable = 1; + read_function = read_digital; + write_Function = write_digital; + var dout2 = { read_command = '?DOUT,2'; write_command = '!DOUT,2,'; allowed = '0,1'; readable = 5} + } + +# +# Code lines start with '@' which is stripped before being emitted into generated driver +# The code is emitted at the appropriate place in the given function +# + code read_function read_digital = { +@ if { [string equal -nocase -length 5 "${data}" "DOUT ="] } { +@ set result [scan "${data}" "DOUT = %d OK" val] +@ if { ${result} == 1 } { +@ set data ${val} +@ } else { +@ sct geterror "Syntax error (Result=${result}) in: '${data}'" +@ } +@ } else { +@ sct geterror "Syntax error in: '${data}'" +@ } + } + code read_function read_twelve = { +@ if { [string equal -nocase -length 5 "${data}" "AOUT ="] } { +@ set result [scan "${data}" "AOUT = %d OK" val] +@ if { ${result} == 1 } { +@ set data [expr (100.0 * ${val}) / 4095.0] +@ } else { +@ sct geterror "Syntax (Result=${result}) error in: '${data}'" +@ } +@ } else { +@ sct geterror "Syntax error in: '${data}'" +@ } + } + code read_function read_sixteen = { +@ if { [string equal -nocase -length 5 "${data}" "AIN ="] } { +@ set result [scan "${data}" "AIN = %d OK" val] +@ if { ${result} == 1 } { +@ set data [expr (100.0 * ${val}) / 65535.0] +@ } else { +@ sct geterror "Syntax error (Result=${result}) in: '${data}'" +@ } +@ } else { +@ sct geterror "Syntax error in: '${data}'" +@ } + } + code read_function read_all_data = { +@ if { [string equal -nocase -length 2 "${data}" "A "] } { +@ set lust [split [string range "${data}" 2 end-3] ','] +@ if { [llength ${lust}] == 8 } { +@ set data [expr [lindex ${lust} 0]] +@ hupdate ${tc_root}/temperature [expr [lindex ${lust} 1]] +@ hupdate ${tc_root}/flow1 [expr [lindex ${lust} 3]] +@ hupdate ${tc_root}/flow2 [expr [lindex ${lust} 4]] +@ hupdate ${tc_root}/flow3 [expr [lindex ${lust} 5]] +@ } else { +@ sct geterror "Syntax error (Result=${result}) in: '${data}'" +@ } +@ } else { +@ sct geterror "Syntax error for read_all_data in: '${data}'" +@ } + } + code write_function write_digital = { + } + code write_function write_twelve = { +@ set par [expr int(4095.0 * ${par} / 100.0)] +@ set cmd "${cmd_str}${par}" + } +# +# This code is after database creation +# + code mkDriver = { + } +}; diff --git a/site_ansto/instrument/config/environment/isotech_ps.sct b/site_ansto/instrument/config/environment/isotech_ps.sct new file mode 100644 index 00000000..585a29d4 --- /dev/null +++ b/site_ansto/instrument/config/environment/isotech_ps.sct @@ -0,0 +1,57 @@ +# Simple driver generator for the ISOTECH Power Supply +# vim: ts=8 sts=2 sw=2 expandtab autoindent smartindent +# +driver isotech_ps = { + vendor = isotech; device = ps; protocol = std; + class = environment; + simulation_group = environment_simulation; + protocol_args = '"\r"'; + group = { + readable = 5 + mutable = true + var relay = { + type = int; + read_command = 'F'; + read_function = read_relay; + writeable = 1 + write_command = 'KO'; + write_function = write_relay; + } + var amps = { + type = float; + read_command = 'A'; + units = 'A' + } + var volts = { + type = float; + read_command = 'V'; + writeable = 1; + write_command = 'SV'; + write_function = write_voltage; + units = 'V' + } + } + code read_function rdValue = { + @ set data [string range [sct result] 1 end] + } + code read_function read_relay = { + @ 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'" + @ } + } + code write_function write_relay = { + @ if { ${par} == 0 } { + @ set cmd "KOD" + @ } else { + @ set cmd "KOE" + @ } + } + code write_function write_voltage = { + @ set par "[format "%05.2f" [sct target]]" + @ set cmd "SV ${par}" + } +}