MATLAB - destroy listener after force quit ctrl+c -
i working on matlab script temperature acquisition ni device. use listener run callback function refreshing chart. when ctrl+c, main script stops following error: "undefined function 'wait' input arguments of type 'event.listener'.". problem listener still trigger events, chart keeps refreshing.
i've tried catch try/catch , used oncleanup function delete listener, without success.
can give me advices please? :)
edit : here code
s = daq.createsession('ni'); s.addanaloginputchannel('cdaq1mod1', 0, 'thermocouple'); s.rate = 7; s.durationinseconds = 5; s.channels.thermocoupletype = 't'; s.channels.units = 'celsius'; lh = addlistener(s,'dataavailable',@plotdata); ocu = oncleanup(@() delete(lh)); s.startbackground(); try wait(s); catch delete(lh); end
to allow code respond gracefully ctrl+c, try attaching callback erroroccurred
event stops session:
... errlistener = addlistener(s, 'erroroccurred', @(~, ~) stop(s)); s.startbackground(); wait(s);
Comments
Post a Comment