MATLAB Timer Function w/ Compiler

6 views (last 30 days)
Chris Yerges
Chris Yerges on 28 Jan 2020
Edited: Geoff Hayes on 28 Jan 2020
Here is the scenerio I am running into. I have a GUI with a start/stop button and an "indicator status light" that controls the start/stop of a timer function. If the light is red when the button is pushed then the timer is not running and it executes "SimTimerFcn" to start the timer. If it is green - it knows it needs to stop the timer and does that. The timer calls another funtion which looks at the contents of a folder to find files it needs to process. All this works great within MATLAB but when it complies it does not work... it seems like its not even trying to run the first iteration. I have tried wait and waitfor and nothing seems to be working... any ideas? I assume I am putting the wait statement in the wrong place or something but this one as thrown me for a loop. Thanks!
2020-01-28 12_54_28-Editor - C__Users_cyerg_Desktop_Metrics Processor_SimStartStop.m.png
2020-01-28 12_54_48-Editor - C__Users_cyerg_Desktop_Metrics Processor_SimTimerFcn.m.png
  6 Comments
Chris Yerges
Chris Yerges on 28 Jan 2020
I dont think it is... someting is not letting the timer get created or something under the complied condition. SimProcessMetrics gets the directories from the handles of the GUI on its own.... its not passed. The directories have nothing to do with the issue.
I converted the code to use a while loop to run SimProcessMetrics and it appears to be working so Im moving on for now but Id like to figure out what is causing the issue in the timer function.
Geoff Hayes
Geoff Hayes on 28 Jan 2020
Edited: Geoff Hayes on 28 Jan 2020
I wonder if this https://www.mathworks.com/matlabcentral/answers/283132-timer-does-not-work-in-the-exe-file#answer_221301 is the problem. You are creating a local variable timer in the SimTimerFcn and then as soon as that function completes, the timer is deleted. You may want to save the timer to the hMainGUI_Handles structure. So your SimTimerFcn code might look like
function SimTimerFcn
hMainGUI = getappdata(0, 'hMainGUI');
hMainGUI_handles = getappdata(0, 'hMainGUI_handles');
hMainGUI_handles.timer = timer;
% etc.
setappdata(0,'hMainGUI_handles', hMainGUI_handles);
start(hMainGUI_handles.timer);
Or something similar to that (I'm not sure if all the syntax is correct...)
You could also move the SimTimerFcn code to the SimStartStop function where you would already have access to the hMainGUI_handles.

Sign in to comment.

Answers (0)

Categories

Find more on Application Deployment in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!