Notifying parent from children's callbacks?
1 view (last 30 days)
Show older comments
I have a handle class that contains one or more instrument objects (e.g., serial, udp, etc). I.e.,:
classdef my_class < handle
properties (Transient)
port1;
port2;
end
methods
function obj = my_class(ipaddr, port_num)
obj.port1 = udp(ipaddr, port_num);
obj.port2 = ....
end
process_data(obj,src, event); %Defined elsewhere
%the rest of the class goes in here
end
(I have this framework for a number of different instruments, each with it's own set of different ports, properties, etc.)
I can setup BytesAvailableFunction callbacks for the two ports that trigger when incoming data is available. I have no trouble with that. What I'd like to figure out how I can trigger a callback at the my_class level (i.e., to trigger process_data(...)).
Some thoughts:
- I was thinking that there may be a way to do this with events and listeners, but I haven't worked extensively with with this aspect of Matlab's OOP before. But because the event trigger object has to have and 'events' block in it's classdef, I couldn't see how this would work. Would I have to sub-class udp, serial, etc. just to add the events blocks? That approach seems cumbersome.
- Another approach that just occurred to me is to use findobj from within the portN callback, to locate the parent. It doesn't seem particularly elegant, but I'd imagine it might work.
- One other option is just to give the ports a copy of the my_class handle (Are there recursive implications?). I.e.:
%In the constructor for my_class
obj.port1.UserData.Parent = obj;
Thanks for your help.
John
0 Comments
Answers (0)
See Also
Categories
Find more on MATLAB Mobile in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!