From ef4f6463891cff9540325e4cd09c0c65dbc8292f Mon Sep 17 00:00:00 2001 From: Tim Stadtmann <tim.stadtmann@rwth-aachen.de> Date: Fri, 5 Aug 2016 17:40:09 +0200 Subject: [PATCH] Fix issues with undeleted comm interfaces On deletion/disconnect, communication-objects of lower layers are now properly deleted and disconnected. --- source/EV3.m | 17 +++++++++++------ source/Motor.m | 6 +++--- source/Sensor.m | 10 +++++----- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/source/EV3.m b/source/EV3.m index face392..2c9032c 100644 --- a/source/EV3.m +++ b/source/EV3.m @@ -127,6 +127,11 @@ classdef EV3 < handle ev3.init = 0; end + function delete(ev3) + if ev3.isConnected + ev3.disconnect(); + end + end %% Connection function connect(ev3, varargin) %connect Connects EV3-object and its Motors and Sensors to physical brick. @@ -152,8 +157,6 @@ classdef EV3 < handle ev3.brick = 0; ev3.isConnected = 0; - - % error('EV3::connect: Aborted connection.'); end end @@ -219,9 +222,9 @@ classdef EV3 < handle % b.disconnect(); % - if ~ev3.isConnected - error('EV3::connect: No brick connected.'); - end +% if ~ev3.isConnected +% error('EV3::connect: No brick connected.'); +% end % Disconnect motors % -> set references to brick object to 0 @@ -238,7 +241,9 @@ classdef EV3 < handle ev3.sensor4.disconnect(); % Delete handle to brick object - ev3.brick.delete(); + if isBrickValid(ev3.brick) && ev3.brick ~= 0 + ev3.brick.delete(); + end ev3.brick = 0; ev3.isConnected = 0; diff --git a/source/Motor.m b/source/Motor.m index c3b09d1..8625762 100644 --- a/source/Motor.m +++ b/source/Motor.m @@ -256,9 +256,9 @@ classdef Motor < handle % brickInterface.delete(); % Actual disconnecting!!! % - if ~motor.isConnected - error('Motor::disconnect: No brick connected.'); - end +% if ~motor.isConnected +% error('Motor::disconnect: No brick connected.'); +% end motor.brick = 0; % Note: actual deleting is done in EV3::disconnect. motor.isConnected = 0; diff --git a/source/Sensor.m b/source/Sensor.m index 55e67d1..f794ae8 100644 --- a/source/Sensor.m +++ b/source/Sensor.m @@ -136,9 +136,9 @@ classdef Sensor < handle function disconnect(sensor) %disconnect Disconnects Sensor-object from physical brick - if ~sensor.isConnected - error('Sensor::disconnect: No brick connected.'); - end +% if ~sensor.isConnected +% error('Sensor::disconnect: No brick connected.'); +% end sensor.brick = 0; % Note: actual deleting is done in EV3::disconnect. sensor.isConnected = 0; @@ -163,8 +163,8 @@ classdef Sensor < handle if strcmp(class(oldMode),class(newMode)) && oldMode~=newMode if ~strcmp(class(oldMode), 'DeviceMode.Error') && ... ~strcmp(class(newMode), 'DeviceMode.Error') - warning(['Sensor::update: Physical sensor''s mode was not ',... - 'the specified one. Changing...']); + %warning(['Sensor::update: Physical sensor''s mode was not ',... + % 'the specified one. Changing...']); sensor.setMode(oldMode); sensor.mode = oldMode; -- GitLab