## # @file Green Magnetic Controller # # This is a driver for SICS to make following communication with the Labview Green Magnet device # # 1. read some system parameters from the device # 2. set the magnet value # 3. abort the magnet value setting during its processing # # Author: Jing Chen (jgn@ansto.gov.au) July 2011 # ### # @record data in the log files proc debug_log {args} { set d1 [clock format [clock seconds] -format %d%h%Y] set fd [open "../log/green_magnet$d1.log" a] puts $fd "[clock format [clock seconds] -format "%D %T"] $args" close $fd } namespace eval ::scobj::green { } # @brief Request a state report from the Oxford Device by sending a Magnetic Field request command proc ::scobj::green::queryGreenMagnetFunc {} { set comm "getAll\r\n" sct send $comm return rdState } ## # @brief Read and record the greeni Magnet values from the Device proc ::scobj::green::rqGreenMagnetFunc {basePath} { set replyStr [sct result] debug_log $replyStr #broadcast "getT reply:$replyStr\n" set pollNode 999 if {[string first "Error" $replyStr] != -1} { broadcast "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!" } elseif {[string first "read timeout" $replyStr] != -1} { broadcast "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/output $paraArr(Output) hset $basePath/PSU_Vol $paraArr(PSU_Vol) hset $basePath/ramping_rate $paraArr(Rate) hset $basePath/insTarget $paraArr(Target) hset $basePath/setPoint [hval $basePath/insTarget] hset $basePath/status $paraArr(Status) hset $basePath/Bmax $paraArr(Bmax) hset $basePath/msg $paraArr(Msg) set pollNode $paraArr(Output) } if {$pollNode != [sct oldval]} { sct oldval $pollNode sct update $pollNode sct utime readtime } return idle } ## # @brief Make a Green Magnet Controller # # @param argList, {name "magnetic" IP localhost PORT 65123 tuning 1 interval 1} # # name: name of green magnet controller object # IP: IP address of RF generator moxa box # POT: 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::green::mkGreen {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 environment sicslist setatt $pa(NAME) long_name $pa(NAME) set scobj_hpath /sics/$pa(NAME) hfactory $scobj_hpath/output plain user float hfactory $scobj_hpath/PSU_Vol plain user float hfactory $scobj_hpath/ramping_rate plain user text hfactory $scobj_hpath/insTarget plain user float hfactory $scobj_hpath/status plain user text hfactory $scobj_hpath/Bmax plain user float hfactory $scobj_hpath/msg plain user text hfactory $scobj_hpath/pollNode plain user text hsetprop $scobj_hpath/output units "V" hsetprop $scobj_hpath/output uplimit 100 hsetprop $scobj_hpath/output lowlimit 0 hsetprop $scobj_hpath/status values idle,busy hset $scobj_hpath/status idle hsetprop $scobj_hpath tuning $pa(TUNING) # Setting Green Magnet Voltage hfactory $scobj_hpath/setPoint plain user float # make data structure here ::scobj::set_required_props $scobj_hpath hsetprop $scobj_hpath klass environment hsetprop $scobj_hpath privilege spy hsetprop $scobj_hpath type part hsetprop $scobj_hpath control true hsetprop $scobj_hpath data true foreach {hpath klass control data nxsave mutable priv alias} { output NXenvironment true true true true user green_output PSU_Vol NXenvironment true true true true user green_PSU_Vol setPoint NXenvironment true true true true user green_setPoint } { hsetprop $scobj_hpath/$hpath nxalias $alias hsetprop $scobj_hpath/$hpath klass $klass hsetprop $scobj_hpath/$hpath privilege $priv hsetprop $scobj_hpath/$hpath control $control hsetprop $scobj_hpath/$hpath data $data hsetprop $scobj_hpath/$hpath nxsave $nxsave hsetprop $scobj_hpath/$hpath mutable $mutable hsetprop $scobj_hpath/$hpath sdsinfo ::nexus::scobj::sdsinfo } ::scobj::hinitprops $pa(NAME) makesctcontroller sct_green std $pa(IP):$pa(PORT) hsetprop $scobj_hpath/pollNode read ::scobj::green::queryGreenMagnetFunc hsetprop $scobj_hpath/pollNode rdState ::scobj::green::rqGreenMagnetFunc /sics/$pa(NAME) hsetprop $scobj_hpath/pollNode oldval "UNKNOWN" #if {[SplitReply [environment_simulation]]=="false"} { sct_green poll $scobj_hpath/pollNode $pa(INTERVAL) #} } # Set the magnetic voltage field proc greenVol {{vol ""} args} { set NAME "green_magnet" if {$vol == ""} { broadcast "Output = [hval /sample/$NAME/output]" } else { if {$vol<[SplitReply [hgetprop /sample/$NAME/output lowlimit]] || \ $vol>[SplitReply [hgetprop /sample/$NAME/output uplimit]]} { return -code error "setpoint violates limits" } else { if {$vol > [hval /sample/$NAME/Bmax]} { broadcast "Maximum field limit is [hval /sample/$NAME/Bmax], reset again!" return } else { #hset /sample/$NAME/setPoint $vol set comm "set $vol\r\n" sct_green send $comm #after 2000 #while {[hval /sample/$NAME/status] == "busy"} { # broadcast "Magnet Ramping at [hval /sample/$NAME/output]" # after 3000 #} } } } return } # abort a magnet voltage setting during its proceeding proc greenAbortSetting {} { set NAME "green" set comm "abort\r\n" sct_green send $comm return } publish greenAbortSetting user publish greenVol user #IP 137.157.204.8 #PORT 22 #::scobj::green::mkGreen { # name "green_magnet" # IP 137.157.204.57 # PORT 22 # tuning 1 # interval 3 #}