Copied in-situ modifications from ics1-quokka.

This commit is contained in:
Ferdi Franceschini
2013-02-20 18:19:44 +11:00
parent b5b4d7a747
commit e7a478489e
17 changed files with 299 additions and 78 deletions

View File

@@ -1,6 +1 @@
# Detector voltage controller
fileeval $cfPath(hmm)/sct_orhvps_common.tcl
::scobj::dethvps::init ca1-quokka 4001 4.1
dhv1 max 2600
dhv1 lower 19
dhv1 upper 57
fileeval $cfPath(hmm)/ordela_detector_config.tcl

View File

@@ -2,19 +2,46 @@
proc ord_get_pot { potxy potnumber } {
for { set rsp "Bad" } { $rsp == "Bad" } { } {
set potname [ format "%s%d" $potxy [expr $potnumber ^ 3] ]
# set potname [ format "%s%d" $potxy [expr $potnumber ^ 3] ]
# set rspall [ dhv1 cmd P $potname ]
set rspall [ sct_dhv1 transact "P $potname" ]
# NOTE: new driver (ie sct_dhv) re-orders lower 2 bits
set potname [ format "%s%d" $potxy $potnumber ]
set rspall [ sct_dhv transact "P $potname" ]
set rsp [lindex [split $rspall " "] 1]
# MJL sometimes the driver returns '=' or '', fix that...
# ALSO the driver sometimes returns TCL internal strings, reject non-numeric data
# ALSO the driver sometimes returns 65, fix that (range 0 to 63)
set rspval 0
if { $rsp == "=" || $rsp == "" || [scan $rsp %d rspval] != 1 } { set rsp "Bad" }
if { $rspval < 0 } { set rspval 0 }
if { $rspval > 63 } { set rspval 63 }
}
return $rsp
return $rspval
}
Publish ord_get_pot User
proc ord_set_pot { potxy potnumber potvalue } {
set potname [ format "%s%d" $potxy [expr $potnumber ^ 3] ]
# set potname [ format "%s%d" $potxy [expr $potnumber ^ 3] ]
# set rsp [ dhv1 cmd p $potname $potvalue ]
set rsp [ sct_dhv1 transact "p $potname $potvalue" ]
# NOTE: new driver (ie sct_dhv) re-orders lower 2 bits
# MJL 9/10 Added retry code in case write failed.
for { set rsp "Bad" } { $rsp == "Bad" } { } {
set potname [ format "%s%d" $potxy $potnumber ]
# MJL It seems that the pots can somehow get set to '65'. I believe this might be returned when the read
# is invalid (e.g. perhaps the read query is corrupted, then the pot index is out of range and the controller
# responds with '65' to let us know that). So it happened that some read pot values appeared to be '65'.
# But if the sct_dhv transact ever attempts to send '65' to a pot, it seems that it hangs forever.
# Another problem in the driver... Just limit the value to 0 - 63 as it should be
if { $potvalue < 0 } { set potvalue 0 }
if { $potvalue > 63 } { set potvalue 63 }
#clientput "About to transact: " $potname " " $potvalue
set rsp [ sct_dhv transact "p $potname $potvalue" ]
# MJL sometimes the driver returns absolute bollocks, looks like strings from inside the TCL interpreter.
# Under this condition, assume the write failed, although we can't really tell without reading back value, but don't bother.
# Just flag anything that's not 'ACK' as 'Bad' i.e. do retries.
# clientput "Response:" $rsp
if { $rsp != "ACK" } { set rsp "Bad" }
}
return $rsp
}
Publish ord_set_pot User
@@ -133,6 +160,27 @@ proc ord_load_pot_all { filename } {
}
Publish ord_load_pot_all User
proc ord_load_pot_all_old_format { filename } {
# When saved by the 21000N software, the first row is y in reversed order and the second row is x in normal order
# This routine reads the file, then reorders the values to normal x then y order
ord_load_pot_all $filename
global ord_pot_all_x
global ord_pot_all_y
set ord_pot_all_x_old_format $ord_pot_all_x
set ord_pot_all_y_old_format $ord_pot_all_y
set ord_pot_all_x ""
set ord_pot_all_y ""
for { set ixy 0 } { $ixy <= 191 } { incr ixy } {
lappend ord_pot_all_x [lindex $ord_pot_all_y_old_format $ixy]
lappend ord_pot_all_y [lindex $ord_pot_all_x_old_format [expr 191 - $ixy]]
}
clientput " All pot settings reordered from 21000N format to normal format."
clientput "x settings:" $ord_pot_all_x
clientput "y settings:" $ord_pot_all_y
}
Publish ord_load_pot_all_old_format User
set histogram_xy ""
set histogram_x ""
set histogram_y ""
@@ -157,7 +205,7 @@ proc ord_get_histogram_xy { bs_x_l bs_x_h bs_y_l bs_y_h roi_x_l roi_x_h roi_y_l
global histogram_x
global histogram_y
clientput "Retrieving 2D xy histogram..."
set histogram_xy [ lreplace [ split [ hmm get 1 ] ] 0 1 ]
set histogram_xy [ lreplace [ split [ ::histogram_memory::gethmm HISTOPERIOD_XY ] ] 0 1 ]
if { ($bs_x_l > $bs_x_h || $bs_y_l > $bs_y_h) && $roi_x_l == 0 && $roi_x_h == 191 && $roi_y_l == 0 && $roi_y_h == 191 } {
set get_full_histogram 1
clientput "Calculating 2D histograms over full detector area..."

View File

@@ -0,0 +1,17 @@
# Detector voltage controller
set sim_mode [SplitReply [detector_simulation]]
if {$::sim_mode == "true"} {
EvFactory new dhv1 sim
} else {
clientput "FastCom Detector Voltage control"
makeasyncqueue acq NHQ200 ca1-quokka 4002
evfactory new dhv1 nhq200 acq 1
dhv1 tolerance 5
dhv1 rate 10
dhv1 upper 2250
dhv1 lower 775
dhv1 max 2600
#dhv1 lock
}

View File

@@ -0,0 +1,33 @@
# Detector voltage controller
# Baud: 19200, Data bits: 8, Stop bits: 1, Parity: None, Flow: None, FIFO: Enable, Interface: RS485-4wire
fileeval $cfPath(hmm)/sct_orhvps_common.tcl
# Old Moxa (before 17/9/2010) in Quokka cabin
#::scobj::dethvps::init ca1-quokka 4001 4.1
#dhv1 max 2600
#dhv1 lower 19
#dhv1 upper 57
# New Moxa (after 17/9/2010) near Quokka tank
#::scobj::dethvps::init 137.157.202.86 4002 4.1
# Spare detector max voltage and pot values
#dhv1 max 2405
#dhv1 lower 19
#dhv1 upper 59
# 22/6/2011
set dhv1Max_SN006 2405
set upper_SN006 55
set dhv1Max_SN003 2600
set upper_SN003 57
set dhvMax $dhv1Max_SN006
set dhvUpper $upper_SN006
::scobj::dethvps::init 137.157.202.71 4001 [expr 0.1 * $dhvMax /63.0]
# Voltage = potval * (dhv1.max / 63)
# if potval = 60 and dhv1.max = 2400 then voltage = 60 * 2400/63 = 2285.7V
dhv1 max $dhvMax
dhv1 lower 19
dhv1 upper $dhvUpper