Configure a callback in App Designer to be non-interruptable

6 次查看(过去 30 天)
I'm using USB connected Arduino device and have the following line:
configureCallback(app.PicoCom,"terminator",@app.PicoInput);
The function app.PicoInput does it's job, but I would like it to complete before going back to the main program. If a function has a component that calls it then the function will be the "callback area" of the app and the component has callback execution control. Since this function is called by an interrupt and is set up by startupFcn(app) it doesn't have a component. How can I make it non-interruptable without messing with flags and mutex?

回答(1 个)

Walter Roberson
Walter Roberson 2025-7-18
The secrets to making a function uninterruptible is:
  • write the code all on one line. MATLAB checks for interrupts at the beginning of each line of code, so if you write it all on one line then there will be no opportunity to interrupt
  • write the code entirely in terms of built-in functions. You might have prevented interrupts by writing all on one line, but if what you are calling is MATLAB code that was written on multiple lines then MATLAB will be checking for interrupts at the beginning of those lines.
  • do not call pause() or uifigure() or figure() or uiwait() or waitfor() or drawnow()
  3 个评论
Walter Roberson
Walter Roberson 2025-7-19
if (app.status == 2) || (app.status == 3) % Running (finishing) a trial?
It is not obvious that app.status is defined at that point.
app.InBuffer(app.InPtr,1) = app.PicoType;
app.InBuffer(app.InPtr,2) = app.PicoData;
It is not obvious that app.InBuffer has been defined at that point.
Those are two different data types. If app.InBuffer has not been defined before this, then app.InBuffer will be initialized to the first type assigned to it, which would be uint8. You would need to initialize to uint32 to fit app.PicoData
Walter Roberson
Walter Roberson 2025-7-19
if ch(2:2)=='H' % #Help! ..Pico not connected correctly
It bugs me that that is not an "elseif" ;-)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Dialog Boxes 的更多信息

产品


版本

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by