Running Multiple timers in parallel (Parfeval) in MATLAB app designer GUI
46 次查看(过去 30 天)
显示 更早的评论
Hello,
I am working on building a GUI that allows me to interface to 7 of the same instruments (7 Current Drivers). I have built a class where I use the serialport to communicate to an instrument using VXI-11 Commands. The class contains different functions, each implementing a certain functionallity; connect, enable, set current, ramp current etc. The same class is used to connect to any of the instruments, in it is attached in Wavelength_QCLdriver_NewFirmware.m. The MATLAB GUI consists of 6 identical tabs, each containing connect buttons, enable buttons and fields to enter and display values.
My initial implementation for the GUI was soley based on callback functions for each field. Connect buttons instantiate the class using the appropriate instrument ID, and other callbacks access the object (property of the class) in order to access different functions. I would display values by doing the same, as I have functions in the class which query the current, voltage etc (The callbacks for each field would contain a while loop, continuously querying the required value). However, this was not a very scalable approach. After connecting to more than 2-3 current drivers, certain fields would not update, or certain buttons would not work. My feeling was the the callback que was getting filled up, and thus the GUI was slow to respond.
I therefore switched my approach to hoping to use a seperate timer for each tab, where the timer runs on a seperate worker (Instantiated using parpool and parfeval). The timer callback contains the parfeval function and the parfeval function calls back to the function needing to be executed periodically. This function uses flags ( 0 or 1, set using event callback functions of different buttons) to decide whether to actually enable, ramp current, or set current. There are thus 7 of such functions, each alson containing the code to display the required values.
The trouble is that the workers running each of these timer's can not access the graphics display, nor change properties of the app object. I am thus not able to access the Wavelength_QCLdriver_NewFirmware object which was instantiated outside of the timer (in the connect button callback), nor can I update values on the GUI. How can I then best try to run these expensive computations in the background asynchronously? Is there a way to still run timers on different workers and somehow pass the necessary data to the app object? Is there a different approach I am completely unaware of? I have attached the app designer code as QCL_GUI_2.mlapp
Resources wise I am using a Dell Precision Tower 7920 with a x64-based Intel(R) Xeon(R) Bronze 3204 CPU @ 1.90GHz and 16.0 GB of installed RAM. I believe I have plenty of compute available.
Any help would be appreciated. Thank you.
0 个评论
回答(1 个)
Akshat Dalal
2023-8-31
Hello Pawan,
I understand you are having some trouble in updating properties of the app object when you parallelize your application.
I believe this error is happening because the parallel pool workers cannot access the Application objects when you call your “timerCallback” functions using “parfeval”. This is a known issue, and a workaround can be found in the following MATLAB Answer - https://in.mathworks.com/matlabcentral/answers/2003857-running-multiple-timers-in-parallel-parfeval-in-matlab-app-designer-gui
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Web Services 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!