From c6b5e65a7178ed40e0cf1da37487f1127b2c3fd4 Mon Sep 17 00:00:00 2001 From: Ferdi Franceschini Date: Fri, 29 Aug 2008 22:09:19 +1000 Subject: [PATCH] SICS-264 Allow sequencing of motors while counting A "waitfor" command has been implement which waits for an object to finish after running the given command. r2687 | ffr | 2008-08-29 22:09:19 +1000 (Fri, 29 Aug 2008) | 3 lines --- site_ansto/instrument/util/eventutil.tcl | 54 ++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 site_ansto/instrument/util/eventutil.tcl diff --git a/site_ansto/instrument/util/eventutil.tcl b/site_ansto/instrument/util/eventutil.tcl new file mode 100644 index 00000000..441e7718 --- /dev/null +++ b/site_ansto/instrument/util/eventutil.tcl @@ -0,0 +1,54 @@ +# TODO Maybe add ::event::onstart and ::event::onfinish commands to execute some +# code when an object starts or finishes +# eg +# onstart hmm { do something } + +namespace eval event { + variable sobjBusy + variable END_EVENT + + set sobjBusy 0 + array set END_EVENT {Motor MOTEND HistMem COUNTEND SingleCounter COUNTEND} + namespace export waitfor +} + +proc ::event::waitCB {args} { + variable sobjBusy + set sobjBusy 0 +} +publish ::event::waitCB user + +## +# @brief Wait for a sics object to finish what it's doing. +# waitfor hmm {histmem start} +# waitfor {samx samz} {run samx 3 samz 4} +proc ::event::waitfor {sobj args} { + variable END_EVENT + variable sobjBusy + + if [ catch { + set valid_sobjType [array names END_EVENT] + set sobjType [SplitReply [sicslist $sobj type] ] + if {[lsearch $valid_sobjType $sobjType ] == -1} { + error "ERROR: You can only wait for the following types of objects $valid_sobjType" + } + set CBID [SplitReply [scriptcallback connect $sobj $END_EVENT($sobjType) ::event::waitCB ] ] + set sobjBusy 1 + set oldStatus [lindex [SplitReply [status]] 0] + eval $args + while {$sobjBusy == 1} { + wait 2 + } + scriptcallback remove $sobj $CBID + SetStatus $oldStatus + } message ] { + scriptcallback remove $sobj $CBID + SetStatus $oldStatus + if {$::errorCode=="NONE"} {return "Return: $message"} + return -code error "Caught $message" + } +} + +namespace import ::event::waitfor + +publish waitfor user