TIMER.DLL is a MEX-file intended to create MATLAB callbacks caused by W95 timer events for asynchronous work, e.g. for real-time data acquisition using MATLAB. It allows MATLAB to connect Windows timer with arbitrary MATLAB evaluation string (similar to conventional MATLAB callbacks). As defined these callbacks will be executed asynchronously every time when appropriate timer event occurs.
TMCLOCK.M presents the simplest example for using timer.dll namely real-time digital clock.
PLATFORM : Windows 95/NT/2000/XP.
MATLAB VERSION : 5.1.
COPYRIGHT : School of Physics and Chemistry, Lancaster
AUTHOR : Dr Igor Kaufman
E-MAIL ADDRESS : I.KAUFMAN@LANCASTER.AC.UK
Igor Kaufman (2021). timer (https://www.mathworks.com/matlabcentral/fileexchange/349-timer), MATLAB Central File Exchange. Retrieved .
Gergely, The reason that you had a problem is that the Matlab engine is not threadsafe, and cannot be called from another thread. This timer implementation gets around that problem in a very tricky way.
The timer implementation uses a Win32 TimerProc to call mexEvalString(). Matlab requires the engine to be called from within the same thread as Matlab is running (the engine is not threadsafe). It just so happens that the TimerProc is dispatched from Matlab's event loop (see MSDN documentation), which is the same thread as Matlab is running in, and so the single thread requirement is satisfied.
I am looking for a way to insert events into Matlab's event queue. The outline of a method for Windows would be:
1) from any thread, create a timer with a very small (or zero) timeout
2) the timer callback will then execute within Matlab's thread, when Matlab's thread is next idle.
I tried to implement this method to trigger matlab calls from a separate thread in my mex file. But Im doing something wrong (2007b). It somehow losts 'connection' and messages are not received any more. Could you pin the important steps in your source?
Until Matlab introduced there own java version of a timer this has been the only timer avaialable fro matlab and of course if you compile your code then this is still the only choice. It underpins my companies whole Matlab application with timed calls to databases. Simply brilliant - never fails - 5 isn't a hig enough rating.
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!