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
This commit is contained in:
Ferdi Franceschini
2008-08-29 22:09:19 +10:00
committed by Douglas Clowes
parent c53b56b97b
commit c6b5e65a71

View File

@@ -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