From f2590461b5e05e18fc27376514dc99b77cef2d76 Mon Sep 17 00:00:00 2001 From: Ferdi Franceschini Date: Wed, 14 Jan 2015 13:27:26 +1100 Subject: [PATCH] Make sure oneshot_state = 1 while a callback is waiting for an event. --- site_ansto/instrument/util/eventutil.tcl | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/site_ansto/instrument/util/eventutil.tcl b/site_ansto/instrument/util/eventutil.tcl index c8ff73f3..01083507 100644 --- a/site_ansto/instrument/util/eventutil.tcl +++ b/site_ansto/instrument/util/eventutil.tcl @@ -70,6 +70,7 @@ scriptcallback connect exe BATCHEND ::batch::call_cleanup # This is meant to be called from the read command on an hdb node. It must be # called everytime the node is polled so that the oneshot callback can be # removed if the given event fails to occur within the allowed time. +# NOTE: set event parameter to 'fatal_error' to signal an error and remove the callback. # @param hpath hdb path to a node which regularly calls this procedure. # @param event an event which may trigger a callback. # @param args is a list of arguments which will be passed to the callback. @@ -98,10 +99,10 @@ proc call_oneshot {hpath event args} { hdelprop $hpath oneshot_cb hsetprop $hpath oneshot_state -1 return -1 - } else { - hsetprop $hpath oneshot_state 1 - return 1 } + } else { + hsetprop $hpath oneshot_state 1 + return 1 } } } @@ -113,13 +114,16 @@ proc call_oneshot {hpath event args} { # @param cb_proc name of the callback procedure # @param trigger event for callback # @param timeout the callback is removed when the timeout expires. +# If timeout < 0 then the callback won't timeout but you can force it to be +# removed by calling set_oneshot again with timeout = 0. # If timeout = 0 the callback will only be called if the trigger event occurs -# the first time the node is polled. If timeout < 0 then the callback will be -# called if the trigger event occurs and then it is removed. +# the first time the node is polled. If there is no trigger event then the +# callback is simply removed. proc set_oneshot {hpath cb_proc event {timeout 60}} { hsetprop $hpath oneshot_cb $cb_proc hsetprop $hpath oneshot_timeout $timeout hsetprop $hpath oneshot_start_time [hgetpropval $hpath read_time] hsetprop $hpath oneshot_trigger $event + hsetprop $hpath oneshot_state 1 } publish set_oneshot user