From 879220a1c153d24c0be5300d2b24df982dcf8d1a Mon Sep 17 00:00:00 2001
From: Tim Stadtmann <tim.stadtmann@rwth-aachen.de>
Date: Sun, 28 May 2017 14:46:16 +0200
Subject: [PATCH] Fix issue #48

---
 source/EV3.m | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/source/EV3.m b/source/EV3.m
index cc7bbbe..e551b3b 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
-- 
GitLab