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

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -