我的班级看起来像:
classdef linescan99 < handle
methods
function obj = linescan99(obj_watcher)
addlistener(obj_watcher,'Contact',@obj.handleEvnt);
end
function follower(obj)
while 1
%computations
end
end
end
end
我注意到,当跟随者功能执行时,班级无法收听可能发生的事件“联系”。不幸的是:这个事件会导致一个循环中断跟随者功能......
你知道如何强制该功能听取这个事件吗?也许在循环中?
非常感谢
........
classdef watcher < handle
properties
State = false
end
events
Contact
end
methods
function OnStateChange(obj,newState)
if newState ~= obj.State
obj.State = newState;
notify(obj,'Contact');
end
end
function follower(obj)
while 1
data=inputSingleScan(sessions_daq.NI_USB_1);
if data>3
obj.OnStateChange(true)
else
obj.OnStateChange(false)
end
end
end
end
end
和
classdef linescan99 < handle
properties
cam=videoinput('gige');
%several properties used in the function "follower"...
State = false
State2
end
methods
function obj = linescan99(obj_watcher)
addlistener(obj_watcher,'Contact',@obj.handleEvnt);
end
function handleEvnt(obj,obj_watcher,~)
if obj_watcher.State %contact
disp('linescan lancé')
obj.State2=true;
obj.suiveur
else
obj.State2=false;
end
end
function follower(obj)
preview(obj.cam)
while 1
image_camera=getsnapshot(obj.cam);
%computations...
if obj.State2
else
break %my goal is to break this while 1 loop when obj_watcher sends
%an event to obj_linscan99 which leads to: obj.State2=0
end
end
end
end
end