sct_protek608.c

Implements a protocol handler for the protek  608 multimeters which just allows us to read the display.
It reports all elements of the display including the bar graph, it does not provide remote control of the multimeter.  The protocol handler broadcasts a warning to all clients if the auto-off function is enabled.

sct_rfamp.c
This is a protocol handler for the Mirrortron 35V 7A AC Generator (ANSFR-83B).

sinqhttpprot.c
Copied the PSI script context http protocol handler.

sct_orhvpsprot.c
Ordela high voltage power supply protocol handler now catches unknown commands.

sct_eurotherm_2000.tcl
Eurotherm controller for the kowari load frame by Douglas Clowes.

sct_lakeshore_3xx.tcl
Latest update from Arndt.  The two control loops are now independent, settletime and tolerance now work properly.

common_instrument_dictionary.tcl
Make instrument/status saveable.

sct_orhvps_common.tcl
Provides voltage ramping and implements the dhv1 command for the Ordela HVPS via the sct_orhpsprot.c protocol handler.

hmm_configuration_common_1.tcl
Adds new "histmem clockscale" subcommand to get and set the clock scale from the fat_clock_scale FAT parameter.
You can now upload the FAT FRAME_BUFFER and FRAME_DUTYCYCLE parameters to the histogram memory.
The veto commands are now "histmem veto on" and "histmem veto off".

hmm_object.tcl
The axis order for the histmem object has been restore to t,y,x

sct_positmotor_common.tcl
Code has been simplified.

nxscripts_common_1.tcl
Removed obsolete ::nexus::data function.  TOF axis now correctly report time_of_flight instead of "time".

plc_common_1.tcl
Make PLC info saveable.

scan_common_1.tcl
SICS-385 The scan command should check the final scan variable value against he soft upper and lower limits, not against the hard limits.
Make sure that the scan variable axis is saved.

platypus, kowari, quokka hmm_configuration.tcl
Use the HOR and VER entries in the new histmem_axes hash to select the horizontal and vertical axes for the histmem.

kowari motor_configuration.tcl secondary_slit_configuration.tcl
Flatten slits motor structure to match old layout in data files.

quokka commands.tcl
SICS-380 EApPosYmm -> EApPosY

quokka detector.tcl
Use new script context controller for Ordela HVPS

quokka hmm_configuration.tcl
Set detector height to 5.08*192 the same as the width

quokka motor_configuration.tcl
Code cleanup

quokka positmotor_configuration.tcl
Use new positmotor code.

quokka aperture_configuration.tcl
Added attenuation factor column to AttRotLookupTable

quokka parameters.tcl
SICS-380 Refactor nexus, remove redundant parameters.

site_ansto.c
Added the following protocols, Httpl, Protek608, aand RFAmp.

scriptcontext.c
SICS-386 SctActionHandler: set "send" string to NULL when a chain of scripts completes with state=idle.
It turns out that if none of the scripts in the "read chain" call [sct send] each time the chain is executed, then SICS will hammer the device with calls to AsconWrite(). This can be avoided if SctActionHandler sets the 'send' string to NULL before "goto finish" in the idle state. This will be safer and still let you have chains with multiple [sct send] and read scripts.

asyncprotocol.c
Fix platypus memory leak.

devser.c
SICS-387 Started adding code to pass signals on to script context drivers.

ascon.c
AsconTask(): Make sure we return to the AsconIdle state when sending a command which expect no response, also only reconnect if there is a Timeout when there has been an error.

r2888 | ffr | 2010-04-19 14:04:41 +1000 (Mon, 19 Apr 2010) | 90 lines
This commit is contained in:
Ferdi Franceschini
2010-04-19 14:04:41 +10:00
committed by Douglas Clowes
parent aa6bb7f1da
commit d9da95a5df
35 changed files with 3936 additions and 2477 deletions

View File

