Timer precedence during called functions

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

Antworten (3)

Walter Roberson
Walter Roberson am 3 Apr. 2012

2 Stimmen

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 Kommentare

Daniel Shub
Daniel Shub am 4 Apr. 2012
I am pretty sure a timer cannot interrupt itself. I am not sure if a timer can interrupt another time. I will have to think about how to test this.
Walter Roberson
Walter Roberson am 4 Apr. 2012
Good point, I should have said, "even handle graphic callbacks"
Daniel Shub
Daniel Shub am 4 Apr. 2012
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.

Melden Sie sich an, um zu kommentieren.

Jan
Jan am 4 Apr. 2012

2 Stimmen

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 Kommentar

Daniel Shub
Daniel Shub am 4 Apr. 2012
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.

Melden Sie sich an, um zu kommentieren.

Sean de Wolski
Sean de Wolski am 3 Apr. 2012

1 Stimme

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.

Kategorien

Mehr zu Entering Commands finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 3 Apr. 2012

Community Treasure Hunt

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

Start Hunting!

Translated by