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
0 个评论
回答(1 个)
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Platform and License 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!