Reputation: 11
I have a MATLAB script that connects to an external machine and starts an operation like so:
% Connecting and initialising...
machine.Go()
% wait function until 'End' event
% Rest of script...
The machine should raise an event at the end of the operation. After the operation ends with an event End
I want to execute the rest of my script.
The documentation (from the machine) says that an event handler should be of the form:
void EventHandler(object sender, EventArgs args)
which seems quite generic. I'm not familiar with events and handlers.
What is the best way to make MATLAB wait until this End
event occurs?
I have seen a couple of solutions with timers, but I don't want to use these as the operations are of varying lengths. I also don't want to use a while loop as this seems inefficient.
Thanks,
Upvotes: 0
Views: 401
Reputation: 11
Managed it with this:
t = timer('TimerFcn',@(~,~)disp('This is the timer callback function.'),'StartDelay',100000);
start(t);
% Create a listener for CollectionEnd event that will interrupt this timer
addlistener(fc,'End',@(~,~)stop(t));
% Wait until timer stopped
wait(t);
Upvotes: 1