Timer in app stalls while evaluating function

4 Ansichten (letzte 30 Tage)
Jane Sprigg
Jane Sprigg am 11 Aug. 2022
Beantwortet: Sanchari am 28 Dez. 2023
This is in Matlab 2022a. The function the timer calls sends a udp message and updates a plot. I'm hoping somebody recognizes this error because I'm having trouble telling where it's getting stuck. The timer stalls somewhere in this function (pollBoardA), and if I hit ctrl-c it breaks out and prints the following message. I can then restart the timer and everything works again. I have not found a reliable way to make this happen but it's happening pretty often. I suspect it's related to the plotting but haven't confirmed it yet since the problem is intermittent.
Operation terminated by user during pollBoardA
In timer/timercb (line 114)
feval(val{1}, obj, eventStruct, val{2:end});
In matlab.ui.internal.componentframework.services.optional.EventDispatcherAddOn>@()obj.ProxyView.sendEventToClient('flush',pvPairs) (line 77)
func = @() obj.ProxyView.sendEventToClient('flush', pvPairs);
In matlab.ui.internal.dialog.DialogHelper.dispatchWhenPeerNodeViewIsReady (line 276)
func()
In matlab.ui.internal.componentframework.services.optional.EventDispatcherAddOn/sendFlushEventToClient (line 79)
matlab.ui.internal.dialog.DialogHelper.dispatchWhenPeerNodeViewIsReady(model, obj.ProxyView, func, obj);
  7 Kommentare
Jane Sprigg
Jane Sprigg am 22 Aug. 2022
I can't lower the rate. Is there a limit in matlab on how fast I can request data?
Geoff Hayes
Geoff Hayes am 22 Aug. 2022
I'm not sure what (or if) there is a limit on how fast you can request data. If you could lower the rate, it would be interesting to see if the problem still occurs.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Sanchari
Sanchari am 28 Dez. 2023
Hello Jane,
I understand that you want to resolve the error message which indicates that the MATLAB operation was terminated due to a user interrupt (Ctrl+C) during the execution of the “pollBoardA” function.
Based on the provided information, it looks like is called by a timer callback. When you press Ctrl+C, MATLAB throws an error and displays the stack trace of where it was in the execution process when the interruption occurred.
The stack trace points towards an issue related to the timer callback and the flushing of events to the client, which is likely related to the graphics rendering or the GUI update.
Here are some steps you can take to troubleshoot and potentially resolve the issue:
  1. Isolate the Problem: Try to isolate the problem by temporarily removing the plotting code from the ‘pollBoardA’ function. If the timer no longer stalls, it suggests that the plotting is indeed related to the issue. You've mentioned that disabling plot updates did not resolve the issue, so the next step is to look at the UDP communication.
  2. Check UDP Operations: Ensure that UDP operations are not blocking the MATLAB thread. If the write operations to the UDP port are waiting for some event that never occurs, they could hang the function. You could add some debug prints before and after the UDP write calls to see if they are completing successfully.
  3. Use Asynchronous Plot Updates: The ‘drawnow’ function forces MATLAB to perform all pending graphical updates, which can be a blocking operation. Consider using ‘drawnow limitrate’ or ‘drawnow update’ to perform quicker, less resource-intensive updates.
  4. Debugging: Use MATLAB's debugging tools to set breakpoints and step through the ‘pollBoardA’ function to see exactly where it might be getting stuck.
  5. Error Handling: Implement error handling within your ‘pollBoardA’ function to catch any issues that arise during its execution. This can help prevent the timer from stalling.
  6. Check for Resource Leaks: Check if system resources are being exhausted. For example, if the buffer ‘app.bufferin’ grows indefinitely, it could be consuming too much memory, leading to performance issues.
  7. Check for Infinite Loops or Deadlocks: Ensure that there are no infinite loops or deadlocks within the callback or any related code, especially if there are dependencies between the timer callback and other parts of your application.
For more information on related queries, I recommend the following resources:
  1. App timer slows when mousing over plot: https://www.mathworks.com/support/search.html/answers/1814705-app-timer-slows-when-mousing-over-plot.html?fq%5B%5D=asset_type_name:answer&fq%5B%5D=category:matlab/desktop-tools-and-development-environment&page=1
  2. Ending a function after a time duration: https://www.mathworks.com/support/search.html/answers/291401-ending-a-function-after-a-time-duration.html?fq%5B%5D=asset_type_name:answer&fq%5B%5D=category:matlab/control-flow&page=1
  3. Appdesigner GUI issue code: https://www.mathworks.com/support/search.html/answers/1614760-appdesigner-gui-issue-code.html?fq%5B%5D=asset_type_name:answer&fq%5B%5D=category:matlab/app-designer&page=1
Hope this information is helpful to you!

Kategorien

Mehr zu Install Products finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by