add sct_oxford_labview.tcl
r3324 | jgn | 2012-01-03 12:00:22 +1100 (Tue, 03 Jan 2012) | 1 line
This commit is contained in:
committed by
Douglas Clowes
parent
21d5f727f1
commit
acd1b9e036
@@ -0,0 +1,223 @@
|
||||
##
|
||||
# @file Magnetic Controller
|
||||
#
|
||||
# This is a driver for SICS to make following communication with the Labview Oxford device
|
||||
#
|
||||
# 1. read and set the Magnetic Field parameter : magneticField
|
||||
# 2. read the Magnetic Temperature paramter : Temp_s1
|
||||
#
|
||||
# Author: Jing Chen (jgn@ansto.gov.au) July 2011
|
||||
#
|
||||
# The Magnetic Controller can be installed with the following command,
|
||||
# ::scobj::magnetic::mkMagnetic {
|
||||
# name "magnetic"
|
||||
# IP localhost
|
||||
# PORT 62944
|
||||
# tuning 1
|
||||
# interval 1
|
||||
#
|
||||
|
||||
##
|
||||
# @brief Set a Magnetific Field value and send to the Oxford Device.
|
||||
#
|
||||
# @param basePath, The object path, this is where we keep our state variables.
|
||||
|
||||
proc debug_log {args} {
|
||||
set fd [open "../log/magnetic.log" a]
|
||||
puts $fd "[clock format [clock seconds] -format "%T"] $args"
|
||||
close $fd
|
||||
}
|
||||
|
||||
namespace eval ::scobj::magnetic {
|
||||
}
|
||||
|
||||
proc ::scobj::magnetic::setting {} {
|
||||
set newField [sct target]
|
||||
set comm "setF $newField\r\n"
|
||||
|
||||
sct send $comm
|
||||
return checkReply
|
||||
}
|
||||
|
||||
proc ::scobj::magnetic::checkReplyFunc {basePath} {
|
||||
# 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!!"
|
||||
# }
|
||||
return idle
|
||||
}
|
||||
|
||||
##
|
||||
|
||||
# @brief Request a state report from the Oxford Device by sending a Magnetic Field request command
|
||||
proc ::scobj::magnetic::rqFieldFunc {} {
|
||||
set comm "getF\r\n"
|
||||
sct send $comm
|
||||
return rdFieldState
|
||||
}
|
||||
|
||||
##
|
||||
# @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 Device, check again!"
|
||||
} else {
|
||||
hset $basePath/magneticField $replyStr
|
||||
}
|
||||
|
||||
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"
|
||||
sct send $comm
|
||||
return rdTempState
|
||||
}
|
||||
|
||||
##
|
||||
# @brief Read and record the Magnetific Temperature value from the Oxford Device
|
||||
proc ::scobj::magnetic::rdTempStateFunc {basePath} {
|
||||
set replyStr [sct result]
|
||||
debug_log $replyStr
|
||||
#broadcast "getT reply:$replyStr\n"
|
||||
if {[string first "Error" $replyStr] != -1} {
|
||||
broadcast "ERROR: cannot get the Magnetific Temperature value from the Oxford Device, check again!"
|
||||
} 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)
|
||||
}
|
||||
|
||||
return idle
|
||||
}
|
||||
|
||||
|
||||
##
|
||||
# @brief Make a Magnetic Controller
|
||||
#
|
||||
# @param argList, {name "magnetic" IP localhost PORT 65123 tuning 1 interval 1}
|
||||
#
|
||||
# name: name of magnetic controller object
|
||||
# IP: IP address of RF generator moxa box
|
||||
# PORT: Port number assigned to the generator on the moxa-box
|
||||
# tuning: boolean, set tuning=1 to allow instrument scientists to set the axe positions
|
||||
# interval: polling and ramping interval in seconds.
|
||||
|
||||
proc ::scobj::magnetic::mkMagnetic {argList} {
|
||||
# Generate parameter array from the argument list
|
||||
foreach {k v} $argList {
|
||||
set KEY [string toupper $k]
|
||||
set pa($KEY) $v
|
||||
}
|
||||
|
||||
MakeSICSObj $pa(NAME) SCT_OBJECT
|
||||
sicslist setatt $pa(NAME) klass instrument
|
||||
sicslist setatt $pa(NAME) long_name $pa(NAME)
|
||||
|
||||
hfactory /sics/$pa(NAME)/field plain user float
|
||||
hfactory /sics/$pa(NAME)/magneticField plain user float
|
||||
|
||||
hfactory /sics/$pa(NAME)/start_magnetic plain user float
|
||||
hfactory /sics/$pa(NAME)/end_magnetic plain user float
|
||||
|
||||
hfactory /sics/$pa(NAME)/Temp plain user float
|
||||
hfactory /sics/$pa(NAME)/Temp_s1 plain user float
|
||||
hfactory /sics/$pa(NAME)/Temp_s2 plain user float
|
||||
hfactory /sics/$pa(NAME)/Temp_s3 plain user float
|
||||
|
||||
hfactory /sics/$pa(NAME)/start_temperature_s1 plain user float
|
||||
hfactory /sics/$pa(NAME)/end_temperature_s1 plain user float
|
||||
hfactory /sics/$pa(NAME)/start_temperature_s2 plain user float
|
||||
hfactory /sics/$pa(NAME)/end_temperature_s2 plain user float
|
||||
hfactory /sics/$pa(NAME)/start_temperature_s3 plain user float
|
||||
hfactory /sics/$pa(NAME)/end_temperature_s3 plain user float
|
||||
|
||||
hfactory /sics/$pa(NAME)/setPoint plain user float
|
||||
hfactory /sics/$pa(NAME)/setRate plain user float
|
||||
hfactory /sics/$pa(NAME)/setTemp plain user float
|
||||
|
||||
#makesctcontroller sct_magnetic rfamp $pa(IP):$pa(PORT)
|
||||
makesctcontroller sct_magnetic std $pa(IP):$pa(PORT)
|
||||
|
||||
hsetprop /sics/$pa(NAME)/field read ::scobj::magnetic::rqFieldFunc
|
||||
hsetprop /sics/$pa(NAME)/field rdFieldState ::scobj::magnetic::rdFieldStateFunc /sics/$pa(NAME)
|
||||
|
||||
hsetprop /sics/$pa(NAME)/Temp read ::scobj::magnetic::rqTempFunc
|
||||
hsetprop /sics/$pa(NAME)/Temp rdTempState ::scobj::magnetic::rdTempStateFunc /sics/$pa(NAME)
|
||||
|
||||
hsetprop /sics/$pa(NAME) tuning $pa(TUNING)
|
||||
|
||||
# Initialise properties required for generating the API for GumTree and to save data
|
||||
::scobj::hinitprops $pa(NAME) start_magnetic end_magnetic magneticField
|
||||
::scobj::hinitprops $pa(NAME) start_temperature_s1 end_temperature_s1 Temp_s1
|
||||
::scobj::hinitprops $pa(NAME) start_temperature_s2 end_temperature_s2 Temp_s2
|
||||
::scobj::hinitprops $pa(NAME) start_temperature_s3 end_temperature_s3 Temp_s3
|
||||
|
||||
sct_magnetic poll /sics/$pa(NAME)/field $pa(INTERVAL)
|
||||
sct_magnetic poll /sics/$pa(NAME)/Temp $pa(INTERVAL)
|
||||
|
||||
if {$pa(TUNING)} {
|
||||
hfactory /sics/$pa(NAME)/set_magneticField plain user float
|
||||
|
||||
hsetprop /sics/$pa(NAME)/set_magneticField write ::scobj::magnetic::setting
|
||||
hsetprop /sics/$pa(NAME)/set_magneticField checkReply ::scobj::magnetic::checkReplyFunc /sics/$pa(NAME)
|
||||
|
||||
sct_magnetic write /sics/$pa(NAME)/set_magneticField $pa(INTERVAL)
|
||||
}
|
||||
|
||||
proc ::histogram_memory::pre_count {} {
|
||||
hset /sics/$pa(NAME)/start_magnetic [hval /sics/$pa(NAME)/magneticField]
|
||||
|
||||
hset /sics/$pa(NAME)/start_temperature_s1 [hval /sics/$pa(NAME)/Temp_s1]
|
||||
hset /sics/$pa(NAME)/start_temperature_s2 [hval /sics/$pa(NAME)/Temp_s2]
|
||||
hset /sics/$pa(NAME)/start_temperature_s3 [hval /sics/$pa(NAME)/Temp_s3]
|
||||
}
|
||||
|
||||
proc ::histogram_memory::post_count {} {
|
||||
hset /sics/$pa(NAME)/end_magnetic [hval /sics/$pa(NAME)/magneticField]
|
||||
|
||||
hset /sics/$pa(NAME)/end_temperature_s1 [hval /sics/$pa(NAME)/Temp_s1]
|
||||
hset /sics/$pa(NAME)/end_temperature_s2 [hval /sics/$pa(NAME)/Temp_s2]
|
||||
hset /sics/$pa(NAME)/end_temperature_s3 [hval /sics/$pa(NAME)/Temp_s3]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
proc OxfordSetField {setPoint} {
|
||||
set NAME "magnetic"
|
||||
hset /sics/$NAME/setPoint $setPoint
|
||||
|
||||
set comm "setF $setPoint\r\n"
|
||||
sct_magnetic send $comm
|
||||
}
|
||||
|
||||
proc OxfordSetRate {setRate} {
|
||||
set NAME "magnetic"
|
||||
hset /sics/$NAME/setRate $setRate
|
||||
|
||||
set comm "setR $setRate\r\n"
|
||||
sct_magnetic send $comm
|
||||
}
|
||||
|
||||
proc OxfordSetTemp {temp} {
|
||||
set NAME "magnetic"
|
||||
hset /sics/$NAME/setTemp $temp
|
||||
|
||||
set comm "setT $temp\r\n"
|
||||
sct_magnetic send $comm
|
||||
}
|
||||
|
||||
|
||||
publish OxfordSetField user
|
||||
publish OxfordSetRate user
|
||||
publish OxfordSetTemp user
|
||||
|
||||
Reference in New Issue
Block a user