Repeatedly call a function in App Designer while working with the App

조회 수: 25 (최근 30일)
Konvictus177
Konvictus177 2022년 10월 28일
댓글: Florian Bidaud 2022년 11월 21일
Hi,
I created an app in app designer that has buttons to load, plot, process and analyze data.
How do I implement a function into the app that runs every second while the user can simultaneously work with the app and click on buttons, load data, etc.
I want the app to continously do something regardless of what action the user takes on the app. The app is supposed to communicate with a PLC, read and then send back a signal continuously every second after startup of the app. When the app crashes or is closed the function wont be called anymore.
Thanks.

답변 (1개)

Florian Bidaud
Florian Bidaud 2022년 10월 28일
편집: Florian Bidaud 2022년 10월 28일
Hi
Have a look a these:
I can think of roundabouts to avoid using the background pool but they won't do exactly what you want.
  댓글 수: 2
Konvictus177
Konvictus177 2022년 11월 2일
편집: Konvictus177 2022년 11월 2일
I implemented a private function in my app that reads certain data from plc and sends data to plc.
In my app startup function I created a timer object that calls this read & send function every second.
This seems to be doing exactly what I want without using background pool. Only thing I have noticed is that when I update a table on my gui the read&send data function is not doing its jobs for a few milliseconds. Would background pool be able to solve this issue?
While this function is continuously running, the user can do other stoff on the app interface such as select data, plot data, .... etc.
Florian Bidaud
Florian Bidaud 2022년 11월 21일
Sorry to answer that late,
But yes, with the function parfeval, you can call a function in another pool, while keep running your app as usual.
Let's say the code you want to run can be written as [Y1,Y2] = function calculationBackground(X1,X2,X3), you could call
F = parfeval(@calculationBackground, 2, X1,X2,X3)
and then get the results with
[Y1,Y2] = fetchOutputs(F)
For your application you will need to include the pause inside that background function

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

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by