Problem with Events and Callbacks
1 view (last 30 days)
Show older comments
Hello Everyone,
I am trying to use Events in MATLAB. I have created two classes. The first class(called: WSN_ENV) is responsible to build the object(nodes) for the second class(called: normal_node). The normal_node class is added to the event listeners which were created in the WSN_ENV. The problem is that when I want to trigger the event (by calling timer function from WSN_ENV) I get:
Warning: Error occurred while executing callback: Error using normal_node.timer Too many input arguments.
Here is my code for both classes. I really don't know what is the problem!
classdef WSN_ENV < handle
properties(GetAccess = 'public', SetAccess = 'public')
Number_of_BS=0;
Number_of_node=0;
global_timer=0;
node_obj=normal_node.empty;
end
events(ListenAccess = 'public', NotifyAccess = 'public')
time_event;
end
methods
%==========================================================================
% Constructor:
function src=WSN_ENV(BS,Node)
src.Number_of_BS=BS;
src.Number_of_node= Node;
for i=1:Node
src.node_obj(i)= normal_node(src,i);
end
end
%==========================================================================
function timer(obj)
obj.global_timer = obj.global_timer + 1;
notify(obj,'time_event'); % Broadcast notice of event
end
end
end
and the second Class:
classdef normal_node < handle
properties(GetAccess = 'public', SetAccess = 'public')
ID=0;
RF_stat='power_off';% power_on, listening
PWR_stat='sleep';% power_on
rx_buffer= 0;
tx_buffer= 0;
data=0;
local_timer=0;
watch_dog=0;
end
methods (Access ='public')
%==========================================================================
% Constructor:
function src=normal_node(ENV_obj,ID)
src.ID=ID;
src.RF_stat= 'power_on';
src.PWR_stat= 'power_on';
addlistener(ENV_obj,'time_event',@normal_node.timer);
end
end
methods (Static)
function obj=timer(obj)
obj.local_timer=obj.local_timer+1;
end
end
end
0 Comments
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!