Clear Filters
Clear Filters

Timer is interrupted, but only sometimes, by other functions

4 views (last 30 days)
I have an application with a GUI which needs, among other things, to communicate via a serial port with hardware A and hardware B (two different ports).
This timer is created at the start of the application and assigned the function to be run every cycle. That function, communicates with hardware A, just to get the state of a sensor.
The timer is never interrupted when the application is running by anything I do. I can use the application normally, and the timer will ask the state of the sensor to hardware A every second (or another perior I set).
However, if click the button with a callback that makes a request from hardware B (get some data), then the timer function waits for that callback to be finished before it continues running.
This is very inconsistent behaviour. I've seen this question/answer and I believe it's related.
Can anyone explain why this happens?
  2 Comments
Gilberto Pin
Gilberto Pin on 27 Nov 2020
Edited: Gilberto Pin on 27 Nov 2020
Dear riverCN, I had the very same problem with GUIs written in appdesigner. This misbehavior was not affecting GUIs written in guide. It seems that the GUI callback, end even updates of graphical objects, in appdesigner blocks the execution of timers that instead are supposed to run in background (or in another thread). Two questions for the development team of Mathworks:
  • Is the appdesigner GUI running in the same thread of timer-objects or command-line exec thread?
  • OR Is the appdesigner GUI running raising some wait-to-complete flag (semaphores/mutex, whatever you are using) to pause the timer objects or the command-line exec thread?
This is really annoying, indeed
riverCN
riverCN on 27 Nov 2020
Edited: riverCN on 27 Nov 2020
Hi Gilberto.
I actually used GUIDE for this app.
Additionally, I tested this problem in more simple GUI versions, both created purely programatically and also generated with GUIDE. I can update graphical objects, and even have callbacks that call the pause function, without ever interrupting the timer.
However, in more complex callback functions (which never contain any reference to the timer function), I get the timer interrupted. I am not sure if it can be caused by the communication via serial port or not... but I cannot find any documentation on this behavior.
Edit: To be clear, it's not the communication that it's delayed - it's really the timer function that stops during the execution of other, completely unrelated, callback.

Sign in to comment.

Answers (0)

Categories

Find more on App Building 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!