Commit feb2dfb6 authored by Maximilian Schnabel's avatar Maximilian Schnabel
Browse files

added killAllConnections() function to provide an easy fix to an error that...

added killAllConnections() function to provide an easy fix to an error that occured when trying to connect to a brick with an already established connection to another EV3 object
parent 27788d41
......@@ -172,20 +172,11 @@ classdef EV3 < MaskedHandle
%
% See also ISCONNECTED / :attr:`isConnected`
% save variables of base directory in vars
vars = evalin('base', 'whos');
for k = 1:length(vars)
% if another EV3 object exists, preemptively disconnect it to prevent connection error
if strcmp(vars(k).class, 'EV3')
evalin('base', [vars(k).name '.disconnect()'])
end
end
if ev3.isConnected
if isCommInterfaceValid(ev3.commInterface)
% Warning lead to confusion of students. Since brick connection is still working
% even if calling connect() multiple times, it is disabled.
% warning('EV3::connect: Already connected. Resetting connection now...');
warning('EV3::connect: Already connected. Resetting connection now...');
ev3.disconnect();
else
warning(['EV3::connect: EV3.isConnected is set to ''True'', but ',...
......@@ -235,6 +226,22 @@ classdef EV3 < MaskedHandle
end
end
function killAllConnections(ev3)
% Disconnects all existing EV3-object and its Motors and Sensors (within base workspace) from physical bricks.
% save variables of base directory in vars
vars = evalin('base', 'whos');
for k = 1:length(vars)
% if another EV3 object exists, preemptively disconnect it to prevent connection error
if strcmp(vars(k).class, 'EV3')
evalin('base', [vars(k).name '.disconnect()'])
end
end
end
function disconnect(ev3)
% Disconnects EV3-object and its Motors and Sensors from physical brick.
%
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment