% Wait for data updates to complete (isDone = false if timeout, true if data ok)įunction isDone = waitForDone(object,timeout) % Delete the time object try stop (hTimer ) catch, end try delete (hTimer ) catch, end % Return the flag indicating whether or not timeout was reached end % waitForDone % waitfor is over - either because of timeout or because the data changed % To determine which, check whether the timer callback was activated % Wait for the object property to change or for timeout, whichever comes first % Create and start the separate timeout timer thread % Wait for data updates to complete (isDone = false if timeout, true if data ok) function isDone = waitForDone (object,timeout ) % Initialize: timeout flag = false The usage is the same as for regular HG handles: Although not documented, waitfor actually accepts handles not only of HG objects (e.g., figure handles) but also of other types of handles, such as regular Java reference handles. It turns out that waitfor can also be used in these cases. Waiting for events on non-HG objectsīut what if we need to wait for an event to happen on a non-Matlab (HG) object? Say on an ActiveX control property or even on a non-graphical Java object? Some toolboxes have other similar blocking functions, for example roipoly in the Image Processing toolbox. Other related built-in Matlab functions are waitforbuttonpress, pause (which awaits user mouse/keyboard clicks), and ginput, gtext, rbbox, dragrect (which awaits mouse clicks in a plot/image axes). uiwait, unlike waitfor, has an optional timeout parameter on the other hand, uiwait cannot wait for a non-deletion event on a regular uicontrol property, as waitfor can. uiwait similarly blocks execution, until a specified figure handle is deleted/closed, or a separate processing thread (typically, a callback function) calls the corresponding uiresume (I discussed uiwait/uiresume, together with their uisuspend/uirestore siblings, last year). waitfor is documented to block code execution until either the specified GUI handle object is deleted, or is updated (possibly to a specified value), or Ctrl-C is pressed in matlab’s Command Window. Matlab has a couple of built-in functions for blocking Matlab’s main processing thread until certain asynchronous GUI events occurs. A typical example is user mouse or keyboard actions in a GUI dialog window, or a specific signal that is received from hardware. This condition may depend on some external process that updates the condition asynchronously, meaning in a non-predictable (non-specific) time. It often happens that we need our program to wait for some condition to occur.
0 Comments
Leave a Reply. |