diff --git a/source/EV3.m b/source/EV3.m index cc7bbbea30b1a469baaab625767c76c9b12b00cd..e551b3b3d57bc3e4453cc901038d0c55a34e3e0e 100644 --- a/source/EV3.m +++ b/source/EV3.m @@ -170,7 +170,8 @@ classdef EV3 < MaskedHandle if ev3.isConnected if isCommInterfaceValid(ev3.commInterface) - error('EV3::connect: Already connected.'); + warning('EV3::connect: Already connected. Resetting connection now...'); + ev3.disconnect(); else warning(['EV3::connect: EV3.isConnected is set to ''True'', but ',... 'comm handle is invalid. Deleting invalid handle and ' ,... @@ -241,8 +242,16 @@ classdef EV3 < MaskedHandle % b.connect('bt', 'serPort', '/dev/rfcomm0'); % |br| % % do stuff |br| % b.disconnect(); % |br| - - ev3.resetPhysicalBrick(); + + % Resetting needs a working connection in order to send reset-commands + % to the Brick. If the connection has been aborted (e.g. by pulling the + % USB-cord), the reset-methods would fail -> catch this error and for + % now do nothing. + try + ev3.resetPhysicalBrick(); + catch ME + % For now: ignore + end % Disconnect motors and sensors % -> set references to comm handle to 0