From aaa10b5cf141f855722d6118b61e895024ada190 Mon Sep 17 00:00:00 2001 From: Jing Chen Date: Tue, 7 Aug 2012 16:27:59 +1000 Subject: [PATCH] r3695 | jgn | 2012-08-07 16:27:59 +1000 (Tue, 07 Aug 2012) | 1 line --- .../pelican/config/beamline/sct_power.tcl | 126 ++++++++++++------ 1 file changed, 86 insertions(+), 40 deletions(-) diff --git a/site_ansto/instrument/pelican/config/beamline/sct_power.tcl b/site_ansto/instrument/pelican/config/beamline/sct_power.tcl index 12960556..3d554da7 100644 --- a/site_ansto/instrument/pelican/config/beamline/sct_power.tcl +++ b/site_ansto/instrument/pelican/config/beamline/sct_power.tcl @@ -36,6 +36,13 @@ namespace eval ::scobj::ag1010 { variable CtrlGetSVER [format %02x 29] variable CtrlGetMEAS [format %02x 30] variable CtrlGetSTA [format %02x 31] + + variable ForPowerLimit 10040 + variable RefPowerLimit 1630 + variable FreqUpLimit 2000000 + variable FreqDownLimit 0.02 + + namespace export par } @@ -57,7 +64,7 @@ proc ::scobj::ag1010::getValue {tc_root nextState rdPara} { set CRC 0 if {$LEN < 2} { - return -code error "Error in getValue: wrong data length provided." + return -code error "Error in LF AG1010 Setting: wrong data length provided." } elseif {$LEN > 2} { set cmd [format %02x%02x%02x%02x%02x $HEAD $LEN $CTRL $DATA $CRC] } else { @@ -65,7 +72,7 @@ proc ::scobj::ag1010::getValue {tc_root nextState rdPara} { } sct send "$cmd" } message ]} { - return -code error "Error in getValue: $message." + return -code error "Error in LF AG1010 Setting: $message." } return $nextState } @@ -82,6 +89,11 @@ proc ::scobj::ag1010::setValue {tc_root nextState rdPara wrPara} { # tc_root and idx are not being used - however, don't remove so we can use the # same calling mask as for setPoint() or other $wrFunc + variable ForPowerLimit + variable RefPowerLimit + variable FreqUpLimit + variable FreqDownLimit + set ns /sics/ag1010 #set ns [sct] if {[ catch { @@ -92,17 +104,32 @@ proc ::scobj::ag1010::setValue {tc_root nextState rdPara wrPara} { set newPara [string trim [sct target] " "] switch -exact $wrPara { - "FPL" { set RPL [hval $ns/limits/ReversePower] - set data [format %04x%04x%04x%04x $newPara $RPL 0 0] + "FPL" { if {$newPara > $ForPowerLimit || $newPara < 0} { + broadcast "Error: The Limit for the Forward Power is 0~$ForPowerLimit dW" + return idle + } else { + set RPL [hval $ns/limits/ReversePower] + set data [format %04x%04x%04x%04x $newPara $RPL 0 0] + } } - "RPL" { set FPL [hval $ns/limits/ForwardPower] - set data [format %04x%04x%04x%04x $FPL $newPara 0 0] + "RPL" { if {$newPara > $RefPowerLimit || $newPara < 0} { + broadcast "Error: The Limit for the Reverse Power is 0~$RefPowerLimit dW" + return idle + } else { + set FPL [hval $ns/limits/ForwardPower] + set data [format %04x%04x%04x%04x $FPL $newPara 0 0] + } } "PAGC" { set data [format %04x $newPara] } "PMGC" { set data [format %04x $newPara] } - "FREQ" { set Freq [expr $newPara / 1000] - set FreqHz [expr $newPara % 1000] - set data [format %04x%04x $Freq $FreqHz] + "FREQ" { if {$newPara<$FreqDownLimit || $newPara>$FreqUpLimit} { + broadcast "Error: Freqence shall be set between $FreqDownLimit Hz and $FreqUpLimit Hz" + return idle + } else { + set Freq [expr $newPara / 1000] + set FreqHz [expr $newPara % 1000] + set data [format %04x%04x $Freq $FreqHz] + } } "SoftOn" { if {$newPara > 1 || $newPara < 0} { @@ -345,14 +372,20 @@ proc ::scobj::ag1010::rdValue {} { #set ns [sct] if {[ catch { set data [string trim [sct result] " "] - broadcast $data + + hset $ns/responseMsg "$data" + #broadcast "rdValue : $data" if {[string first "failed" $data] != -1} { - broadcast "Error in rdValue: $data" + broadcast "Error in LF AG1010 Response: $data" + return -code error "$data" + } elseif {[string first "read timeout" $data] != -1} { + broadcast "Error in LF AG1010 Response: $data" return -code error "$data" } elseif {[string length $data] < 1} { - broadcast "Error in rdValue: no message returned from device" - return -code error "Error in rdValue: no message returned from device" + broadcast "Error in LF AG1010 Response: no message returned from device" + return -code error "Error in LF AG1010 Response: no message returned from device" } + set ctrlCode [format %d 0x[string range $data 4 5]] switch -glob $ctrlCode { @@ -382,8 +415,7 @@ proc ::scobj::ag1010::rdValue {} { set FreqHz [format %d [expr 0x$FreqHzH$FreqHzL]] hset $ns/FRE/FREQ [expr $Freq * 1000 + $FreqHz] } - 7 { - set softKey 0x[string range $data 6 7] + 7 { set softKey 0x[string range $data 6 7] if {[expr $softKey & 0x80] == 0} { hset $ns/SKEY/SoftOn "Controller takes over the keyboard of controller" } else { @@ -461,8 +493,7 @@ proc ::scobj::ag1010::rdValue {} { set DVerL [string range $data 16 17] hset $ns/SVER/DeviceVersion "$DVerH$DVerL" } - 14 { - set FPH [string range $data 6 7] + 14 { set FPH [string range $data 6 7] set FPL [string range $data 8 9] hset $ns/MEAS/ForwardPower [format %d [expr 0x$FPH$FPL]] @@ -600,18 +631,18 @@ proc createNode {scobj_hpath sct_controller cmdGroup varName readable writable p hsetprop $nodeName read ${ns}::getValue $scobj_hpath $rdFunc $rdPara hsetprop $nodeName $rdFunc ${ns}::$rdFunc if {$pollEnabled == 1} { - #if {[SplitReply [environment_simulation]]=="false"} { + if {[SplitReply [environment_simulation]]=="false"} { $sct_controller poll $nodeName - #} + } } } if {$writable == 1} { hsetprop $nodeName write ${ns}::setValue $scobj_hpath $rdFunc $rdPara $wrPara hsetprop $nodeName $rdFunc ${ns}::$rdFunc if {$pollEnabled == 1} { - #if {[SplitReply [environment_simulation]]=="false"} { + if {[SplitReply [environment_simulation]]=="false"} { $sct_controller write $nodeName - #} + } } } if {1 < [string length $unit]} { @@ -657,6 +688,7 @@ proc ::scobj::ag1010::mkAG {argList} { set scobj_hpath /sics #makesctcontroller sct_ag1010 rfamp $pa(IP):$pa(PORT) + #makesctcontroller sct_$pa(NAME) std $pa(IP):$pa(PORT) makesctcontroller sct_$pa(NAME) lfgen $pa(IP):$pa(PORT) ######################################################################################################### @@ -733,7 +765,7 @@ proc ::scobj::ag1010::mkAG {argList} { STA/keyState Key2 0 0 0 1 text {} user {} {} {} {} STA/keyState Key3 0 0 0 1 text {} user {} {} {} {} - P responseMsg 0 0 0 1 text {} user {2 42} {} {} {} + P responseMsg 0 0 0 1 text {} spy {2 42} {} {} {} P SetLimitsFPL 0 1 1 1 int {dW} user {10 2} {rdValue} {FPL} {} P SetLimitsRPL 0 1 1 1 int {dW} user {10 2} {rdValue} {RPL} {} @@ -767,6 +799,8 @@ proc ::scobj::ag1010::mkAG {argList} { # SICS commands +namespace import ::scobj::ag1010::par + proc LFSetLimitsFPL {para} { set HEAD 0x96 @@ -777,12 +811,16 @@ proc LFSetLimitsFPL {para} { set ns /sics/ag1010 set newPara [string trim $para " "] - set RPL [hval $ns/limits/ReversePower] - set data [format %04x%04x%04x%04x $newPara $RPL 0 0] - set cmdi [format %02x%02x%02x%s%02x $HEAD $LEN $CTRL $data $CRC] + if {$para > 10040 || $para < 0} { + broadcast "Error: The Limit for the Forward Power is 0~10040 dW" + } else { + set RPL [hval $ns/limits/ReversePower] + set data [format %04x%04x%04x%04x $newPara $RPL 0 0] + set cmd [format %02x%02x%02x%s%02x $HEAD $LEN $CTRL $data $CRC] - broadcast "Set Forward Power Limits to $newPara dW" - sct_ag1010 send "$cmd" + broadcast "Set Forward Power Limits to $newPara dW" + sct_ag1010 send "$cmd" + } } proc LFSetLimitsRPL {para} { @@ -795,12 +833,16 @@ proc LFSetLimitsRPL {para} { set ns /sics/ag1010 set newPara [string trim $para " "] - set FPL [hval $ns/limits/ForwardPower] - set data [format %04x%04x%04x%04x $FPL $newPara 0 0] - set cmd [format %02x%02x%02x%s%02x $HEAD $LEN $CTRL $data $CRC] + if {$para > 1630 || $para < 0} { + broadcast "Error: The Limit for the Reflected Power is 0~1630 dW" + } else { + set FPL [hval $ns/limits/ForwardPower] + set data [format %04x%04x%04x%04x $FPL $newPara 0 0] + set cmd [format %02x%02x%02x%s%02x $HEAD $LEN $CTRL $data $CRC] - broadcast "Set Reverse Power Limits to $newPara dW" - sct_ag1010 send "$cmd" + broadcast "Set Reverse Power Limits to $newPara dW" + sct_ag1010 send "$cmd" + } } proc LFSetPAGC {para} { @@ -847,13 +889,17 @@ proc LFSetFREQ {para} { set ns /sics/ag1010 set newPara [string trim $para " "] - set Freq [expr $newPara / 1000] - set FreqHz [expr $newPara % 1000] - set data [format %04x%04x $Freq $FreqHz] - set cmd [format %02x%02x%02x%s%02x $HEAD $LEN $CTRL $data $CRC] + if {$para < 0.02 || $para > 2000000} { + broadcast "Error: Freqence shall be set between 0.02 Hz and 2 MHz" + } else { + set Freq [expr $newPara / 1000] + set FreqHz [expr $newPara % 1000] + set data [format %04x%04x $Freq $FreqHz] + set cmd [format %02x%02x%02x%s%02x $HEAD $LEN $CTRL $data $CRC] - broadcast "Set Frequency to $newPara Hz" - sct_ag1010 send "$cmd" + broadcast "Set Frequency to $newPara Hz" + sct_ag1010 send "$cmd" + } } proc LFSetBurstMode {para} { @@ -1129,8 +1175,8 @@ publish LFGetMEAS user # IP 137.157.202.219 ::scobj::ag1010::mkAG { name "ag1010" - IP localhost - PORT 50001 + IP 137.157.202.219 + PORT 4001 tuning 1 interval 5 }