Auto Refresh in app designer.

I have a couple of controls in my GUI but it can also happen that I control my system manually (sometimes). So the below image shows the lamps 1 and 2 ON (set and read by GUI after setting) but the 3rd one has turned ON anytime. When I turn the 3rd one ON, I want the GUI to change the lamp color and also the switch direction. I know commands to change the color of the lamp and switch position, but I am not getting how can I introduce this sensing part in my GUI.
In other words, I need a refresh function that can refresh the GUI at an as fast a rate as it can and then change the lamp colors accordingly.
Please let me know your inputs. Thanks a lot, in advance!

8 Comments

> I know commands to change the color of the lamp and switch position, but I am not getting how can I introduce this sensing part in my GUI.
You don't need to externally monitor the states of the switches & lamps. If lap colors 1 & 2 should change when lamp 3 changes, and if lamp 3 is changed by the user, then the callback function to lamp 3 should also change lamps 1 and 2.
If an external function controls lamp 3, instead of changing it direclty it could call a local app function that controlls all of the lamp states.
Many of your 50 questions have reasonable answers that are not accepted and with no replies. Please take the time to provide feedback to the volunteers who are solving your problems by either accepting answers that worked or leaving comments so that people know what works and what doesn't work. See your list of questions.
>If an external function controls lamp 3, instead of changing it direclty it could call a local app function that controlls all of the lamp states.
I actually want the above. I have another MATLAB script running in parallel (which is not the GUI script but the GUI is still continuously running). If that MATLAB script turns on switch 3 then lamp 3 colors should change in the GUI as well, that is what I want. GUI and the other MATLAB scripts are not linked by any code.
So, I was thinking if I have a refresh callback function that can continuously sense which bit on the controller is high (and then change the switch direction to 'On' and lamp color to green). Of course, the GUI turning ON and OFF the switch and reading the status of the bit part is already done. But I'm wondering what I need to do when the bit is pulled up high not by the GUI but by an external user (using another MATLAB script in this case). In that case, too, my GUI should show the "correct status" of the lamps and switches. So my GUI should always know which bits are high/low. I have the commands to read the status which is why my GUI part is working. I need to add an additional feature to GUI which can help GUI read the status of bits always until GUI is running. Please let me know your inputs. Thanks.
Also, thanks for pointing out the MATLAB answers to my questions. I have reviewed a few, and still going through the rest. Hopefully, I will be done soon.
Can you edit the external function?
If so, instead of setting the lamp state directly within the external function, the external function can call a public function within your app. The public function would then controll all 3 lamp states. This is the most efficient and cleanest approach.
If the external function cannot be edited (which, I doubt is the case), you can set up a listener that triggers when there is a state change in lamp #3. See addlistener. This can be tricky to set up for the first time.
Thank you for explaining the situation. I understand now, and I think that I need an addlistener() because the external function is not under our control and hence cannot be edited.
I am trying to use the
addlistener(ROI, 'ROIMoved', @app.sense_callback)
where
sense_callback(app, parameters)
But I'm not sure how to use these as I don't have any ROI functions in my code and also I don't know how to do these work. I tried reading about this, but still unsure how to use them in my GUI. Could you please share some pointers? It would be great if you could tell me the command that I can use. Please let me know. Thanks.
What's ROI? I thought you were listening to the switch or the lamp?
BTW, I realized that the Value propery of both objects is not set to be obsevervable so I'm not quite sure how to set a listener up for those objects.
I don't know what is ROI either, which is what I said above. I am looking how can I use addlistener() (if I can)
J. Alex Lee
J. Alex Lee on 8 Jun 2021
Edited: J. Alex Lee on 8 Jun 2021
in response to built-in classes where the value is not observable, if you are using a matlab release that has the new custom ui component (https://www.mathworks.com/help/matlab/developing-custom-ui-component-classes.html), you can wrap your switches into a custom app where you can "fake" access into the switch value.
in fact, it probably makes sense to create a custom component anyway that bundles a switch with a lamp. a lamp doesn't appear to have a "Value" anyway.
by the way, i still do not understand the situation with the "external script that is not editable"...how exactly is it interacting with your hardware and/or gui?
For the lamp you'd listen to the color property (which is also not observable).
The only scenario I can imagine where this makes sense it's that OP is not the owner of the app nor the external script (I hope it's a function) and cannot make changes to either files and the switch can be changed by progresses not within OP's control.

Sign in to comment.

 Accepted Answer

J. Alex Lee
J. Alex Lee on 6 Jun 2021
in general for "auto refresh" you can use the timer object to schedule recurrent execution - disclaimer i have only played with this in non-GUI context with intent to eventually incorporate in a appdesigner app, but haven't got that far
but if you mean you have hardware switches that your GUI is supposed to be somehow connected to, and if you flip physical switch 3, you need the GUI switch 3 to know about it, maybe there are other/better mechanisms through the software/hardware interface

5 Comments

Thank you for your reply. I corrected my question to avoid any confusion. I need to refresh the GUI as fast as I can to sense and change the lamp colors accordingly. Please let me know your inputs. Thanks in advance.
While a timer could be used to continually check the states of the lamps, it would be inefficient and costly if you want it to indefinitely check the states as quickly as possible. It's not clear why you need something that monitors the lamp states.
Also, J. Alex Lee provided you with the link to the timer function so you can learn about its options and build it if you need it.
Thank you for your reply.
I have another MATLAB script running in parallel (which is not the GUI script but the GUI is still continuously running). If that MATLAB script turns on switch 3 then lamp 3 colors should change in the GUI as well, that is what I want. GUI and the other MATLAB scripts are not linked by any code.
So, I was thinking if I have a refresh callback function that can continuously sense which bit on the controller is high (and then change the switch direction to 'On' and lamp color to green). Of course, the GUI turning ON and OFF the switch and reading the status of the bit part is already done. But I'm wondering what I need to do when the bit is pulled up high not by the GUI but by an external user (using another MATLAB script in this case). In that case, too, my GUI should show the "correct status" of the lamps and switches. So my GUI should always know which bits are high/low. I have the commands to read the status which is why my GUI part is working. I need to add an additional feature to GUI which can help GUI read the status of bits always until GUI is running. Please let me know your inputs. Thanks.
you could give your other script access to your GUI switch to flip it on whenever it switches the actual switch, or if it is not allowed by appdesigner, you can provide a public method in your app that will do the switching that the second script can invoke
As I said, I cannot link the two by any means as the other script is not controllable. Also, the valve can be manually turned ON in which case what you are suggesting cannot work.

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2019b

Community Treasure Hunt

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

Start Hunting!