update formats of displayed strings

r3766 | jgn | 2012-10-15 12:01:50 +1100 (Mon, 15 Oct 2012) | 1 line
This commit is contained in:
Jing Chen
2012-10-15 12:01:50 +11:00
committed by Douglas Clowes
parent c85cd9f081
commit 935a45cbf5

View File

@@ -32,16 +32,41 @@ proc debug_log {args} {
namespace eval ::scobj::magnetic {
}
proc ::scobj::magnetic::setting {} {
set newField [sct target]
set comm "setF $newField\r\n"
proc ::scobj::magnetic::setting {field basePath} {
set fieldVal [sct target]
switch -exact $field {
"field" {set comm "setF $fieldVal\r\n"
hset $basePath/fieldSetPoint $fieldVal
}
"rate" {set comm "setR $fieldVal\r\n"
hset $basePath/fieldSetRate $fieldVal
}
"DiluxTemp" {set comm "setDilutTemp $fieldVal\r\n"
hset $basePath/DilutTempSetPoint $fieldVal
}
"HelioxTemp" {set comm "setHelioxTemp $fieldVal\r\n"
hset $basePath/HelioxTempSetPoint $fieldVal
}
"HeaterS" {if {[string equal [string toupper $fieldVal] "ON"]!=1 && [string equal [string toupper $fieldVal] "OFF"]!=1} {
error "Error commmand, the corrent command should be : OxfordSetHS ON/OFF"
return idle
} else {
set comm "setHS [string toupper $fieldVal]\r\n"
broadcast "Wait 60 seconds for the operation to complete before reset the mode"
}
}
default {error "ERROR: illegal input command, check and input again!"
return idle
}
}
sct send $comm
return checkReply
}
proc ::scobj::magnetic::checkReplyFunc {basePath} {
# set replyStr [sct result]
set replyStr [sct result]
#analysis the reply from the Oxford Device
# if {[string first "Error" $replyStr] != -1} {
# broadcast "Error: Oxford Device cannot set the new target value, check again!!"
@@ -79,7 +104,6 @@ proc ::scobj::magnetic::rdTempSetPointStateFunc {basePath} {
sct update $replyStr
sct utime readtime
}
return idle
}
@@ -94,6 +118,7 @@ proc ::scobj::magnetic::rqFieldFunc {} {
# @brief Read and record the Magnetific Field value from the Oxford Device
proc ::scobj::magnetic::rdFieldStateFunc {basePath} {
set replyStr [sct result]
debug_log $replyStr
#broadcast "getF reply: $replyStr"
if {[string first "Error" $replyStr] != -1} {
broadcast "Error: cannot get the Magnetific Field value from the Oxford Labview server, check again!"
@@ -102,8 +127,12 @@ proc ::scobj::magnetic::rdFieldStateFunc {basePath} {
} elseif {[string first "read timeout" $replyStr] != -1} {
broadcast "Error: read timeout on the connectiion to the Oxford Labview server"
} else {
debug_log "Magnetic Current: $replyStr"
hset $basePath/magneticField $replyStr
#debug_log $replyStr
set s1 [string trimright $replyStr "\n"]
set s2 [split $s1 "=;"]
array set paraArr $s2
hset $basePath/magneticFieldCurernt $paraArr(Field_Current)
hset $basePath/magneticFieldTesla $paraArr(Field_Tesla)
}
if {$replyStr != [sct oldval]} {
@@ -111,41 +140,80 @@ proc ::scobj::magnetic::rdFieldStateFunc {basePath} {
sct update $replyStr
sct utime readtime
}
return idle
}
# @brief Request a state report from the Oxford Device by sending a Magnetic Temperature request command
proc ::scobj::magnetic::rqTempFunc {} {
set comm "getT\r\n"
proc ::scobj::magnetic::rqTempFunc {field} {
switch -exact $field {
"sample" {set comm "getT\r\n"}
"Heliox" {set comm "getHelioxTemp\r\n"}
"Dilut" {set comm "getDilutionTemp\r\n"}
default {error "ERROR: illegal input command, check and input again!"
return idle
}
}
sct send $comm
return rdTempState
}
##
# @brief Read and record the Magnetific Temperature value from the Oxford Device
proc ::scobj::magnetic::rdTempStateFunc {basePath} {
proc ::scobj::magnetic::rdTempStateFunc {basePath field} {
set replyStr [sct result]
debug_log $replyStr
#broadcast "getT reply:$replyStr\n"
#broadcast "Temp : @$replyStr@"
set curVal $replyStr
if {[string first "Error" $replyStr] != -1} {
broadcast "Error: cannot get the Magnetific Temperature value from the Oxford Labview server, check again!"
debug_log $replyStr
error "Error: cannot get the Magnetific Temperature value from the Oxford Labview server, check again!"
} elseif {[string first "failed" $replyStr] != -1} {
broadcast "Error: Connection to Oxford Labview server failed, check connection!"
debug_log $replyStr
error "Error: Connection to Oxford Labview server failed, check connection!"
} elseif {[string first "read timeout" $replyStr] != -1} {
broadcast "Error: read timeout on the connectiion to the Oxford Labview server"
debug_log $replyStr
error "Error: read timeout on the connectiion to the Oxford Labview server"
} else {
set s1 [string trimright $replyStr "\n"]
set s2 [split $s1 "=;"]
array set paraArr $s2
hset $basePath/Temp_s1 $paraArr(T1)
hset $basePath/Temp_s2 $paraArr(T2)
hset $basePath/Temp_s3 $paraArr(T3)
switch -exact $field {
"sample" {set s1 [string trimright $replyStr "\n"]
set s2 [split $s1 "=;"]
array set paraArr $s2
hset $basePath/Temp_s1 $paraArr(T1)
hset $basePath/Temp_s2 $paraArr(T2)
hset $basePath/Temp_s3 $paraArr(T3)
set logText "Displayed Temp : $paraArr(T1) $paraArr(T2) $paraArr(T3)"
}
"Heliox" {set s1 [string trimright $replyStr "\n"]
set s1 [string trimright $s1 "Cdeg"]
set s2 [split $s1 "=;"]
array set paraArr $s2
hset $basePath/HelioxTempReading $paraArr(Temp)
hset $basePath/HelioxTempSetPoint $paraArr(SetPoint)
set curVal $paraArr(Temp)
set logText "Heliox Temp : $paraArr(Temp)"
}
"Dilut" {set s1 [string trimright $replyStr "\n"]
set s2 [split $s1 "=;"]
array set paraArr $s2
hset $basePath/DilutTempReading $paraArr(Temp)
hset $basePath/DilutTempSetPoint $paraArr(SetPoint)
set curVal $paraArr(Temp)
set logText "Dilut Temp : $paraArr(Temp)"
}
default {error "ERROR: illegal input field in rdTempStateFunc, check the input field!"
return idle
}
}
debug_log $logText
}
if {$replyStr != [sct oldval]} {
sct oldval $replyStr
sct update $replyStr
if {$curVal != [sct oldval]} {
sct oldval $curVal
sct update $curVal
sct utime readtime
}
@@ -176,13 +244,14 @@ proc ::scobj::magnetic::mkMagnetic {argList} {
set hPath /sics/$pa(NAME)
hfactory $hPath/field plain user float
hfactory $hPath/magneticField plain user float
hfactory $hPath/field plain user text
hfactory $hPath/magneticFieldCurernt plain user float
hfactory $hPath/magneticFieldTesla plain user float
hfactory $hPath/start_magnetic plain user float
hfactory $hPath/end_magnetic plain user float
hfactory $hPath/Temp plain user float
hfactory $hPath/Temp plain user text
hfactory $hPath/Temp_s1 plain user float
hfactory $hPath/Temp_s2 plain user float
hfactory $hPath/Temp_s3 plain user float
@@ -197,23 +266,35 @@ proc ::scobj::magnetic::mkMagnetic {argList} {
hfactory $hPath/end_temperature_s3 plain user float
# Setting Magnetic field
hfactory $hPath/setPoint plain user float
hfactory $hPath/setRate plain user float
hfactory $hPath/fieldSetPoint plain user float
hfactory $hPath/fieldSetRate plain user float
# Setting Temperature & initiate
hfactory $hPath/TempSetTarget plain user float
hfactory $hPath/TempSetPoint plain user float
# this three values will be upadted immediately by the current readings in the system
hset $hPath/magneticFieldCurernt 10
hset $hPath/magneticFieldTesla 10
hset $hPath/fieldSetPoint 0
hset $hPath/magneticField 0
hset $hPath/setPoint 0
# Setting Heliox Temperature & initiate
hfactory $hPath/HelioxTempSetPoint plain user float
# This feature needs to implement the Labview code to get current reading of the Heliox tempterature
hfactory $hPath/HelioxTempReading plain user float
hset $hPath/TempSetTarget 0
hset $hPath/TempSetPoint 0
hset $hPath/HelioxTempSetPoint 0
hset $hPath/HelioxTempReading 0
hsetprop $hPath oldval UNKNOWN
hsetprop $hPath/Temp oldval UNKNOWN
hsetprop $hPath/field oldval UNKNOWN
# Setting Dilution Sample Temperature & initiate
hfactory $hPath/DilutTempSetPoint plain user float
hfactory $hPath/DilutTempReading plain user float
hset $hPath/DilutTempSetPoint 0
hset $hPath/DilutTempReading 0
hsetprop $hPath oldval UNKNOWN
hsetprop $hPath/Temp oldval UNKNOWN
hsetprop $hPath/field oldval UNKNOWN
hsetprop $hPath/HelioxTempReading oldval UNKNOWN
hsetprop $hPath/DilutTempReading oldval UNKNOWN
# add HDB file
hsetprop $hPath klass environment
hsetprop $hPath privilege spy
@@ -221,11 +302,14 @@ proc ::scobj::magnetic::mkMagnetic {argList} {
hsetprop $hPath control true
hsetprop $hPath data true
foreach {hdbPath klass control data nxsave mutable priv alias} {
/sics/magnetic/Temp_s1 NXsensor true true true true user magnetic_T1
/sics/magnetic/Temp_s2 NXsensor true true true true user magnetic_T2
/sics/magnetic/Temp_s3 NXsensor true true true true user magnetic_T3
/sics/magnetic/magneticField NXsensor true true true true user magnetic_Field
foreach {hdbPath klass control data nxsave mutable priv alias} {
/sics/magnetic/Temp_s1 NXsensor true true true true user magnetic_T1
/sics/magnetic/Temp_s2 NXsensor true true true true user magnetic_T2
/sics/magnetic/Temp_s3 NXsensor true true true true user magnetic_T3
/sics/magnetic/magneticFieldCurernt NXsensor true true true true user magnetic_Field_Current
/sics/magnetic/magneticFieldTesla NXsensor true true true true user magnetic_Field_Tesla
/sics/magnetic/HelioxTempReading NXsensor true true true true user magnetic_Heliox_Temp
/sics/magnetic/DilutTempReading NXsensor true true true true user magnetic_Dilut_Temp
} {
hsetprop $hdbPath nxalias $alias
hsetprop $hdbPath klass $klass
@@ -241,7 +325,7 @@ proc ::scobj::magnetic::mkMagnetic {argList} {
::scobj::hinitprops $pa(NAME)
# proc ::histogram_memory::pre_count "{fPath $pa(NAME)}" {
# hset /sics/$fPath/start_magnetic [hval /sics/$fPath/magneticField]
# hset /sics/$fPath/start_magnetic [hval /sics/$fPath/magneticFieldCurernt]
# hset /sics/$fPath/start_temperature_s1 [hval /sics/$fPath/Temp_s1]
# hset /sics/$fPath/start_temperature_s2 [hval /sics/$fPath/Temp_s2]
@@ -249,7 +333,7 @@ proc ::scobj::magnetic::mkMagnetic {argList} {
# }
# proc ::histogram_memory::post_count "{fPath $pa(NAME)}" {
# hset /sics/$fPath/end_magnetic [hval /sics/$fPath/magneticField]
# hset /sics/$fPath/end_magnetic [hval /sics/$fPath/magneticFieldCurernt]
# hset /sics/$fPath/end_temperature_s1 [hval /sics/$fPath/Temp_s1]
# hset /sics/$fPath/end_temperature_s2 [hval /sics/$fPath/Temp_s2]
@@ -258,109 +342,154 @@ proc ::scobj::magnetic::mkMagnetic {argList} {
makesctcontroller sct_magnetic std $pa(IP):$pa(PORT)
hsetprop $hPath read ::scobj::magnetic::rqTempSetPointFunc
hsetprop $hPath rdTempSetPointState ::scobj::magnetic::rdTempSetPointStateFunc $hPath
hsetprop $hPath/field read ::scobj::magnetic::rqFieldFunc
hsetprop $hPath/field rdFieldState ::scobj::magnetic::rdFieldStateFunc $hPath
hsetprop $hPath/Temp read ::scobj::magnetic::rqTempFunc
hsetprop $hPath/Temp rdTempState ::scobj::magnetic::rdTempStateFunc $hPath
hsetprop $hPath/Temp read ::scobj::magnetic::rqTempFunc "sample"
hsetprop $hPath/Temp rdTempState ::scobj::magnetic::rdTempStateFunc $hPath "sample"
hsetprop $hPath/HelioxTempReading read ::scobj::magnetic::rqTempFunc "Heliox"
hsetprop $hPath/HelioxTempReading rdTempState ::scobj::magnetic::rdTempStateFunc $hPath "Heliox"
hsetprop $hPath/DilutTempReading read ::scobj::magnetic::rqTempFunc "Dilut"
hsetprop $hPath/DilutTempReading rdTempState ::scobj::magnetic::rdTempStateFunc $hPath "Dilut"
if {[SplitReply [environment_simulation]]=="false"} {
sct_magnetic poll $hPath 1
#need to set interval to 1 if need to monitor magnetic value in Labview
#sct_magnetic poll $hPath/field 1
sct_magnetic poll $hPath/field $pa(INTERVAL)
sct_magnetic poll $hPath/Temp $pa(INTERVAL)
sct_magnetic poll $hPath/HelioxTempReading $pa(INTERVAL)
sct_magnetic poll $hPath/DilutTempReading $pa(INTERVAL)
}
hsetprop $hPath tuning $pa(TUNING)
if {$pa(TUNING)} {
hfactory $hPath/set_rate plain user float
hfactory $hPath/set_magneticField plain user float
hfactory $hPath/set_DiluxTemp plain user float
hfactory $hPath/set_HelioxTemp plain user float
hfactory $hPath/set_HeaterSwitch plain user text
hsetprop $hPath/set_magneticField write ::scobj::magnetic::setting
hsetprop $hPath/set_magneticField checkReply ::scobj::magnetic::checkReplyFunc $hPath
hsetprop $hPath/set_magneticField write ::scobj::magnetic::setting "field" $hPath
hsetprop $hPath/set_rate write ::scobj::magnetic::setting "rate" $hPath
hsetprop $hPath/set_DiluxTemp write ::scobj::magnetic::setting "DiluxTemp" $hPath
hsetprop $hPath/set_HelioxTemp write ::scobj::magnetic::setting "HelioxTemp" $hPath
hsetprop $hPath/set_HeaterSwitch write ::scobj::magnetic::setting "HeaterS" $hPath
hsetprop $hPath/set_magneticField checkReply ::scobj::magnetic::checkReplyFunc $hPath
if {[SplitReply [environment_simulation]]=="false"} {
sct_magnetic write $hPath/set_rate
sct_magnetic write $hPath/set_magneticField
sct_magnetic write $hPath/set_DiluxTemp
sct_magnetic write $hPath/set_HelioxTemp
sct_magnetic write $hPath/set_HeaterSwitch
}
}
}
# Set the magnetic field
# Querying/Setting the magnetic field
# command is : OxfordSetField fieldValue P ; where "P" is an optinal parameter and if set will change
# to posistent mode after changig the magnetic field
proc OxfordSetField {setPoint {mode ""} args} {
set NAME "magnetic"
hset /sics/$NAME/setPoint $setPoint
proc OxfordSetField {{setPoint ""} {mode ""} args} {
set NAME "magnetic"
if {$setPoint == ""} {
if {$mode == ""} {
broadcast "[hget /sample/$NAME/fieldSetPoint]"
} else {
broadcast "Wrong parameters being provided, check!"
}
} else {
hset /sics/$NAME/fieldSetPoint $setPoint
if {$mode == ""} {
set comm "setF $setPoint\r\n"
sct_magnetic send $comm
} elseif {$mode == "P"} {
set comm "setF $setPoint Pers\r\n"
sct_magnetic send $comm
} else {
broadcast "Wrong parameters being provided, check!"
return
}
if {$mode == ""} {
set comm "setF $setPoint\r\n"
sct_magnetic send $comm
} elseif {$mode == "P"} {
set comm "setF $setPoint Pers\r\n"
sct_magnetic send $comm
} else {
broadcast "Wrong parameters being provided, check!"
return
}
#set num 0
#while { $num <= 40 && [expr abs([hval /sics/$NAME/setPoint] - [hval /sics/$NAME/magneticField]) ] >= 0.001 } {
# broadcast "Magnetic field being set to [hval /sics/$NAME/magneticField] now ......"
# after 500
# set num [expr $num + 1]
#}
#broadcast "Done, Magnetic field set to [hval /sics/$NAME/magneticField]"
#set num 0
#while { $num <= 40 && [expr abs([hval /sics/$NAME/fieldSetPoint] - [hval /sics/$NAME/magneticFieldCurernt]) ] >= 0.001 } {
# broadcast "Magnetic field being set to [hval /sics/$NAME/magneticFieldCurernt] now ......"
# after 500
# set num [expr $num + 1]
#}
#broadcast "Done, Magnetic field set to [hval /sics/$NAME/magneticFieldCurernt]"
}
}
# Querying/Setting the changing rate of the Magnetic Field
# Assign the rate of the changing magnetic field;
# This needs only to be set once unless required
proc OxfordSetRate {setRate} {
set NAME "magnetic"
hset /sics/$NAME/setRate $setRate
proc OxfordSetRate {{setRate ""} args} {
set NAME "magnetic"
if {$setRate == ""} {
broadcast "[hget /sample/$NAME/fieldSetRate]"
} else {
hset /sample/$NAME/fieldSetRate $setRate
set comm "setR $setRate\r\n"
sct_magnetic send $comm
set comm "setR $setRate\r\n"
sct_magnetic send $comm
}
}
# Change the Heliox temperature
proc OxfordSetHTemp {temp} {
set NAME "magnetic"
hset /sics/$NAME/TempSetTarget $temp
# Querying/Setting the Heliox sample temperature
proc OxfordSetHTemp {{temp ""} args} {
set NAME "magnetic"
if {$temp == ""} {
broadcast "[hget /sample/$NAME/HelioxTempSetPoint]"
} else {
#hset /sample/$NAME/HelioxTempSetPoint $temp
set comm "setT $temp\r\n"
sct_magnetic send $comm
set comm "setHelioxTemp $temp\r\n"
sct_magnetic send $comm
#set num 0
#while { $num <= 40 && [expr abs([hval /sics/$NAME/TempSetTarget] - [hval /sics/$NAME/TempSetPoint]) ] >= 0.001 } {
# broadcast "Temperature being set to [hval /sics/$NAME/TempSetPoint] now ......"
# after 500
# set num [expr $num + 1]
#}
#broadcast "Done, Temperaure set to [hval /sics/$NAME/TempSetPoint]"
#set num 0
#while { $num <= 40 && [expr abs([hval /sample/$NAME/HelioxTempSetPoint] - [hval /sample/$NAME/HelioxTempReading]) ] >= 0.001 } {
# broadcast "Temperature being set to [hval /sample/$NAME/HelioxTempReading] now ......"
# after 500
# set num [expr $num + 1]
#}
#broadcast "Done, Temperaure set to [hval /sample/$NAME/HelioxTempReading]"
}
}
# Set the Heater Switch to ON or OFF
# Querying/Setting the Diluxtion Sample temperature
proc OxfordSetDTemp {{temp ""} args} {
set NAME "magnetic"
if {$temp == ""} {
broadcast "[hget /sample/$NAME/DilutTempSetPoint]"
} else {
hset /sample/$NAME/DilutTempSetPoint $temp
set comm "setDilutTemp $temp\r\n"
sct_magnetic send $comm
}
}
# Setting the Heater Switch to ON or OFF
# Command: OxfordSetHS ON (turn on, goto non-persistent mode)
# OxfordSetHS OFF (turn off, goto persistent mode)
proc OxfordSetHS {mode} {
if {[string equal $mode "ON"]!=1 && [string equal $mode "OFF"]!=1} {
if {[string equal [string toupper $mode] "ON"]!=1 && [string equal [string toupper $mode] "OFF"]!=1} {
error "Error commmand, the corrent command should be : OxfordSetHS ON/OFF"
return
}
set comm "setHS $mode\r\n"
set comm "setHS [string toupper $mode]\r\n"
sct_magnetic send $comm
broadcast "Wait 60 seconds for the operation to complete before reset the mode"
}
publish OxfordSetHTemp user
publish OxfordSetField user
publish OxfordSetRate user
publish OxfordSetHS user
publish OxfordSetField user
publish OxfordSetRate user
publish OxfordSetHTemp user
publish OxfordSetDTemp user
publish OxfordSetHS user