Change puts to clientput to avoid error on stdout undefined

This commit is contained in:
Douglas Clowes
2014-06-30 13:44:14 +10:00
parent 202004766a
commit 7960cb73a0
7 changed files with 276 additions and 232 deletions

View File

@@ -165,34 +165,34 @@ proc bruker_BEC1_init {sct_controller tc_root} {
set catch_status [ catch {
# set the communication protocol: terminator <CR>, bps 9600 baud, 7 data bits +
# 1 stop bit + odd parity bit
# puts "setting serial communication parameters"
# clientput "setting serial communication parameters"
# hset $tc_root/other/cfgProtocol_comm "COMM 1,5,1"
# Query the device ID
# puts "sending: $sct_controller queue $tc_root/other/deviceID_idn progress read"
# clientput "sending: $sct_controller queue $tc_root/other/deviceID_idn progress read"
# $sct_controller queue $tc_root/other/deviceID_idn progress read
# !! Not working properly yet - needs fixing
#sct send "*IDN?"
#sct data [$sct_controller result]
#puts "rdValDrct(): result is $data"
#clientput "rdValDrct(): result is $data"
#set data [hget $tc_root/other/deviceID_idn]
# puts "set deviceID_idn (hval $tc_root/other/deviceID_idn)"
# clientput "set deviceID_idn (hval $tc_root/other/deviceID_idn)"
#set data [hval $tc_root/other/deviceID_idn]
#set ::scobj::bruker_BEC1::this_sDeviceID data
# puts "sct_bruker_BEC1.tcl: connected to device $::scobj::bruker_BEC1::this_sDeviceID"
# clientput "sct_bruker_BEC1.tcl: connected to device $::scobj::bruker_BEC1::this_sDeviceID"
# reset the device to have it in a defined state
# hset $tc_root/other/reset_rst {*RST}
# Queue the Read Device Status-byte command so we can access the result in the
# corresponding node later
# puts "sending: $sct_controller queue $tc_root/other/statusByte progress read"
# clientput "sending: $sct_controller queue $tc_root/other/statusByte progress read"
# $sct_controller queue $tc_root/other/statusByte progress read
# hset $tc_root/other/cfgProtocol_comm "COMM 1,5,1"
# Was the self-test successful?
# $sct_controller queue $tc_root/other/selftest progress read
# set ::scobj::bruker_BEC1::this_selfTestResult [hval $tc_root/other/selftest]
# if {$::scobj::bruker_BEC1::this_selfTestResult == 0} {
# puts "sct_bruker_BEC1.tcl: Lakeshore $::scobj::bruker_BEC1::bruker_BEC1_LSmodel self-test ok."
# clientput "sct_bruker_BEC1.tcl: Lakeshore $::scobj::bruker_BEC1::bruker_BEC1_LSmodel self-test ok."
# } else {
# puts "sct_bruker_BEC1.tcl: The Lakeshore $::scobj::bruker_BEC1::bruker_BEC1_LSmodel failed its self-test."
# clientput "sct_bruker_BEC1.tcl: The Lakeshore $::scobj::bruker_BEC1::bruker_BEC1_LSmodel failed its self-test."
# }
# Set the default tolerances for the setpoint magentic field strength
hset $tc_root/emon/tolerance $::scobj::bruker_BEC1::bruker_BEC1_tolerance
@@ -221,7 +221,7 @@ proc getValue {tc_root nextState cmd expectedLen} {
}
after $::scobj::bruker_BEC1::bruker_BEC1_MIN_TIME_BETWEEN_COMMANDS
sct send $cmd
# puts "sct send !$cmd!"
# clientput "sct send !$cmd!"
return $nextState
} message ]
handle_exception $catch_status $message "in getValue(). Last query command: $::scobj::bruker_BEC1::bruker_BEC1_lastQueryCmd"
@@ -236,9 +236,9 @@ proc getValue {tc_root nextState cmd expectedLen} {
# @return idle Always returns system state idle - command sequence completed.
proc rdValue {expectedLength} {
set data [sct result]
# puts "rdValue(): result is $data"
# clientput "rdValue(): result is $data"
# broadcast rdValue "rdValue(): result is $data"
#puts "sct result !$data!"
#clientput "sct result !$data!"
set rData $data
# 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]} {
@@ -249,7 +249,7 @@ proc getValue {tc_root nextState cmd expectedLen} {
# Continue as normal
switch -glob -- $data {
"ASCERR:*" {
puts "ASCERR in rdValue: Last query command: $::scobj::bruker_BEC1::bruker_BEC1_lastQueryCmd"
clientput "ASCERR in rdValue: Last query command: $::scobj::bruker_BEC1::bruker_BEC1_lastQueryCmd"
sct geterror $data
}
default {
@@ -258,7 +258,7 @@ proc getValue {tc_root nextState cmd expectedLen} {
#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/
return idle
#puts "Rejected !$data! as reply to $::scobj::bruker_BEC1::bruker_BEC1_lastQueryCmd"
#clientput "Rejected !$data! as reply to $::scobj::bruker_BEC1::bruker_BEC1_lastQueryCmd"
}
set orgdata $data
set data [ExtractValue $data $::scobj::bruker_BEC1::bruker_BEC1_lastQueryCmd]
@@ -285,7 +285,7 @@ proc getValue {tc_root nextState cmd expectedLen} {
# we have to extract again without stripping trailing characters that
# normally represent a physical unit like Ampere but could here be part
# of a hexadecimal value
#puts "rdValue: Interpreting status byte information: $orgdata $::scobj::bruker_BEC1::bruker_BEC1_lastQueryCmd"
#clientput "rdValue: Interpreting status byte information: $orgdata $::scobj::bruker_BEC1::bruker_BEC1_lastQueryCmd"
# Ananlyse the status bytes string containing the 4 status bytes and present the
# result in human readable form (Text instead of hex number)
analyseStatusByte $rData
@@ -301,7 +301,7 @@ proc getValue {tc_root nextState cmd expectedLen} {
# of a hexadecimal value
# Beware that Bruker uses reverse notation.
set data [ExtractValue $orgdata $::scobj::bruker_BEC1::bruker_BEC1_lastQueryCmd]
#puts "rdValue: Interpreting status byte information: $::scobj::bruker_BEC1::bruker_BEC1_lastQueryCmd"
#clientput "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"
}
@@ -327,7 +327,7 @@ proc getValue {tc_root nextState cmd expectedLen} {
proc inTolerance {expectedLength} {
set tc_root $::scobj::bruker_BEC1::bruker_BEC1_path2nodes
set data [sct result]
# puts "inT result !$data!"
# clientput "inT result !$data!"
# 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]} {
# Discard if it is not the reply to our query
@@ -335,10 +335,10 @@ proc inTolerance {expectedLength} {
}
set catch_status [ catch {
set oldvalue [sct oldval]
# puts "inTolerance(): data=$data oldval=$oldvalue"
# clientput "inTolerance(): data=$data oldval=$oldvalue"
switch -glob -- $data {
"ASCERR:*" {
puts "ASCERR in inTolerance: Last query command: $::scobj::bruker_BEC1::bruker_BEC1_lastQueryCmd"
clientput "ASCERR in inTolerance: Last query command: $::scobj::bruker_BEC1::bruker_BEC1_lastQueryCmd"
sct geterror $data
}
default {
@@ -347,7 +347,7 @@ proc inTolerance {expectedLength} {
# 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}
# . statusByteString: STA/0CHF/-0.0002T. Last query command: STA/
#puts "Rejected !$data! as reply to $::scobj::bruker_BEC1::bruker_BEC1_lastQueryCmd"
#clientput "Rejected !$data! as reply to $::scobj::bruker_BEC1::bruker_BEC1_lastQueryCmd"
return idle
}
set data [ExtractValue $data $::scobj::bruker_BEC1::bruker_BEC1_lastQueryCmd]
@@ -361,7 +361,7 @@ proc inTolerance {expectedLength} {
}
}
}
# puts "inTolerance $::scobj::bruker_BEC1::bruker_BEC1_sct_obj_name data:$data"
# clientput "inTolerance $::scobj::bruker_BEC1::bruker_BEC1_sct_obj_name data:$data"
# now update the manual nodes reporting whether the actual field strength
# is within tolerance of the corresponding setpoint
if {$data == 0 } {
@@ -376,7 +376,7 @@ proc inTolerance {expectedLength} {
set setpt [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"
# clientput "inTolerance(): comparing sensor/setpoint=$setpt with actual sensorValue=$temp"
set diff [expr {abs($setpt - $NominalOutpCurrent)}]
if {$diff > $::scobj::bruker_BEC1::bruker_BEC1_driveTolerance} {
# ERROR: node /sics/ma1/emon/mon_mode not found. Last query command: DCP/
@@ -391,11 +391,11 @@ proc inTolerance {expectedLength} {
hset $tc_root/status "idle"
}
}
# puts "inTolerance 4 $::scobj::bruker_BEC1::bruker_BEC1_sct_obj_name data:$data"
# clientput "inTolerance 4 $::scobj::bruker_BEC1::bruker_BEC1_sct_obj_name data:$data"
return idle
} message ]
handle_exception $catch_status $message "in inTolerance(). Last query command: $::scobj::bruker_BEC1::bruker_BEC1_lastQueryCmd"
# puts "Leaving inTolerance idx:$CtrlLoopIdx"
# clientput "Leaving inTolerance idx:$CtrlLoopIdx"
}
@@ -445,7 +445,7 @@ proc noResponse {} {
# @return nextState
proc setDesiredField {tc_root nextState cmd} {
set catch_status [ catch {
#puts "executing setDesiredField ($tc_root $nextState $cmd)"
#clientput "executing setDesiredField ($tc_root $nextState $cmd)"
set ns ::scobj::lh45
set par [sct target]
@@ -453,11 +453,11 @@ proc setDesiredField {tc_root nextState cmd} {
set wrStatus [sct writestatus]
if {$wrStatus == "start"} {
# Called by drive adapter
# puts "setDesiredField(): driving set to 1"
# clientput "setDesiredField(): driving set to 1"
set nodename $tc_root/sensor/setpoint
hsetprop $nodename driving 1
}
#puts "setDesiredField(wrStatus=$wrStatus): sct send $cmd$par"
#clientput "setDesiredField(wrStatus=$wrStatus): sct send $cmd$par"
after $::scobj::bruker_BEC1::bruker_BEC1_MIN_TIME_BETWEEN_COMMANDS
sct send "$cmd$par"
return $nextState
@@ -474,7 +474,7 @@ proc setDesiredField {tc_root nextState cmd} {
# @return nextState
proc setDesiredCurrent {tc_root nextState cmd} {
set catch_status [ catch {
# puts "executing setDesiredCurrent ($tc_root $nextState $cmd)"
# clientput "executing setDesiredCurrent ($tc_root $nextState $cmd)"
set ns ::scobj::lh45
set par [sct target]
@@ -482,11 +482,11 @@ proc setDesiredCurrent {tc_root nextState cmd} {
set wrStatus [sct writestatus]
if {$wrStatus == "start"} {
# Called by drive adapter
# puts "setDesiredCurrent(): driving set to 1"
# clientput "setDesiredCurrent(): driving set to 1"
set nodename $tc_root/sensor/nominal_outp_current
hsetprop $nodename driving 1
}
#puts "setDesiredCurrent(wrStatus=$wrStatus): sct send $cmd$par"
#clientput "setDesiredCurrent(wrStatus=$wrStatus): sct send $cmd$par"
after $::scobj::bruker_BEC1::bruker_BEC1_MIN_TIME_BETWEEN_COMMANDS
sct send "$cmd$par"
return $nextState
@@ -579,7 +579,7 @@ proc ExtractValue {response lastQueryCmd} {
# || $::scobj::bruker_BEC1::bruker_BEC1_polarityUnitAbsent == false} {
#}
}
#puts "ExtractValue(): response:$response, extractedValue:$extractedValue"
#clientput "ExtractValue(): response:$response, extractedValue:$extractedValue"
return $extractedValue
} message ]
handle_exception $catch_status $message "in ExtractValue(). Last device response: $response"
@@ -652,18 +652,18 @@ proc ExtractValue {response lastQueryCmd} {
proc decodeErrByte {errByte errList} {
set errorText ""
set delim ", "
#puts "decodeErrByte: errByte:$errByte"
#clientput "decodeErrByte: errByte:$errByte"
set catch_status [ catch {
# convert to decimal for calculations
set hexvar "0x$errByte"
set decErrByte [expr {$hexvar}]
# puts "errByte=$errByte, hexvar=$hexvar, decErrByte=$decErrByte"
# clientput "errByte=$errByte, hexvar=$hexvar, decErrByte=$decErrByte"
foreach {hexVal errText} $errList {
#puts "errByte:$errByte hexVal:$hexVal errText:$errText"
#clientput "errByte:$errByte hexVal:$hexVal errText:$errText"
# convert to decimal for calculations
set hexvar "0x$hexVal"
set decVal [expr { $hexvar }]
#puts "decErrByte:$decErrByte decVal:$decVal errText:$errText"
#clientput "decErrByte:$decErrByte decVal:$decVal errText:$errText"
if { $decErrByte >= $decVal } {
if {[string length $errorText] > 1} {
set errorText "$errorText$delim$errText"
@@ -696,7 +696,7 @@ proc extractStatusByte {statusByteString whichByte} {
# allow for an initial offset of 4 char for 'STA/'
incr offset 4
set statusByte [string range $statusByteString $offset [expr {$offset+1}]]
#puts "ExtractValue(): response:$response, extractedValue:$extractedValue"
#clientput "ExtractValue(): response:$response, extractedValue:$extractedValue"
return $statusByte
} message ]
handle_exception $catch_status $message "in extractStatusByte(). statusByteString: $statusByteString, whichByte: $whichByte"
@@ -708,7 +708,7 @@ proc analyseStatusByte {statusByteString} {
# A typical argument may look like this:
# "STA/0000C100"
set catch_status [ catch {
#puts "statusByteString:$statusByteString"
#clientput "statusByteString:$statusByteString"
set LSB_ErrByteTxt "Ok"
set MSB_ErrByteTxt "Ok"
set PwrSupplyStatusByteTxt "Ok"
@@ -781,10 +781,10 @@ proc analyseStatusByte {statusByteString} {
#00 {Neutral state}
set StateMachineStatusByteTxt [decodeErrByte $tmp_StateMachineStatusByte $errList]
}
#puts "LSB_ErrByte :x$tmp_LSB_ErrByte: $LSB_ErrByteTxt"
#puts "MSB_ErrByte :x$tmp_MSB_ErrByte: $MSB_ErrByteTxt"
#puts "pwr_supply_status:x$tmp_PwrSupplyStatusByte: $PwrSupplyStatusByteTxt"
#puts "StateMachine :x$tmp_StateMachineStatusByte: $StateMachineStatusTxt"
#clientput "LSB_ErrByte :x$tmp_LSB_ErrByte: $LSB_ErrByteTxt"
#clientput "MSB_ErrByte :x$tmp_MSB_ErrByte: $MSB_ErrByteTxt"
#clientput "pwr_supply_status:x$tmp_PwrSupplyStatusByte: $PwrSupplyStatusByteTxt"
#clientput "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"
@@ -804,7 +804,7 @@ proc analyseStatusByte {statusByteString} {
# @param separator String holding the separator used in $s, e.g. a coma
# @return returnval String holding the extracted element. String is empty if operation failed.
proc getValFromString {s element separator} {
#puts "getValFromString $s $element $separator"
#clientput "getValFromString $s $element $separator"
set startIdx 0
set endIdx 0
set eIdx $element
@@ -829,7 +829,7 @@ proc getValFromString {s element separator} {
}
set endIdx [string first $separator $s $startIdx]
incr endIdx -1
#puts "startIdx=$startIdx endIdx=$endIdx"
#clientput "startIdx=$startIdx endIdx=$endIdx"
# endIdx points to one character before the next separator or is -1 if it is the
# last element in the string $s
if {$endIdx >= 0} {
@@ -837,7 +837,7 @@ proc getValFromString {s element separator} {
} else {
set returnval [string range $s $startIdx 555]
}
#puts "getValFromString $s, $element, $separator,\n returns: $returnval"
#clientput "getValFromString $s, $element, $separator,\n returns: $returnval"
return $returnval
}
@@ -920,7 +920,7 @@ proc helpNotes4user {scobj_hpath cmdGroup varName} {
set nodeName "$scobj_hpath/$varName"
}
set helptext "No help available"
#puts "helpNotes4user $scobj_hpath/$cmdGroup varName"
#clientput "helpNotes4user $scobj_hpath/$cmdGroup varName"
switch -glob $varName {
"local_remote_state*" {
set h1 {REM: «n» Query or Set local/remote state.}
@@ -1057,11 +1057,11 @@ proc helpNotes4user {scobj_hpath cmdGroup varName} {
}
default {
set helptext {Sorry mate. No help available.}
puts "No help info available for node $varName"
clientput "No help info available for node $varName"
}
}
#set sLen [string bytelength $helptext]
#puts "helptext ($sLen bytes) $helptext"
#clientput "helptext ($sLen bytes) $helptext"
hsetprop $nodeName help $helptext
} message ]
handle_exception $catch_status $message "in helpNotes4user(). varName=$varName."
@@ -1088,7 +1088,7 @@ proc helpNotes4user {scobj_hpath cmdGroup varName} {
# @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 klasse} {
#puts "createing node for: $scobj_hpath $cmdGroup $varName $readable $writable $pollEnabled $drivable $dataType $permission $rdCmd $rdFunc $wrCmd $wrFunc"
#clientput "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
set nodeName "$scobj_hpath/$cmdGroup/$varName"
@@ -1100,7 +1100,7 @@ proc createNode {scobj_hpath sct_controller cmdGroup varName readable writable p
hsetprop $nodeName read ${ns}::getValue $scobj_hpath $rdFunc $rdCmd $replyLen
}
if {$pollEnabled == 1} {
# puts "enabling polling for $nodeName"
# clientput "enabling polling for $nodeName"
$sct_controller poll $nodeName
}
hsetprop $nodeName $rdFunc ${ns}::$rdFunc $replyLen
@@ -1330,7 +1330,7 @@ proc mk_sct_bruker_BEC1 {sct_controller klasse tempobj tol CID CTYPE} {
# initialise the device
bruker_BEC1_init $sct_controller $scobj_hpath
puts "Bruker BEC1 power supply for 1-Tesla magnet ready at /sample/$tempobj (Driver 2010-06-25)"
clientput "Bruker BEC1 power supply for 1-Tesla magnet ready at /sample/$tempobj (Driver 2010-06-25)"
} message ]
handle_exception $catch_status $message "In subroutine mk_sct_bruker_BEC1()."
}
@@ -1356,7 +1356,7 @@ proc add_bruker_BEC1 {name IP port {_tol 0.1} {CID 1} {CTYPE B} } {
return
}
set catch_status [ catch {
puts "\nadd_bruker_BEC1: makesctcontroller $name astvelsel ${IP}:$port for Bruker BEC1 1-Tesla magnet power supply"
clientput "\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)
@@ -1383,7 +1383,7 @@ if {[ catch {
}
}
} message ]} {
puts "ERROR: $message"
clientput "ERROR: $message"
}
namespace import ::scobj::bruker_BEC1::*