Calling a GUI callback function to run in parallel

5 次查看(过去 30 天)
Hello everyone,
I have two GUIs (GUI_main,GUI_slave) controlling two different hardware. Now I want to trigger a push button function in GUI_slave by using GUI_main. I managed to do this by copying the handles of GUI_slave into a global variable which is used for any interfacing with callbacks. I know it is not pretty still this works fine for me. Only problem it is sequential.
Any way to run this in parallel, so sending the trigger and GUI_main resumes it tasks? Or do I need to rewrite the program into subprograms to decouple it completely from the GUI? Note that GUI_slave has to show the user some sensor data while the hardware is running.
Cheers Mika

回答(1 个)

Walter Roberson
Walter Roberson 2016-9-15
If you have the Parallel Computing Toolbox then you can use spmd or parfeval to create multiple execution paths. However, if you invoked that from within a callback, both of those would still have the callback as the place to return to afterwards. One way around that is to have the main program uiwait() or waitfor() an event generated by the callback, so that you could at least get out of being within callbacks -- which makes a difference for whether other callbacks can interrupt.
However, the recommended method for handling something like this is to write the handling for the hardware in terms of callbacks such as BytesAvailableFcn that get called when the hardware has data available, or the similar callback that gets invoked when the previous data has been transmitted to the hardware. These callbacks would not run simultaneously, but the I/O would be handled asynchronously in such a setup, with it (at least in theory) being possible to put data into a buffer or send data from a buffer even while a callback for the other handware is running. You would generally prefer the callbacks to be short so the callbacks for the other hardware does not get queued, but not too short or you will waste too much time on the overhead of starting callbacks. Sometimes using timer callbacks can be a useful approach.
  2 个评论
Mikael Erkkilä
Mikael Erkkilä 2016-9-15
Thanks fo your answer. Hmm I get the point, yet in parallel computing mode there is no display output available without additional coding/hacking. Basically I only need a trigger signal, so that GUI_slave starts a predefined routine. Currently the user does this manually by clicking the start button first in gui_main and then in gui_slave...Eventually I will program a timer callback in gui_slave with a low time constant scanning for a trigger signal, if there is no better option available
Mikael Erkkilä
Mikael Erkkilä 2016-9-15
So I put the sensor readout into a timer callback function in GUI_slave and now GUI_main triggers the simpler run function in GUI_slave. Although this function is fast, now the GUI_main stays paused as long as the timer of GUI_slave isn't stopped. Any ideas how to solve this?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Platform and License 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by