Timer precedence during called functions

2 次查看(过去 30 天)
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.

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by