@@ -3,275 +3,115 @@
# position. The second column is the motor position.
# The lookup table must have a header which names the two columns.
namespace eval ::scobj::positmotor {
variable posit_table
variable posit_indices
# TODO Add a script to edit the posit_table and attach it to indexed nodes with read and write actions.
proc abort_on_invalid_posindex {pos motor} {
variable posit_indices
set pos0 [lindex $posit_indices($motor) 0]
set posend [lindex $posit_indices($motor) end]
if {$pos < $pos0 || $pos > $posend} {
return -code error "ERROR: Indexed position must be between $pos0 and $posend"
}
}
proc isbetween {val l1 l2} {
if {($l1 <= $val && $val <= $l2) || ($l2 <= $val && $val <= $l1)} {
return true
} else {
return false
}
}
proc iswithin {val pos prec} {
if {[expr $pos - $prec] <= $val && $val <= [expr $pos + $prec]} {
return true
} else {
return false
}
}
##
# @brief Convert an indexed position to a physical motor position
proc pos2val {pos motor} {
variable posit_table
if [ catch {
abort_on_invalid_posindex $pos $motor
set bot [expr int(floor($pos))]
set top [expr int(ceil($pos))]
set fract [expr fmod($pos,1)]
set val [expr $fract * ($posit_table($motor,$top) - $posit_table($motor,$bot)) + $posit_table($motor,$bot)]
} message ] {
return -code error $message
} else {
return $val
}
}
##
# @brief Convert a physical motor position to and indexed position
proc val2pos {val precision motor} {
variable posit_table
variable posit_indices
set val [expr double($val)]
set pos0 [lindex $posit_indices($motor) 0]
set posend [lindex $posit_indices($motor) end]
if {$posit_table($motor,$pos0) < $posit_table($motor,$posend)} {
set fwd_table true
if {$val < [expr $posit_table($motor,$pos0) - $precision]} {return -$pos0}
if {$val > [expr $posit_table($motor,$posend) + $precision]} {return -$posend}
} else {
set fwd_table false
if {$val < [expr $posit_table($motor,$posend) - $precision]} {return -$posend}
if {$val > [expr $posit_table($motor,$pos0) + $precision]} {return -$pos0}
}
if [catch {
set ibot $pos0
set itop [lindex $posit_indices($motor) 1]
if {$fwd_table} {
while {$val > [expr $posit_table($motor,$itop) + $precision]} {
incr ibot
incr itop
}
} else {
while {$val < [expr $posit_table($motor,$itop) - $precision]} {
incr ibot
incr itop
}
}
set bot [expr $posit_table($motor,$ibot)]
set top [expr $posit_table($motor,$itop)]
if [iswithin $val $bot $precision] {
set pos $ibot
} elseif [iswithin $val $top $precision] {
set pos $itop
} else {
# set pos [format "%.3f" [expr int(($val -$bot)/$precision)*$precision/($top - $bot) + $ibot]]
set pos [expr abs(int(($val -$bot)/$precision)*$precision/($top - $bot)) + $ibot]
}
} errmsg] {
return -code error $errmsg
} else {
return $pos
}
}
proc rd_index {par motor} {
sct result [SplitReply [$motor]]
return state_reading_index
}
namespace eval ::scobj::positmotor { }
##
# @brief Translate and report the current motor reading.
proc ::scobj::positmotor::rptVal {val2IDXfn table precision_node} {
set newVal [$val2IDXfn [sct result] [hval $precision_node] $table]
if {[sct oldval] != $newVal} {
sct update $newVal
sct oldval $newVal
}
set path [sct]
if {[hval $path/status] == "STOPPING"} {
hset $path/status "IDLE"
}
return idle
}
##
# @brief Updates the position index and sets the associated instrument
# parameter
#
# @param path, Script context object path
# @param par, Control parameter for the positional motor
# @param motor, The name of the motor which does the actual driving
# @param staticpar, The static parameter defined in the lookup table.
# @param calc_instpar, Name of an optional function which calculates
# the instrument parameter from the staticpar. Eg attenuation
proc state_reading_index {path par motor staticpar calc_instpar} {
variable posit_table
variable posit_label
sct writestatus replyreceived
set rply [val2pos [sct result] [hval $path/$par/motprecision] $motor]
set data $rply
# broadcast state_reading_index update parameter $par $data
if {$data != [sct oldval] || [sct force_update] } {
# if {[status] == "status = Driving" && [hval $path/status] == "IDLE"} {
# hset $path/status BUSY
# }
sct oldval $data
sct update $data
if {$data > 0 && [string is integer $data]} {
if {$calc_instpar == "@none"} {
hset $path/$staticpar $posit_label($motor,$data)
} else {
hset $path/$staticpar [$calc_instpar $posit_label($motor,$data)]
}
}
sct force_update False
sct utime readtime
}
if {[hval $path/status] == "STOPPING"} {
hset $path/status IDLE
}
return idle
}
# Convert position index to a physical position before running the motor
proc w_index {sct_controller path par motor} {
variable posit_table
# broadcast w_index
if [ catch {
set val [pos2val [sct target] $motor]
hset $path/status BUSY
run $motor $val
# $sct_controller poll $path 1
} errmsg ] {
error $errmsg
return noResponse
} else {
return noResponse
}
}
proc noResponse {} {
return idle
}
# TODO Check thread 0 and motion control disabled?
proc check_motor {} {
# broadcast check_motor
set val [sct target]
return OK
}
proc setposindex {posindex val motor} {
variable posit_table
set posit_table($motor,$posindex) $val
}
# @brief Request the current motor reading
proc ::scobj::positmotor::reqVal {state motor} {
sct result [SplitReply [$motor]]
return $state
}
##
# @brief Create a positional motor control object which lets you
# drive to an indexed position defined in a lookup table.
# @brief Convert the target position to a motor position and drive the motor to the target.
proc ::scobj::positmotor::setVal {ID2valXfn motor table} {
set path [sct]
set pos [$ID2valXfn [sct target] $table]
hset $path/status "BUSY"
run $motor $pos
return noResponse
}
proc ::scobj::positmotor::noResponse {} {
return idle
}
##
# @brief Creates a controller which can drive motors to discrete labelled positions
#
# @param sct_controller, Name of controller created with mk_sct_positmotor
# @param klass, Controls place in hdb and nexus file hierarchy.
# @param motor, Name of motor which handles the actual driving.
# @param scobjName, Name of script-context object which we are creating.
# @param pindex, Position index, selects the position to drive to.
# @param table_ID, Tag which identifies the lookup table used for this controller.
# @param posit_list, Lookup table which maps the index set on the control parameter to a position.
# @param calc_instpar, Optional command which returns ????
proc mk_sct_positmotor {sct_controller klass motor scobjName pindex table_ID posit_list {calc_instpar @none}} {
variable posit_table
variable posit_indices
variable posit_label
set index 1
set staticpar [lindex $posit_list 0]
foreach {label position} [lrange $posit_list 2 end] {
lappend posit_indices($motor) $index
set posit_table($motor,$index) $position
set posit_label($motor,$index) $label
incr index
}
# set posit_indices [lsort -integer [array names posit_table]]
if [ catch {
# @param sct_controller, name of script-context protocol handler
# @param name, name of parameter which corresponds to the discrete motor positions
# @param type, float or int
# @param motor, name of motor
# @param klass, nexus class for parameter
# @param table, table of index versus motor positions
proc mkPosit {sct_controller name type motor klass table} {
set ns ::scobj::positmotor
MakeSICSObj $scobjName SCT_OBJECT
sicslist setatt $scobjName klass $klass
# Make setable position parameter and poll it.
set scobjPath /sics/$scobjName
hfactory $scobjPath/$pindex plain user float
hsetprop $scobjPath/$pindex read ${ns}::rd_index $pindex $motor
hsetprop $scobjPath/$pindex state_reading_index ${ns}::state_reading_index $scobjPath $pindex $motor $staticpar $calc_instpar
hsetprop $scobjPath/$pindex write ${ns}::w_index $sct_controller $scobjPath $pindex $motor
hsetprop $scobjPath/$pindex noResponse ${ns}::noResponse
hsetprop $scobjPath/$pindex check ${ns}::check_motor
MakeSICSObj $name SCT_OBJECT user $type
sicslist setatt $name klass $klass
hfactory /sics/$name/precision script "getmotpar $motor precision" "$motor precision " float 1
hsetprop /sics/$name read ::scobj::positmotor::reqVal report $motor
hsetprop /sics/$name report ::scobj::positmotor::rptVal ::scobj::positmotor::mot2ID $table /sics/$name/precision
hsetprop /sics/$name write ::scobj::positmotor::setVal ::scobj::positmotor::ID2mot $motor $table
hsetprop /sics/$name noResponse ${ns}::noResponse
hsetprop /sics/$name oldval "UNKNOWN"
hsetprop $scobjPath/$pindex oldval UNKNOWN
hsetprop $scobjPath/$pindex force_update True
# hsetprop $scobjPath/$pindex motprecision [SplitReply [samx precision]]
hfactory $scobjPath/$pindex/motprecision script "getmotpar $motor precision" "$motor precision " float 1
hfactory /sics/$name/status plain spy text
hset /sics/$name/status "IDLE"
hfactory $scobjPath/$pindex/lookup_table plain spy none
hsetprop $scobjPath/$pindex/lookup_table ID $table_ID
hsetprop $scobjPath/$pindex/lookup_table numpos [llength $posit_indices($motor)]
foreach posindex $posit_indices($motor) {
hfactory $scobjPath/$pindex/lookup_table/$posindex script "${ns}::pos2val $posindex $motor" "${ns}::setposindex $posindex $motor " float 1
hsetprop $scobjPath/$pindex/lookup_table/$posindex $staticpar $posit_label($motor,$posindex)
}
hfactory $scobjPath/$staticpar plain user float
hfactory $scobjPath/status plain spy text
hset $scobjPath/status IDLE
proc ${motor}_MOTEND {} [subst -nocommands {
if { [hval $scobjPath/status] == "BUSY"} {
# $sct_controller poll $scobjPath/$pindex 5
hset $scobjPath/status STOPPING
proc ${ns}::${motor}_MOTEND {} [subst -nocommands {
if { [hval /sics/$name/status] == "BUSY"} {
hset /sics/$name/status "STOPPING"
}
}]
publish ${ns}::${motor}_MOTEND user
scriptcallback connect $motor MOTEND ${ns}::${motor}_MOTEND
$sct_controller poll /sics/$name 2
$sct_controller write /sics/$name
}
$sct_controller poll $scobjPath/$pindex 2
$sct_controller write $scobjPath/$pindex
sicslist setatt $scobjName long_name $scobjName
::scobj::hinitprops $scobjName
::scobj::hinitprops $scobjName $pindex
::scobj::hinitprops $scobjName $staticpar
} message ] {
return -code error $message
proc ::scobj::positmotor::ID2mot {ID table} {
set UID [string toupper $ID]
foreach {i m} $table {
if {$UID == [string toupper $i]} {
return $m
}
}
namespace export mk_sct_positmotor
return "UNKNOWN"
}
proc ::scobj::positmotor::mot2ID {mot precision table} {
set firstMot [lindex $table 1]
set lastMot [lindex $table end]
if {abs($mot - $firstMot) <= $precision} {
return [lindex $table 0]
}
set sign [expr {$mot - $firstMot}]
set iprev [lindex $table 0]
set mprev [lindex $table 1]
foreach {i m} [lrange $table 2 end] {
if {abs($mot - $m) <= $precision} {
return $i
} elseif {[expr {$sign * ($mot - $m)} ] < 0} {
return [expr {($mot-$mprev)*($i - $iprev)/($m - $mprev)+$iprev}]
}
set iprev $i
set mprev $m
}
return -code error "lookup failed"
}
namespace import ::scobj::positmotor::*
##
# Eg
# hfactory /controllers plain spy none
#
# makesctcontroller /controllers/sct_mc1 std localhost:62034
# makesctcontroller sct_mc3 std localhost:62034
#
# mk_sct_positmotor sct_mc1 chi index { 1 0 2 15 3 20 }
# mkPosit sct_mc3 diameter float apx sample {2.5 0 5.0 -23 7.5 -47}