Configure a callback in App Designer to be non-interruptable

조회 수: 23 (최근 30일)
Gavin
Gavin 2025년 7월 17일
댓글: Walter Roberson 2025년 11월 4일
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?

채택된 답변

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()
  댓글 수: 5
Gavin
Gavin 2025년 11월 4일
app.status is initialized during startup and well managed.
Data typing is handled in the code, structures are initialized as needed.
e.g.
function InitInBuffer(app)
% Clean out InBuffer reset pointers
app.InBuffer = zeros(40, 2); % Circular Array init
app.InPtr = 1; % Where to read
app.OutPtr = 1; % Where Pico Data goes
app.BFEmpty = true; % No data yet
end
The circular buffer is handled correctly.I use it to get data out of the Windows USB buffer where I can deal with in in my own time. Type isn't changed to a char until it's read from the buffer.
Typ = char(app.InBuffer(app.OutPtr,1));
if ~isletter(Typ) % manage possible error (it never happens)
And BTW the PicoInput code is about 80 lines so not going to fit on one line.
Hasn't been a problem any more with ML2025
Walter Roberson
Walter Roberson 2025년 11월 4일
function InitInBuffer(app)
% Clean out InBuffer reset pointers
app.InBuffer = zeros(40, 2); % Circular Array init
You are not returning app from the function, and app is not a global variable or a shared variable. All changes to app will be lost when the funtion returns.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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