Timer precedence during called functions

3 ビュー (過去 30 日間)
Sean
Sean 2012 年 4 月 3 日
Hello,
I have a timer that is pulling in video frames as a preview in a GUI. Unfortunately, I have found that if I call other functions, the timer waits until the function fully completes before executing. By this I mean that if I run a module to analyze the incoming video, the preview stops working until the analysis is completed.
Does anyone know how I can give the timer function precedence, so that it can perform its frame acquisition in between lines of called functions instead of waiting until they complete?
Thanks in advance, Sean

回答 (3 件)

Walter Roberson
Walter Roberson 2012 年 4 月 3 日
Which MATLAB version are you using? There was a major change in timer precedence somewhere around R2006b-ish .
But as Sean points out, timers cannot interrupt built-in functions. These days they can, however, interrupt regular .m functions, even callbacks.
  3 件のコメント
Walter Roberson
Walter Roberson 2012 年 4 月 4 日
Good point, I should have said, "even handle graphic callbacks"
Daniel Shub
Daniel Shub 2012 年 4 月 4 日
Callbacks are now wider than timers and graphics: handle objects, serial port objects, and audioplayer objects can all have callbacks. I think all callbacks except timers behave the same and operate out of the same thread.

サインインしてコメントする。


Jan
Jan 2012 年 4 月 4 日
Walter, Sean, Daniel: We need an exhaustive documentation of the timer precedence and the multi-threading effects e.g. concerning global 's in a timer callback. There must be a documentation anywhere already. It is time to publish it.
A bunch of drawnows is messy. How can we check the length of the event queue programmatically?
  1 件のコメント
Daniel Shub
Daniel Shub 2012 年 4 月 4 日
Yes we do. I use globals so infrequently, I don't even know how they work in standard callbacks.
As for the event queue, I think this should be a new question. I could see lots of uses for this. Even better if you could manipulate the queue. A couple of years ago Yair posted this: http://undocumentedmatlab.com/blog/matlab-and-the-event-dispatch-thread-edt/ which could be the start.

サインインしてコメントする。


Sean de Wolski
Sean de Wolski 2012 年 4 月 3 日
Set the timer's 'busymode' option to 'queue' so that the most recent event is queued. Then add a bunch of drawnows in your code to flush the queue while your code is running.
doc drawnow
This still will not interrupt functions such as mtimes or fft that don't check the queue (the same reason you can't ctrl+c out of it) but it will flush the timer events if its your own code blocking the timer.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by