version 20091201, not tested. Fixed drivestatus return values (insights from Lakeshore 336 driver) and removed obsolete line terminator code.

r2837 | axm | 2009-12-09 18:38:58 +1100 (Wed, 09 Dec 2009) | 2 lines
This commit is contained in:
Arndt Meiers
2009-12-09 18:38:58 +11:00
committed by Douglas Clowes
parent f4e26c7e08
commit 814fa32408

View File

@@ -13,7 +13,7 @@
# #
# @author: Arndt Meier, ANSTO, 2009-08-31 # @author: Arndt Meier, ANSTO, 2009-08-31
# @brief: driver for Bruker 1-Tesla magnet power supply (in TCL) # @brief: driver for Bruker 1-Tesla magnet power supply (in TCL)
# @version: 20091002 for sics2_4 # @version: 20091127 for sics2_4
# #
# known bugs: betaa stage - version 1.1.0 # known bugs: betaa stage - version 1.1.0
# ----------------------------------------------------------------------------*/ # ----------------------------------------------------------------------------*/
@@ -51,6 +51,11 @@
# did not have the expected effect so far. # did not have the expected effect so far.
# - Fixed the StateMachineStatusByteTxt bug - now decodes the # - Fixed the StateMachineStatusByteTxt bug - now decodes the
# status byte correctly into its corresponding error text. # status byte correctly into its corresponding error text.
# - Removed terminator variable - obsolete as this is done when the scriptcontext
# object is created.
# - 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.
# Default parameters for the device # Default parameters for the device
namespace eval ::scobj::bruker_BEC1 { namespace eval ::scobj::bruker_BEC1 {
@@ -69,7 +74,7 @@ namespace eval ::scobj::bruker_BEC1 {
# provide a global variable holding the path to the nodes # provide a global variable holding the path to the nodes
set bruker_BEC1_path2nodes "/sample/ma1" set bruker_BEC1_path2nodes "/sample/ma1"
# terminator string for serial communication # terminator string for serial communication
set bruker_BEC1_term "" #set bruker_BEC1_term "" !obsolete. Done in the call to the scriptcontext constructor
# variables that are identical to node names but are needed internally as well # variables that are identical to node names but are needed internally as well
# temperature tolerance in Ampere # temperature tolerance in Ampere
set bruker_BEC1_tolerance 0.1 set bruker_BEC1_tolerance 0.1
@@ -167,8 +172,8 @@ proc getValue {tc_root nextState cmd expectedLen} {
set tNow [clock clicks -milliseconds] set tNow [clock clicks -milliseconds]
} }
#set diff2 [expr $tNow - $::scobj::bruker_BEC1::bruker_BEC1_timeLastCommand] #set diff2 [expr $tNow - $::scobj::bruker_BEC1::bruker_BEC1_timeLastCommand]
sct send $cmd$::scobj::bruker_BEC1::bruker_BEC1_term sct send $cmd
# puts "sct send !$cmd$::scobj::bruker_BEC1::bruker_BEC1_term!" # puts "sct send !$cmd!"
set ::scobj::bruker_BEC1::bruker_BEC1_timeLastCommand $tNow set ::scobj::bruker_BEC1::bruker_BEC1_timeLastCommand $tNow
#puts "diff1:$diff1, diff2:$diff2 $cmd" #puts "diff1:$diff1, diff2:$diff2 $cmd"
} message ] { } message ] {
@@ -278,7 +283,7 @@ puts "Rejected !$data! as reply to $::scobj::bruker_BEC1::bruker_BEC1_lastQueryC
proc inTolerance {expectedLength} { proc inTolerance {expectedLength} {
set tc_root $::scobj::bruker_BEC1::bruker_BEC1_path2nodes set tc_root $::scobj::bruker_BEC1::bruker_BEC1_path2nodes
set data [sct result] set data [sct result]
# puts "inT result !$data!" #puts "inT result !$data!"
# Do we get the answer to the question we asked?! Occasionally the BEC1 is sending info on its own. # Do we get the answer to the question we asked?! Occasionally the BEC1 is sending info on its own.
if { 0 != [string compare -length 4 $data $::scobj::bruker_BEC1::bruker_BEC1_lastQueryCmd]} { if { 0 != [string compare -length 4 $data $::scobj::bruker_BEC1::bruker_BEC1_lastQueryCmd]} {
# Discard if it is not the reply to our query # Discard if it is not the reply to our query
@@ -298,7 +303,7 @@ proc inTolerance {expectedLength} {
# Discard - this it is not the reply to our query because this is what happened: # Discard - this it is not the reply to our query because this is what happened:
#ERROR: in rdValue: in analyseStatusByte(): in decodeErrByte(): syntax error in expression "0xHF": extra tokens at end of expression. errByte: HF, errList: 08 {Inrush procedure error} 01 {Current limit exceeded} #ERROR: in rdValue: in analyseStatusByte(): in decodeErrByte(): syntax error in expression "0xHF": extra tokens at end of expression. errByte: HF, errList: 08 {Inrush procedure error} 01 {Current limit exceeded}
# . statusByteString: STA/0CHF/-0.0002T. Last query command: STA/ # . statusByteString: STA/0CHF/-0.0002T. Last query command: STA/
puts "Rejected !$data! as reply to $::scobj::bruker_BEC1::bruker_BEC1_lastQueryCmd" #puts "Rejected !$data! as reply to $::scobj::bruker_BEC1::bruker_BEC1_lastQueryCmd"
return idle return idle
} }
set data [ExtractValue $data $::scobj::bruker_BEC1::bruker_BEC1_lastQueryCmd] set data [ExtractValue $data $::scobj::bruker_BEC1::bruker_BEC1_lastQueryCmd]
@@ -369,7 +374,7 @@ proc setValue {tc_root nextState cmd } {
while {[expr $tNow - $::scobj::bruker_BEC1::bruker_BEC1_timeLastCommand] < $::scobj::bruker_BEC1::bruker_BEC1_MIN_TIME_BETWEEN_COMMANDS} { while {[expr $tNow - $::scobj::bruker_BEC1::bruker_BEC1_timeLastCommand] < $::scobj::bruker_BEC1::bruker_BEC1_MIN_TIME_BETWEEN_COMMANDS} {
set tNow [clock clicks -milliseconds] set tNow [clock clicks -milliseconds]
} }
sct send "$cmd$par$::scobj::bruker_BEC1::bruker_BEC1_term" sct send "$cmd$par"
set ::scobj::bruker_BEC1::bruker_BEC1_timeLastCommand $tNow set ::scobj::bruker_BEC1::bruker_BEC1_timeLastCommand $tNow
if { 0 == [string compare -length 4 $cmd "RST=0"] } { if { 0 == [string compare -length 4 $cmd "RST=0"] } {
# Reset error messages - also update the node displaying the last error # Reset error messages - also update the node displaying the last error
@@ -414,13 +419,13 @@ proc setDesiredField {tc_root nextState cmd} {
set nodename $tc_root/sensor/setpoint set nodename $tc_root/sensor/setpoint
hsetprop $nodename driving 1 hsetprop $nodename driving 1
} }
#puts "setDesiredField(wrStatus=$wrStatus): sct send $cmd$par$::scobj::bruker_BEC1::bruker_BEC1_term" #puts "setDesiredField(wrStatus=$wrStatus): sct send $cmd$par"
set tNow [clock clicks -milliseconds] set tNow [clock clicks -milliseconds]
#set diff1 [expr $tNow - $::scobj::bruker_BEC1::bruker_BEC1_timeLastCommand] #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} { while {[expr $tNow - $::scobj::bruker_BEC1::bruker_BEC1_timeLastCommand] < $::scobj::bruker_BEC1::bruker_BEC1_MIN_TIME_BETWEEN_COMMANDS} {
set tNow [clock clicks -milliseconds] set tNow [clock clicks -milliseconds]
} }
sct send "$cmd$par$::scobj::bruker_BEC1::bruker_BEC1_term" sct send "$cmd$par"
} message ] { } message ] {
return -code error "in setDesiredField: $message. Last write command: $::scobj::bruker_BEC1::bruker_BEC1_lastWriteCmd" return -code error "in setDesiredField: $message. Last write command: $::scobj::bruker_BEC1::bruker_BEC1_lastWriteCmd"
} }
@@ -448,13 +453,13 @@ proc setDesiredCurrent {tc_root nextState cmd} {
set nodename $tc_root/sensor/NominalOutpCurrent set nodename $tc_root/sensor/NominalOutpCurrent
hsetprop $nodename driving 1 hsetprop $nodename driving 1
} }
#puts "setDesiredCurrent(wrStatus=$wrStatus): sct send $cmd$par$::scobj::bruker_BEC1::bruker_BEC1_term" #puts "setDesiredCurrent(wrStatus=$wrStatus): sct send $cmd$par"
set tNow [clock clicks -milliseconds] set tNow [clock clicks -milliseconds]
#set diff1 [expr $tNow - $::scobj::bruker_BEC1::bruker_BEC1_timeLastCommand] #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} { while {[expr $tNow - $::scobj::bruker_BEC1::bruker_BEC1_timeLastCommand] < $::scobj::bruker_BEC1::bruker_BEC1_MIN_TIME_BETWEEN_COMMANDS} {
set tNow [clock clicks -milliseconds] set tNow [clock clicks -milliseconds]
} }
sct send "$cmd$par$::scobj::bruker_BEC1::bruker_BEC1_term" sct send "$cmd$par"
set ::scobj::bruker_BEC1::bruker_BEC1_timeLastCommand $tNow set ::scobj::bruker_BEC1::bruker_BEC1_timeLastCommand $tNow
} message ] { } message ] {
return -code error "in setDesiredCurrent: $message. Last write command: $::scobj::bruker_BEC1::bruker_BEC1_lastWriteCmd" return -code error "in setDesiredCurrent: $message. Last write command: $::scobj::bruker_BEC1::bruker_BEC1_lastWriteCmd"
@@ -472,14 +477,15 @@ proc setDesiredCurrent {tc_root nextState cmd} {
# only call this when writestatus!="start" # only call this when writestatus!="start"
proc drivestatus {tc_root} { proc drivestatus {tc_root} {
if [ catch { if [ catch {
if [sct driving] { if [sct driving] {
return busy set retval busy
} else { } else {
return idle set retval idle
} }
} message ] { } message ] {
return -code error "in drivestatus: $message. Last write command: $::scobj::bruker_BEC1::bruker_BEC1_lastWriteCmd" return -code error "in drivestatus: $message. Last write command: $::scobj::bruker_BEC1::bruker_BEC1_lastWriteCmd"
} }
return $retval
} }
## ##
@@ -1122,11 +1128,9 @@ proc mk_sct_bruker_BEC1 {sct_controller klass tempobj tol} {
set ::scobj::bruker_BEC1::bruker_BEC1_sct_obj_name $tempobj set ::scobj::bruker_BEC1::bruker_BEC1_sct_obj_name $tempobj
# terminator string for serial communication # terminator string for serial communication
set CR "\r" #set CR "\r"
set LF "\n" #set LF "\n"
#set ::scobj::bruker_BEC1::bruker_BEC1_term $CR
set ::scobj::bruker_BEC1::bruker_BEC1_term ""
set ::scobj::bruker_BEC1::bruker_BEC1_tolerance $tol 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]
@@ -1227,7 +1231,7 @@ proc mk_sct_bruker_BEC1 {sct_controller klass tempobj tol} {
helpNotes4user $scobj_hpath "emon" "monMode" helpNotes4user $scobj_hpath "emon" "monMode"
hfactory $scobj_hpath/emon/errhandler plain spy text hfactory $scobj_hpath/emon/errhandler plain spy text
hset $scobj_hpath/emon/errhandler "pause" hset $scobj_hpath/emon/errhandler "lazy"
helpNotes4user $scobj_hpath "emon" "errhandler" helpNotes4user $scobj_hpath "emon" "errhandler"
hfactory $scobj_hpath/pwrCtrl/LSB_Err plain spy text hfactory $scobj_hpath/pwrCtrl/LSB_Err plain spy text
@@ -1299,7 +1303,7 @@ proc mk_sct_bruker_BEC1 {sct_controller klass tempobj tol} {
# initialise the device # initialise the device
bruker_BEC1_init $sct_controller $scobj_hpath bruker_BEC1_init $sct_controller $scobj_hpath
puts "Bruker BEC1 power supply for 1-Tesla magnet ready at /sample/$tempobj (Driver 20091002_beta)" puts "Bruker BEC1 power supply for 1-Tesla magnet ready at /sample/$tempobj (Driver 20091127)"
} message ] { } message ] {
return -code error "in mk_sct_bruker_BEC1 $message" return -code error "in mk_sct_bruker_BEC1 $message"
} }
@@ -1318,8 +1322,15 @@ proc mk_sct_bruker_BEC1 {sct_controller klass tempobj tol} {
# @param tol magnetic field strength tolerance in Tesla (default 0.1T) # @param tol magnetic field strength tolerance in Tesla (default 0.1T)
# @return nothing (well, the sct object) # @return nothing (well, the sct object)
proc add_bruker_BEC1 {name IP port {_tol 0.1} } { 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]] {
return
}
if [ catch { if [ catch {
puts "\nadd_bruker_BEC1: makesctcontroller $name std ${IP}:$port for Bruker BEC1 1-Tesla magnet power supply" 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" makesctcontroller sct_bruker_BEC1_$name std ${IP}:$port "\r"
mk_sct_bruker_BEC1 sct_bruker_BEC1_$name environment $name $_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/monMode /sics/$name/emon/isInTolerance /sics/$name/emon/errhandler