Merged in-situ modifications for Release 2.5 candidate 5

r2895 | ffr | 2010-04-29 16:02:15 +1000 (Thu, 29 Apr 2010) | 2 lines
This commit is contained in:
Ferdi Franceschini
2010-04-29 16:02:15 +10:00
committed by Douglas Clowes
parent a2ca46ab67
commit e6e3c3be52
24 changed files with 478 additions and 363 deletions

View File

@@ -3,6 +3,8 @@
# MakeSICSObj $obj SCT_<class>
# The MakeSICSObj cmd adds a /sics/$obj node. NOTE the /sics node is not browsable.
#include <tcl.h>
##
# /*--------------------------------------------------------------------------
# B R U K E R B - E C 1 D R I V E R
@@ -19,6 +21,11 @@
# ----------------------------------------------------------------------------*/
# Notes
# Uses the astvelsel protocol handler (from ./site_ansto/hardsup/sct_velselprot.c)
# instead of the standard script context handler. This is necessary because replies
# from the device have no terminator while queries to the device need a line terminator
# (CR 0x0D). am2010-04-07
#
# Hdb nodes which report data readings should have a "get" script attached to the
# "read" property of the node. This ensures that we can update the reading on demand
# which is necessary for logging data.
@@ -35,7 +42,7 @@
# Bugs, limitations, changes:
# - checks whether the reply from the device matches the query - if not, it discards the reply.
# - added LSB_Err byte 1 interpretation (water failure). Added help notes
# - added lsb_err byte 1 interpretation (water failure). Added help notes
# for the user for the status byte text nodes.
# - MAJOR PROBLEM: Although the driver seems to be doing just about everything
# right, the BEC1 device shuts itself off (changes to DCpower=0) and goes
@@ -56,7 +63,8 @@
# - proc drivestatus now sets a retval variable that is returned. Default
# action for drivable when paused is lazy instead of pause to avoid
# stopping the histogram server.
# - source code syntax checked with nagelfar - removed a couple of potential
# problems, 20100121
##
# @brief Handle exceptions caught by a 'catch' command.
# Note: You must use 'error' not 'return -code error' to
@@ -104,7 +112,8 @@ namespace eval ::scobj::bruker_BEC1 {
# if necessary. If commands come in too fast, the DCpower may switch itself off.
set bruker_BEC1_MIN_TIME_BETWEEN_COMMANDS 50
# set a start value for the time of the last command send to or read from the device
set bruker_BEC1_timeLastCommand [clock clicks -milliseconds]
#set bruker_BEC1_timeLastCommand 0
#set bruker_BEC1_timeLastCommand [clock clicks -milliseconds]
# Some global variables that are useful as default initilisation values or for tracking
# Name of the scriptcontext object created from calling this driver - an instrument may use more than one
@@ -203,19 +212,13 @@ proc bruker_BEC1_init {sct_controller tc_root} {
# @param idx indicates which control loop or which input channel
# the command belongs to
# @return nextState The next function to call after this one (typically 'rdValue')
proc getValue {tc_root nextState cmd expectedLen} {
set catch_status [ catch {
set ::scobj::bruker_BEC1::bruker_BEC1_lastQueryCmd "$cmd"
set tNow [clock clicks -milliseconds]
#set diff1 [expr $tNow - $::scobj::bruker_BEC1::bruker_BEC1_timeLastCommand]
while {[expr $tNow - $::scobj::bruker_BEC1::bruker_BEC1_timeLastCommand] < $::scobj::bruker_BEC1::bruker_BEC1_MIN_TIME_BETWEEN_COMMANDS} {
set tNow [clock clicks -milliseconds]
}
#set diff2 [expr $tNow - $::scobj::bruker_BEC1::bruker_BEC1_timeLastCommand]
after $::scobj::bruker_BEC1::bruker_BEC1_MIN_TIME_BETWEEN_COMMANDS
sct send $cmd
# puts "sct send !$cmd!"
set ::scobj::bruker_BEC1::bruker_BEC1_timeLastCommand $tNow
#puts "diff1:$diff1, diff2:$diff2 $cmd"
return $nextState
} message ]
handle_exception $catch_status $message "in getValue(). Last query command: $::scobj::bruker_BEC1::bruker_BEC1_lastQueryCmd"
@@ -239,7 +242,7 @@ proc getValue {tc_root nextState cmd expectedLen} {
# Discard if it is not the reply to our query
return idle
}
set catch_status [ catch {
set catch_status [ catch {
# Continue as normal
switch -glob -- $data {
"ASCERR:*" {
@@ -297,7 +300,7 @@ proc getValue {tc_root nextState cmd expectedLen} {
set data [ExtractValue $orgdata $::scobj::bruker_BEC1::bruker_BEC1_lastQueryCmd]
#puts "rdValue: Interpreting status byte information: $::scobj::bruker_BEC1::bruker_BEC1_lastQueryCmd"
#pwrCtrl EthernetAddrHex 1 0 1 0 text spy {ETH/} {rdValue} {} {setValue} {}\
hset $::scobj::bruker_BEC1::bruker_BEC1_path2nodes/pwrCtrl/EthernetAddrDec "UNKNOWN"
hset $::scobj::bruker_BEC1::bruker_BEC1_path2nodes/pwrctrl/EthernetAddrDec "UNKNOWN"
}
}
}
@@ -306,7 +309,7 @@ proc getValue {tc_root nextState cmd expectedLen} {
return idle
} message ]
handle_exception $catch_status $message "in rdValue(). Last query command: $::scobj::bruker_BEC1::bruker_BEC1_lastQueryCmd"
}
}
@@ -314,7 +317,7 @@ proc getValue {tc_root nextState cmd expectedLen} {
##
# @brief Does what rdValue() does plus it checks if the current is in tolerance.
# inTolerance is the default nextState after getValue() for read node pwrCtrl/DC_power.
# inTolerance is the default nextState after getValue() for read node pwrctrl/dc_power.
# If the device is switched off, current is reported to be in tolerance so that
# slow return to ambient conditions can be carried out
# @return idle Always returns system state idle - command sequence completed.
@@ -328,8 +331,8 @@ proc inTolerance {expectedLength} {
return idle
}
set catch_status [ catch {
set oldval [sct oldval]
# puts "inTolerance(): data=$data oldval=$oldval"
set oldvalue [sct oldval]
# puts "inTolerance(): data=$data oldval=$oldvalue"
switch -glob -- $data {
"ASCERR:*" {
puts "ASCERR in inTolerance: Last query command: $::scobj::bruker_BEC1::bruker_BEC1_lastQueryCmd"
@@ -345,8 +348,8 @@ proc inTolerance {expectedLength} {
return idle
}
set data [ExtractValue $data $::scobj::bruker_BEC1::bruker_BEC1_lastQueryCmd]
if {$data != $oldval} {
if {$oldval == "UNKNOWN"} {
if {$data != $oldvalue} {
if {$oldvalue == "UNKNOWN"} {
sct utime timecheck
}
sct oldval $data
@@ -360,27 +363,27 @@ proc inTolerance {expectedLength} {
# is within tolerance of the corresponding setpoint
if {$data == 0 } {
# DC power switched off
hset $tc_root/emon/monMode "idle"
hset $tc_root/emon/isInTolerance "inTolerance"
hset $tc_root/emon/mon_mode "idle"
hset $tc_root/emon/is_in_tolerance "inTolerance"
hset $tc_root/status "idle"
} else {
set intol [checktol $tc_root]
if {$intol==0} { sct utime timecheck }
set nodename $tc_root/sensor/NominalOutpCurrent
set nodename $tc_root/sensor/nominal_outp_current
set setpt [hval $nodename]
set nodename $tc_root/sensor/DesiredCurrent
set NominalOutpCurrent [hval $nodename]
set nodename $tc_root/sensor/desired_current
set nominal_outp_current [hval $nodename]
# puts "inTolerance(): comparing sensor/setpoint=$setpt with actual sensorValue=$temp"
set diff [expr abs($setpt - $NominalOutpCurrent)]
set diff [expr {abs($setpt - $NominalOutpCurrent)}]
if {$diff > $::scobj::bruker_BEC1::bruker_BEC1_driveTolerance} {
# ERROR: node /sics/ma1/emon/monMode not found. Last query command: DCP/
set nodename $tc_root/emon/monMode
# ERROR: node /sics/ma1/emon/mon_mode not found. Last query command: DCP/
set nodename $tc_root/emon/mon_mode
hset $nodename "drive"
hset $tc_root/status "busy"
} else {
set nodename $tc_root/sensor/NominalOutpCurrent
set nodename $tc_root/sensor/nominal_outp_current
hsetprop $nodename driving 0
set nodename $tc_root/emon/monMode
set nodename $tc_root/emon/mon_mode
hset $nodename "monitor"
hset $tc_root/status "idle"
}
@@ -407,18 +410,14 @@ proc setValue {tc_root nextState cmd } {
set catch_status [ catch {
set par [sct target]
set ::scobj::bruker_BEC1::bruker_BEC1_lastWriteCmd "$cmd$par"
set tNow [clock clicks -milliseconds]
while {[expr $tNow - $::scobj::bruker_BEC1::bruker_BEC1_timeLastCommand] < $::scobj::bruker_BEC1::bruker_BEC1_MIN_TIME_BETWEEN_COMMANDS} {
set tNow [clock clicks -milliseconds]
}
after $::scobj::bruker_BEC1::bruker_BEC1_MIN_TIME_BETWEEN_COMMANDS
sct send "$cmd$par"
set ::scobj::bruker_BEC1::bruker_BEC1_timeLastCommand $tNow
if { 0 == [string compare -length 4 $cmd "RST=0"] } {
# Reset error messages - also update the node displaying the last error
set ::scobj::bruker_BEC1::bruker_BEC1_errMsg "none"
set ::scobj::bruker_BEC1::bruker_BEC1_errMsg2 "none"
hset $::scobj::bruker_BEC1::bruker_BEC1_path2nodes/emon/lastErrorMsg $::scobj::bruker_BEC1::bruker_BEC1_errMsg
hset $::scobj::bruker_BEC1::bruker_BEC1_path2nodes/emon/lastErrorMsg2 $::scobj::bruker_BEC1::bruker_BEC1_errMsg2
hset $::scobj::bruker_BEC1::bruker_BEC1_path2nodes/emon/last_error_msg $::scobj::bruker_BEC1::bruker_BEC1_errMsg
hset $::scobj::bruker_BEC1::bruker_BEC1_path2nodes/emon/last_error_msg2 $::scobj::bruker_BEC1::bruker_BEC1_errMsg2
}
return $nextState
} message ]
@@ -456,11 +455,7 @@ proc setDesiredField {tc_root nextState cmd} {
hsetprop $nodename driving 1
}
#puts "setDesiredField(wrStatus=$wrStatus): sct send $cmd$par"
set tNow [clock clicks -milliseconds]
#set diff1 [expr $tNow - $::scobj::bruker_BEC1::bruker_BEC1_timeLastCommand]
while {[expr $tNow - $::scobj::bruker_BEC1::bruker_BEC1_timeLastCommand] < $::scobj::bruker_BEC1::bruker_BEC1_MIN_TIME_BETWEEN_COMMANDS} {
set tNow [clock clicks -milliseconds]
}
after $::scobj::bruker_BEC1::bruker_BEC1_MIN_TIME_BETWEEN_COMMANDS
sct send "$cmd$par"
return $nextState
} message ]
@@ -485,17 +480,12 @@ proc setDesiredCurrent {tc_root nextState cmd} {
if {$wrStatus == "start"} {
# Called by drive adapter
# puts "setDesiredCurrent(): driving set to 1"
set nodename $tc_root/sensor/NominalOutpCurrent
set nodename $tc_root/sensor/nominal_outp_current
hsetprop $nodename driving 1
}
#puts "setDesiredCurrent(wrStatus=$wrStatus): sct send $cmd$par"
set tNow [clock clicks -milliseconds]
#set diff1 [expr $tNow - $::scobj::bruker_BEC1::bruker_BEC1_timeLastCommand]
while {[expr $tNow - $::scobj::bruker_BEC1::bruker_BEC1_timeLastCommand] < $::scobj::bruker_BEC1::bruker_BEC1_MIN_TIME_BETWEEN_COMMANDS} {
set tNow [clock clicks -milliseconds]
}
after $::scobj::bruker_BEC1::bruker_BEC1_MIN_TIME_BETWEEN_COMMANDS
sct send "$cmd$par"
set ::scobj::bruker_BEC1::bruker_BEC1_timeLastCommand $tNow
return $nextState
} message ]
handle_exception $catch_status $message "in setDesiredCurrent(). Last write command: $::scobj::bruker_BEC1::bruker_BEC1_lastWriteCmd"
@@ -512,7 +502,7 @@ proc setDesiredCurrent {tc_root nextState cmd} {
proc drivestatus {tc_root} {
# broadcast "DEBUG: in drivestatus. Last write command: $::scobj::bruker_BEC1::bruker_BEC1_lastWriteCmd"
set catch_status [ catch {
if [sct driving] {
if {[sct driving]} {
set retval busy
} else {
set retval idle
@@ -529,8 +519,8 @@ proc drivestatus {tc_root} {
# @return idle Indicates that the device is ready for the next command
proc halt {tc_root} {
# stop driving at current field strength or current
set sensorValue $tc_root/sensor/DesiredCurrent
set nodename $tc_root/sensor/NominalOutpCurrent
set sensorValue $tc_root/sensor/desired_current
set nodename $tc_root/sensor/nominal_outp_current
hset $nodename [hval $sensorValue]
hsetprop $nodename driving 0
return idle
@@ -571,7 +561,7 @@ proc ExtractValue {response lastQueryCmd} {
"E01*" {set ::scobj::bruker_BEC1::bruker_BEC1_errMsg "FUNCTION ERROR - Function not supported, $response"}
"E02*" {set ::scobj::bruker_BEC1::bruker_BEC1_errMsg "ARGUMENT ERROR - command argument contains unexpected characters, $response"}
"E03*" {set ::scobj::bruker_BEC1::bruker_BEC1_errMsg "PORT NOT AVAILABLE, $response"}
"E04*" {set ::scobj::bruker_BEC1::bruker_BEC1_errMsg "LOCAL ERROR - access denied, check LocalRemoteState setting, $response"}
"E04*" {set ::scobj::bruker_BEC1::bruker_BEC1_errMsg "LOCAL ERROR - access denied, check local_remote_state setting, $response"}
"E05*" {set ::scobj::bruker_BEC1::bruker_BEC1_errMsg "RANGE ERROR - the arguments are out of the allowed range, $response"}
"E06*" {set ::scobj::bruker_BEC1::bruker_BEC1_errMsg "MODE ERROR - access denied, external reference active, $response"}
"E07*" {set ::scobj::bruker_BEC1::bruker_BEC1_errMsg "ERROR PENDING, $response"}
@@ -579,9 +569,9 @@ proc ExtractValue {response lastQueryCmd} {
"E99*" {set ::scobj::bruker_BEC1::bruker_BEC1_errMsg "NO TCP/IP COMMUNICATION, $response"}
}
set extractedValue $::scobj::bruker_BEC1::bruker_BEC1_errValue
# update the node lastErrorMsg
hset $::scobj::bruker_BEC1::bruker_BEC1_path2nodes/emon/lastErrorMsg $::scobj::bruker_BEC1::bruker_BEC1_errMsg
hset $::scobj::bruker_BEC1::bruker_BEC1_path2nodes/emon/lastErrorMsg2 $::scobj::bruker_BEC1::bruker_BEC1_errMsg2
# update the node last_error_msg
hset $::scobj::bruker_BEC1::bruker_BEC1_path2nodes/emon/last_error_msg $::scobj::bruker_BEC1::bruker_BEC1_errMsg
hset $::scobj::bruker_BEC1::bruker_BEC1_path2nodes/emon/last_error_msg2 $::scobj::bruker_BEC1::bruker_BEC1_errMsg2
#if { 0 != [string compare -length 4 $lastQueryCmd "POL/"] \
# || $::scobj::bruker_BEC1::bruker_BEC1_polarityUnitAbsent == false} {
#}
@@ -662,11 +652,14 @@ proc decodeErrByte {errByte errList} {
#puts "decodeErrByte: errByte:$errByte"
set catch_status [ catch {
# convert to decimal for calculations
set decErrByte [expr 0x$errByte]
set hexvar "0x$errByte"
set decErrByte [expr {$hexvar}]
# puts "errByte=$errByte, hexvar=$hexvar, decErrByte=$decErrByte"
foreach {hexVal errText} $errList {
#puts "errByte:$errByte hexVal:$hexVal errText:$errText"
# convert to decimal for calculations
set decVal [expr 0x$hexVal]
set hexvar "0x$hexVal"
set decVal [expr { $hexvar }]
#puts "decErrByte:$decErrByte decVal:$decVal errText:$errText"
if { $decErrByte >= $decVal } {
if {[string length $errorText] > 1} {
@@ -674,11 +667,11 @@ proc decodeErrByte {errByte errList} {
} else {
set errorText $errText
}
set decErrByte [expr $decErrByte - $decVal]
set decErrByte [expr {$decErrByte - $decVal}]
}
}
if {2 > [string length $errText]} {
set $errorText "Unknown error"
set errorText "Unknown error"
}
return $errorText
} message ]
@@ -696,10 +689,10 @@ proc extractStatusByte {statusByteString whichByte} {
set catch_status [ catch {
set statusByte "UNKNOWN"
set statusByteStringLength [string length $statusByteString]
set offset [expr $whichByte*2]
set offset [expr {$whichByte*2}]
# allow for an initial offset of 4 char for 'STA/'
incr offset 4
set statusByte [string range $statusByteString $offset [expr $offset+1]]
set statusByte [string range $statusByteString $offset [expr {$offset+1}]]
#puts "ExtractValue(): response:$response, extractedValue:$extractedValue"
return $statusByte
} message ]
@@ -787,13 +780,13 @@ proc analyseStatusByte {statusByteString} {
}
#puts "LSB_ErrByte :x$tmp_LSB_ErrByte: $LSB_ErrByteTxt"
#puts "MSB_ErrByte :x$tmp_MSB_ErrByte: $MSB_ErrByteTxt"
#puts "PwrSupplyStatus:x$tmp_PwrSupplyStatusByte: $PwrSupplyStatusByteTxt"
#puts "pwr_supply_status:x$tmp_PwrSupplyStatusByte: $PwrSupplyStatusByteTxt"
#puts "StateMachine :x$tmp_StateMachineStatusByte: $StateMachineStatusTxt"
hset $::scobj::bruker_BEC1::bruker_BEC1_path2nodes/pwrCtrl/LSB_Err "x$tmp_LSB_ErrByte: $LSB_ErrByteTxt"
hset $::scobj::bruker_BEC1::bruker_BEC1_path2nodes/pwrCtrl/MSB_Err "x$tmp_MSB_ErrByte: $MSB_ErrByteTxt"
hset $::scobj::bruker_BEC1::bruker_BEC1_path2nodes/pwrCtrl/PwrSupplyStatus "x$tmp_PwrSupplyStatusByte: $PwrSupplyStatusByteTxt"
hset $::scobj::bruker_BEC1::bruker_BEC1_path2nodes/pwrCtrl/StateMachineStatus "x$tmp_StateMachineStatusByte: $StateMachineStatusByteTxt"
hset $::scobj::bruker_BEC1::bruker_BEC1_path2nodes/pwrctrl/lsb_err "x$tmp_LSB_ErrByte: $LSB_ErrByteTxt"
hset $::scobj::bruker_BEC1::bruker_BEC1_path2nodes/pwrctrl/msb_err "x$tmp_MSB_ErrByte: $MSB_ErrByteTxt"
hset $::scobj::bruker_BEC1::bruker_BEC1_path2nodes/pwrctrl/pwr_supply_status "x$tmp_PwrSupplyStatusByte: $PwrSupplyStatusByteTxt"
hset $::scobj::bruker_BEC1::bruker_BEC1_path2nodes/pwrctrl/state_machine_status "x$tmp_StateMachineStatusByte: $StateMachineStatusByteTxt"
return "Ok"
} message ]
handle_exception $catch_status $message "in analyseStatusByte(). statusByteString: $statusByteString"
@@ -829,7 +822,7 @@ proc getValFromString {s element separator} {
# startIdx points to the first non-blank character of the value we are interested in
set returnval ""
if {$startIdx < 0} {
return returnval
return $returnval
}
set endIdx [string first $separator $s $startIdx]
incr endIdx -1
@@ -843,7 +836,7 @@ proc getValFromString {s element separator} {
}
#puts "getValFromString $s, $element, $separator,\n returns: $returnval"
return $returnval
}
}
@@ -854,18 +847,18 @@ proc getValFromString {s element separator} {
proc checktol {tc_root} {
set catch_status [ catch {
set retVal 0
set sensorValue $tc_root/sensor/DesiredCurrent
set NominalOutpCurrent [hval $sensorValue]
set isetp $tc_root/sensor/NominalOutpCurrent
set sensorValue $tc_root/sensor/desired_current
set nominal_outp_current [hval $sensorValue]
set isetp $tc_root/sensor/nominal_outp_current
set setpt [hval $isetp]
set tol [hval $tc_root/emon/tolerance]
set loField [expr $setpt - $tol]
set hiField [expr $setpt + $tol]
set loField [expr {$setpt - $tol}]
set hiField [expr {$setpt + $tol}]
if { $NominalOutpCurrent < $loField || $NominalOutpCurrent > $hiField} {
hset $tc_root/emon/isInTolerance "outsideTolerance"
hset $tc_root/emon/is_in_tolerance "outsideTolerance"
set retVal 0
} else {
hset $tc_root/emon/isInTolerance "inTolerance"
hset $tc_root/emon/is_in_tolerance "inTolerance"
set retVal 1
}
return $retVal
@@ -926,23 +919,23 @@ proc helpNotes4user {scobj_hpath cmdGroup varName} {
set helptext "No help available"
#puts "helpNotes4user $scobj_hpath/$cmdGroup varName"
switch -glob $varName {
"LocalRemoteState*" {
"local_remote_state*" {
set h1 {REM: «n» Query or Set local/remote state.}
set h2 {«n» 0:local (local and remote comands allowed).}
set h3 {«n» 1:remote state (only remote commands allowed).}
set helptext $h1$CRLF$h2$CRLF$h3
}
"DC_power*" {
"dc_power*" {
set h1 {DCP «off/on» DC power }
set h2 { 0:off, 1:on}
set helptext $h1$CRLF$h2
}
"DesiredCurrent*" {
"desired_current*" {
set h1 {CUR «nn.nn» Read and set DAC current}
set h2 {«nn.nn» DAC current in Amperes}
set helptext $h1$CRLF$h2
}
"PwrCtrlFrom*" {
"pwr_ctrl_from*" {
set h1 {EXT: «n» Query / Set source of reference for power supply control}
set h2 {«EXT:0» internal reference, DAC}
set h3 {«EXT:1» external reference voltage}
@@ -963,17 +956,17 @@ proc helpNotes4user {scobj_hpath cmdGroup varName} {
set h3 {«POL:1» Set negative polarity}
set helptext $h1$CRLF$h2$CRLF$h3
}
"ActualDAC_Field*" {
"actual_dac_field*" {
set h1 {FLD «nn.nn» Query/Set magnetic field strength }
set h2 {«nn.nn» magnetic field strength in Teslas (setpoint)}
set helptext $h1$CRLF$h2
}
"NominalOutpCurrent*" {
"nominal_outp_current*" {
set h1 {CHN «nn.nn» Query nominal output current.}
set h2 {«nn.nn» Nominal output current in Amperes}
set helptext $h1$CRLF$h2
}
"OutputVoltage*" {
"output_voltage*" {
set h1 {CHV «nn.nn» Query output voltage.}
set h2 { «nn.nn» Output voltage in Volts.}
set helptext $h1$CRLF$h2
@@ -983,13 +976,13 @@ proc helpNotes4user {scobj_hpath cmdGroup varName} {
set h2 {Returned: Load resistance in Ohms.}
set helptext $h1$CRLF$h2
}
"MeasuredField*" {
"measured_field*" {
set h1 {CHF/ Query measured magnetic field. }
set h2 {Returned: Measured magnetic field in Teslas.}
set h3 {}
set helptext $h1$CRLF$h2$CRLF$h3
}
"ResetErrorMsg*" {
"reset_error_msg*" {
set h1 {RST: «0» Reset error messages. }
set h2 { «0» Send zero to reset error messages.}
set helptext $h1$CRLF$h2
@@ -999,25 +992,25 @@ proc helpNotes4user {scobj_hpath cmdGroup varName} {
set h2 {Returned: status byte in hexadecimal format. Note: DC power must be ON}
set helptext $h1$CRLF$h2
}
"LSB_Err*" {
"lsb_err*" {
set h1 {Interpretation of the first 2 hexadecimal characters of the StatusByte string.}
set h2 {LSB (lower status byte) contains interlock status conditions}
set h3 {such as water or partial power failure.}
set helptext $h1$CRLF$h2$CRLF$h3
}
"MSB_Err*" {
"msb_err*" {
set h1 {Interpretation of the hexadecimal characters 3 and 4 of the StatusByte string.}
set h2 {MSB (machine status byte) contains interlock status conditions}
set h3 {such as an overcurrent condition.}
set helptext $h1$CRLF$h2$CRLF$h3
}
"PwrSupplyStatus*" {
"pwr_supply_status*" {
set h1 {Interpretation of the hexadecimal characters 5 and 6 of the StatusByte string.}
set h2 {Contains information about the power supply status}
set h3 {such as DC power on or off.}
set helptext $h1$CRLF$h2$CRLF$h3
}
"StateMachineStatus*" {
"state_machine_status*" {
set h1 {Interpretation of the hexadecimal characters 7 and 8 of the StatusByte string.}
set h2 {Contains information about the power supply State Machines}
set h3 {such as the Inrush or Test DAC states.}
@@ -1031,7 +1024,7 @@ proc helpNotes4user {scobj_hpath cmdGroup varName} {
set h2 {Returned: ethernet address in hexadecimal numbers.}
set helptext $h1$CRLF$h2
}
"isInTolerance*" {
"is_in_tolerance*" {
set h1 {A flag that indicates whether the actual magnetic field strength is within tolerance}
set h2 {of the setpoint field strength.}
set helptext $h1$CRLF$h2
@@ -1045,7 +1038,7 @@ proc helpNotes4user {scobj_hpath cmdGroup varName} {
set h1 {Tolerance specifies the magnetic field strength tolerance in Tesla applicable to the setpoint.}
set helptext $h1
}
"monMode*" {
"mon_mode*" {
set h1 {A flag that indicates whether the magnet's current is being actively changed to}
set h2 {drive the magnetic field towards the setpoint or whether the current is stable}
set h3 {with the magnetic field in tolerance with the setpoint.}
@@ -1056,8 +1049,8 @@ proc helpNotes4user {scobj_hpath cmdGroup varName} {
set h2 {The default action is always 'pause'.}
set helptext $h1$CRLF$h2
}
"lastErrorMsg*" {
set helptext {lastErrorMsg and lastErrorMsg2 display the last 2 error messages received from the device.}
"last_error_msg*" {
set helptext {last_error_msg and last_error_msg2 display the last 2 error messages received from the device.}
}
default {
set helptext {Sorry mate. No help available.}
@@ -1089,11 +1082,11 @@ proc helpNotes4user {scobj_hpath cmdGroup varName} {
# @param wrCmd actual device write command to be sent to the device
# @param wrFunc Function to be called to send the wrCmd to the device, typically setValue()
# @param allowedValues allowed values for the node data - does not permit other
# @param klass Nexus class name (?)
# @param klasse Nexus class name (?)
# @return OK
proc createNode {scobj_hpath sct_controller cmdGroup varName readable writable\
pollEnabled drivable replyLen dataType permission rdCmd rdFunc wrCmd\
wrFunc allowedValues klass} {
wrFunc allowedValues klasse} {
#puts "createing node for: $scobj_hpath $cmdGroup $varName $readable $writable $pollEnabled $drivable $dataType $permission $rdCmd $rdFunc $wrCmd $wrFunc"
set catch_status [ catch {
set ns ::scobj::bruker_BEC1
@@ -1145,11 +1138,11 @@ proc createNode {scobj_hpath sct_controller cmdGroup varName readable writable\
##
# @brief mk_sct_bruker_BEC1() creates a scriptcontext object for a Bruker BEC1 power supply (for 1T magnet)
# @param sct_controller name of the bruker_BEC1 scriptcontext object (typically sct_bruker_BEC1_tc1 or tc2)
# @param klass Nexus class name (?), typically 'environment'
# @param klasse Nexus class name (?), typically 'environment'
# @param tempobj short name for the magnet power supply scriptcontext object (typ. ma1 or ma2)
# @param tol magentic field strength tolerance in Tesla (typ. 1)
# @return nothing (well, the sct object)
proc mk_sct_bruker_BEC1 {sct_controller klass tempobj tol} {
proc mk_sct_bruker_BEC1 {sct_controller klasse tempobj tol} {
set catch_status [ catch {
set ns ::scobj::bruker_BEC1
set ::scobj::bruker_BEC1::bruker_BEC1_sct_obj_name $tempobj
@@ -1159,10 +1152,10 @@ proc mk_sct_bruker_BEC1 {sct_controller klass tempobj tol} {
#set LF "\n"
set ::scobj::bruker_BEC1::bruker_BEC1_tolerance $tol
set ::scobj::bruker_BEC1::bruker_BEC1_driveTolerance [expr $tol * $::scobj::bruker_BEC1::bruker_BEC1_tolerance]
set ::scobj::bruker_BEC1::bruker_BEC1_driveTolerance [expr {$tol * $::scobj::bruker_BEC1::bruker_BEC1_tolerance}]
MakeSICSObj $tempobj SCT_OBJECT
sicslist setatt $tempobj klass $klass
sicslist setatt $tempobj klass $klasse
sicslist setatt $tempobj long_name $tempobj
# Create a base node for all the state machines of this sics object
set scobj_hpath /sics/$tempobj
@@ -1189,18 +1182,18 @@ proc mk_sct_bruker_BEC1 {sct_controller klass tempobj tol} {
# wrFunc Function to be called to send the wrCmd to the device, typically setValue()
# allowedValues allowed values for the node data - does not permit other
set deviceCommandToplevel {\
sensor MeasuredField 1 0 1 0 13 float spy {CHF/} {rdValue} {} {setValue} {}\
sensor ActualDAC_Field 1 1 1 0 16 float user {FLD/} {rdValue} {FLD=} {setValue} {}\
sensor DesiredCurrent 1 1 1 1 15 float user {CUR/} {rdValue} {CUR=} {setDesiredCurrent} {}\
sensor NominalOutpCurrent 1 0 1 0 13 float spy {CHN/} {rdValue} {} {setDesiredCurrent} {}\
sensor measured_field 1 0 1 0 13 float spy {CHF/} {rdValue} {} {setValue} {}\
sensor actual_dac_field 1 1 1 0 16 float user {FLD/} {rdValue} {FLD=} {setValue} {}\
sensor desired_current 1 1 1 1 15 float user {CUR/} {rdValue} {CUR=} {setDesiredCurrent} {}\
sensor nominal_outp_current 1 0 1 0 13 float spy {CHN/} {rdValue} {} {setDesiredCurrent} {}\
}
set deviceCommand {\
pwrCtrl DC_power 1 1 1 0 7 int user {DCP/} {inTolerance} {DCP=} {setValue} {0,1}\
pwrCtrl PwrCtrlFrom 1 1 1 0 7 int user {EXT/} {rdValue} {EXT=} {setValue} {0,1,2}\
pwrCtrl LocalRemoteState 1 1 1 0 7 int user {REM/} {rdValue} {REM=} {setValue} {0,1}\
pwrCtrl OutputVoltage 1 0 1 0 12 float spy {CHV/} {rdValue} {} {setValue} {}\
pwrCtrl ResetErrorMsg 0 1 0 0 7 int user {} {rdValue} {RST=} {setValue} {0}\
pwrCtrl statusByte 1 1 1 0 13 text user {STA/} {rdValue} {STA=} {setValue} {0}\
pwrctrl dc_power 1 1 1 0 7 int user {DCP/} {inTolerance} {DCP=} {setValue} {0,1}\
pwrctrl pwr_ctrl_from 1 1 1 0 7 int user {EXT/} {rdValue} {EXT=} {setValue} {0,1,2}\
pwrctrl local_remote_state 1 1 1 0 7 int user {REM/} {rdValue} {REM=} {setValue} {0,1}\
pwrctrl output_voltage 1 0 1 0 12 float spy {CHV/} {rdValue} {} {setValue} {}\
pwrctrl reset_error_msg 0 1 0 0 7 int user {} {rdValue} {RST=} {setValue} {0}\
pwrctrl statusByte 1 1 1 0 13 text user {STA/} {rdValue} {STA=} {setValue} {0}\
}
# it seems these functions are not supported by our device
#pwrCtrl EthernetAddrHex 1 0 1 0 text spy {ETH/} {rdValue} {} {setValue} {}\
@@ -1210,26 +1203,26 @@ proc mk_sct_bruker_BEC1 {sct_controller klass tempobj tol} {
hfactory $scobj_hpath/sensor plain spy none
foreach {cmdGroup varName readable writable pollEnabled drivable replyLen dataType permission rdCmd rdFunc wrCmd wrFunc allowedValues} $deviceCommandToplevel {
createNode $scobj_hpath $sct_controller $cmdGroup $varName $readable $writable $pollEnabled $drivable $replyLen $dataType $permission $rdCmd $rdFunc $wrCmd $wrFunc $allowedValues $klass
createNode $scobj_hpath $sct_controller $cmdGroup $varName $readable $writable $pollEnabled $drivable $replyLen $dataType $permission $rdCmd $rdFunc $wrCmd $wrFunc $allowedValues $klasse
}
# create a base node for each commandGroup element - these are all polled
hfactory $scobj_hpath/emon plain spy none
hfactory $scobj_hpath/pwrCtrl plain spy none
hfactory $scobj_hpath/pwrctrl plain spy none
foreach {cmdGroup varName readable writable pollEnabled drivable replyLen dataType permission rdCmd rdFunc wrCmd wrFunc allowedValues} $deviceCommand {
createNode $scobj_hpath $sct_controller $cmdGroup $varName $readable $writable $pollEnabled $drivable $replyLen $dataType $permission $rdCmd $rdFunc $wrCmd $wrFunc $allowedValues $klass
createNode $scobj_hpath $sct_controller $cmdGroup $varName $readable $writable $pollEnabled $drivable $replyLen $dataType $permission $rdCmd $rdFunc $wrCmd $wrFunc $allowedValues $klasse
}
# Create state machines for the following required nodes that do not correspond
# to device commands.
hfactory $scobj_hpath/emon/lastErrorMsg plain user text
#hsetprop $scobj_hpath/emon/lastErrorMsg values *any*
hset $scobj_hpath/emon/lastErrorMsg $::scobj::bruker_BEC1::bruker_BEC1_errMsg
helpNotes4user $scobj_hpath "emon" "lastErrorMsg"
hfactory $scobj_hpath/emon/lastErrorMsg2 plain user text
hset $scobj_hpath/emon/lastErrorMsg2 $::scobj::bruker_BEC1::bruker_BEC1_errMsg2
helpNotes4user $scobj_hpath "emon" "lastErrorMsg2"
hfactory $scobj_hpath/emon/last_error_msg plain user text
#hsetprop $scobj_hpath/emon/last_error_msg values *any*
hset $scobj_hpath/emon/last_error_msg $::scobj::bruker_BEC1::bruker_BEC1_errMsg
helpNotes4user $scobj_hpath "emon" "last_error_msg"
hfactory $scobj_hpath/emon/last_error_msg2 plain user text
hset $scobj_hpath/emon/last_error_msg2 $::scobj::bruker_BEC1::bruker_BEC1_errMsg2
helpNotes4user $scobj_hpath "emon" "last_error_msg2"
#hfactory $scobj_hpath/emon/statusText plain user text
#hset $scobj_hpath/emon/statusText $::scobj::bruker_BEC1::bruker_BEC1_statusText
@@ -1240,10 +1233,10 @@ proc mk_sct_bruker_BEC1 {sct_controller klass tempobj tol} {
hset $scobj_hpath/emon/apply_tolerance 1
helpNotes4user $scobj_hpath "emon" "apply_tolerance"
hfactory $scobj_hpath/emon/isInTolerance plain spy text
hsetprop $scobj_hpath/emon/isInTolerance values idle,drive,monitor,error
hset $scobj_hpath/emon/isInTolerance "inTolerance"
helpNotes4user $scobj_hpath "emon" "isInTolerance"
hfactory $scobj_hpath/emon/is_in_tolerance plain spy text
hsetprop $scobj_hpath/emon/is_in_tolerance values idle,drive,monitor,error
hset $scobj_hpath/emon/is_in_tolerance "inTolerance"
helpNotes4user $scobj_hpath "emon" "is_in_tolerance"
hfactory $scobj_hpath/emon/tolerance plain user float
hsetprop $scobj_hpath/emon/tolerance units $::scobj::bruker_BEC1::bruker_BEC1_magneticFiledUnits
@@ -1252,34 +1245,34 @@ proc mk_sct_bruker_BEC1 {sct_controller klass tempobj tol} {
helpNotes4user $scobj_hpath "emon" "tolerance"
# environment monitoring flags: shows if setpoints (field, current) are in tolerance
hfactory $scobj_hpath/emon/monMode plain user text
hsetprop $scobj_hpath/emon/monMode values idle,drive,monitor,error
hset $scobj_hpath/emon/monMode "idle"
helpNotes4user $scobj_hpath "emon" "monMode"
hfactory $scobj_hpath/emon/mon_mode plain user text
hsetprop $scobj_hpath/emon/mon_mode values idle,drive,monitor,error
hset $scobj_hpath/emon/mon_mode "idle"
helpNotes4user $scobj_hpath "emon" "mon_mode"
hfactory $scobj_hpath/emon/errhandler plain spy text
hset $scobj_hpath/emon/errhandler "lazy"
helpNotes4user $scobj_hpath "emon" "errhandler"
hfactory $scobj_hpath/pwrCtrl/LSB_Err plain spy text
hset $scobj_hpath/pwrCtrl/LSB_Err "UNKNOWN"
helpNotes4user $scobj_hpath "pwrCtrl" "LSB_Err"
hfactory $scobj_hpath/pwrctrl/lsb_err plain spy text
hset $scobj_hpath/pwrctrl/lsb_err "UNKNOWN"
helpNotes4user $scobj_hpath "pwrctrl" "lsb_err"
hfactory $scobj_hpath/pwrCtrl/MSB_Err plain spy text
hset $scobj_hpath/pwrCtrl/MSB_Err "UNKNOWN"
helpNotes4user $scobj_hpath "pwrCtrl" "MSB_Err"
hfactory $scobj_hpath/pwrctrl/msb_err plain spy text
hset $scobj_hpath/pwrctrl/msb_err "UNKNOWN"
helpNotes4user $scobj_hpath "pwrctrl" "msb_err"
hfactory $scobj_hpath/pwrCtrl/PwrSupplyStatus plain spy text
hset $scobj_hpath/pwrCtrl/PwrSupplyStatus "UNKNOWN"
helpNotes4user $scobj_hpath "pwrCtrl" "PwrSupplyStatus"
hfactory $scobj_hpath/pwrctrl/pwr_supply_status plain spy text
hset $scobj_hpath/pwrctrl/pwr_supply_status "UNKNOWN"
helpNotes4user $scobj_hpath "pwrctrl" "pwr_supply_status"
hfactory $scobj_hpath/pwrCtrl/StateMachineStatus plain spy text
hset $scobj_hpath/pwrCtrl/StateMachineStatus "UNKNOWN"
helpNotes4user $scobj_hpath "pwrCtrl" "StateMachineStatus"
hfactory $scobj_hpath/pwrctrl/state_machine_status plain spy text
hset $scobj_hpath/pwrctrl/state_machine_status "UNKNOWN"
helpNotes4user $scobj_hpath "pwrctrl" "state_machine_status"
#hfactory $scobj_hpath/pwrCtrl/EthernetAddrDec plain user text
#hset $scobj_hpath/pwrCtrl/EthernetAddrDec "UNKNOWN"
#helpNotes4user $scobj_hpath "pwrCtrl" "EthernetAddrDec"
#hfactory $scobj_hpath/pwrctrl/EthernetAddrDec plain user text
#hset $scobj_hpath/pwrctrl/EthernetAddrDec "UNKNOWN"
#helpNotes4user $scobj_hpath "pwrctrl" "EthernetAddrDec"
hfactory $scobj_hpath/status plain spy text
hsetprop $scobj_hpath/status values busy,idle
@@ -1293,19 +1286,19 @@ proc mk_sct_bruker_BEC1 {sct_controller klass tempobj tol} {
# Note: node names longer than 8 characters cause eror messages - avoid
set nxProperties "
$scobj_hpath sensor NXsensor spy
$scobj_hpath sensor/MeasuredField sensor user
$scobj_hpath sensor/ActualDAC_Field sensor user
$scobj_hpath sensor/DesiredCurrent sensor user
$scobj_hpath sensor/NominalOutpCurrent sensor user
$scobj_hpath sensor/measured_field sensor user
$scobj_hpath sensor/actual_dac_field sensor user
$scobj_hpath sensor/desired_current sensor user
$scobj_hpath sensor/nominal_outp_current sensor user
"
set aliasProperties "
$scobj_hpath MeasuredField sensor _sensor_MeasuredField
$scobj_hpath ActualDAC_Field sensor _sensor_ActualDAC_Field
$scobj_hpath DesiredCurrent sensor _sensor_DesiredCurrent
$scobj_hpath NominalOutpCurrent sensor _sensor_NominalOutpCurrent
$scobj_hpath measured_field sensor _sensor_MeasuredField
$scobj_hpath actual_dac_field sensor _sensor_ActualDAC_Field
$scobj_hpath desired_current sensor _sensor_DesiredCurrent
$scobj_hpath nominal_outp_current sensor _sensor_NominalOutpCurrent
"
foreach {rootpath hpath klass priv} $nxProperties {
hsetprop $rootpath/$hpath klass $klass
foreach {rootpath hpath klasse priv} $nxProperties {
hsetprop $rootpath/$hpath klass $klasse
hsetprop $rootpath/$hpath privilege $priv
hsetprop $rootpath/$hpath control true
hsetprop $rootpath/$hpath data true
@@ -1324,21 +1317,23 @@ proc mk_sct_bruker_BEC1 {sct_controller klass tempobj tol} {
# for generating the GumTree interface and saving data for script context objects (hdf file)
# @param scobj, name of script context object (path to a node)
# @param par, optional parameter (name of the node variable)
::scobj::hinitprops $tempobj/sensor NominalOutpCurrent
::scobj::hinitprops $tempobj/sensor nominal_outp_current
hsetprop $scobj_hpath/pwrctrl/statusByte control false
ansto_makesctdrive ${tempobj}_driveable $scobj_hpath/sensor/DesiredCurrent $scobj_hpath/sensor/NominalOutpCurrent $sct_controller
ansto_makesctdrive ${tempobj}_driveable $scobj_hpath/sensor/desired_current $scobj_hpath/sensor/nominal_outp_current $sct_controller
# initialise the device
bruker_BEC1_init $sct_controller $scobj_hpath
puts "Bruker BEC1 power supply for 1-Tesla magnet ready at /sample/$tempobj (Driver 20091209)"
puts "Bruker BEC1 power supply for 1-Tesla magnet ready at /sample/$tempobj (Driver 2010-04-07)"
} message ]
handle_exception $catch_status $message "In subroutine mk_sct_bruker_BEC1()."
}
namespace export mk_sct_bruker_BEC1
# endproc mk_sct_bruker_BEC1 sct_controller klass tempobj tol bruker_BEC1_LSmodel
}
namespace export mk_sct_bruker_BEC1
# endproc mk_sct_bruker_BEC1 sct_controller klasse tempobj tol bruker_BEC1_LSmodel
}
# end of namespace mk_sct_bruker_BEC1
##
# @brief add_bruker_BEC1() adds a scriptcontext object for a Bruker BEC1 power supply (1T magnet)
# and makes it available to SICServer
@@ -1351,15 +1346,16 @@ proc add_bruker_BEC1 {name IP port {_tol 0.1} } {
# Don't create a magnet controller for the script validator, this may cause the
# the BEC1 to lock up.
# NOTE: This is placed outside the catch block because "return" raises an exception
if [SplitReply [environment_simulation]] {
if {[SplitReply [environment_simulation]]} {
return
}
set catch_status [ catch {
puts "\nadd_bruker_BEC1: makesctcontroller $name std ${IP}:$port for Bruker BEC1 1-Tesla magnet power supply"
# Command terminator for Bruker unit is only carriage return without linefeed '\r'
makesctcontroller sct_bruker_BEC1_$name std ${IP}:$port "\r"
puts "\nadd_bruker_BEC1: makesctcontroller $name astvelsel ${IP}:$port for Bruker BEC1 1-Tesla magnet power supply"
# Command terminator for Bruker unit is always carriage return without linefeed '\r'
makesctcontroller sct_bruker_BEC1_$name astvelsel ${IP}:$port "\r"
# proc mk_sct_bruker_BEC1 (sct_controller klasse tempobj tol)
mk_sct_bruker_BEC1 sct_bruker_BEC1_$name environment $name $_tol
makesctemon $name /sics/$name/emon/monMode /sics/$name/emon/isInTolerance /sics/$name/emon/errhandler
makesctemon $name /sics/$name/emon/mon_mode /sics/$name/emon/is_in_tolerance /sics/$name/emon/errhandler
} message ]
handle_exception $catch_status $message "In subroutine add_bruker_BEC1()."
}