Skip to content
Snippets Groups Projects
Commit d907c14d authored by Maximilian Schnabel's avatar Maximilian Schnabel
Browse files

preemptively disconnect other EV3 objects before trying to establish a connection

parent 2b04e204
No related branches found
No related tags found
2 merge requests!7Keep going if mountpoint exists (persistent),!6Docs NXT compatibility
......@@ -35,20 +35,19 @@ classdef EV3 < MaskedHandle
% batteryValue (numeric): Current battery charge. Depending on batteryMode, the reading is either in percentage or voltage. See also :attr:`batteryMode`. *[READ-ONLY]*
% isConnected (bool): True if virtual brick-object is connected to physical one. *[READ-ONLY]*
%
% ::
%
% Example:
% # This example expects a motor at port A and a (random) sensor at port 1
% brick = EV3();
% brick.connect('usb');
% motorA = brick.motorA;
% motorA.setProperties('power', 50, 'limitValue', 720);
% motorA.start();
% motorA.waitFor();
% disp(brick.sensor1.value);
% brick.beep();
% delete brick;
%
% Example:
% % This example expects a motor at port A and a (random) sensor at port 1 |br|
% b = EV3(); % |br|
% b.connect('usb'); % |br|
% ma = b.motorA; % |br|
% ma.setProperties('power', 50, 'limitValue', 720); % |br|
% ma.start(); % |br|
% % fun |br|
% ma.waitFor(); % |br|
% disp(b.sensor1.value); % |br|
% b.beep(); % |br|
% delete b; % |br|
properties
% batteryMode (string in {'Percentage', 'Voltage'}): Mode for reading battery charge. [WRITABLE]
......@@ -159,24 +158,28 @@ classdef EV3 < MaskedHandle
% (necessary if connectionType is 'bt'). *[OPTIONAL]*
% beep (bool): If true, EV3 beeps if connection has been established. *[OPTIONAL]*
%
%
% ::
%
% Example:
% % Setup bluetooth connection via com-port 0
% brick = EV3();
% brick.connect('bt', 'serPort', '/dev/rfcomm0');
% % Setup usb connection, beep when connection has been established
% brick = EV3();
% brick.connect('usb', 'beep', 'on', );
% Example:
% % Setup bluetooth connection via com-port 0 |br|
% b = EV3(); % |br|
% b.connect('bt', 'serPort', '/dev/rfcomm0'); % |br|
% % Setup usb connection, beep when connection has been established
% b = EV3(); % |br|
% b.connect('usb', 'beep', 'on', ); % |br|
%
% 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 ',...
......@@ -232,14 +235,11 @@ classdef EV3 < MaskedHandle
% Notes:
% * Gets called automatically when EV3-object is destroyed.
%
%
% ::
%
% Example:
% brick = EV3();
% brick.connect('bt', 'serPort', '/dev/rfcomm0');
% % do stuff
% brick.disconnect();
% Example:
% b = EV3(); % |br|
% b.connect('bt', 'serPort', '/dev/rfcomm0'); % |br|
% % do stuff |br|
% b.disconnect(); % |br|
% 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
......@@ -281,13 +281,10 @@ classdef EV3 < MaskedHandle
% Notes:
% * This equals playTone(10, 1000, 100).
%
%
% ::
%
% Example:
% brick = EV3();
% brick.connect('bt', 'serPort', '/dev/rfcomm0');
% brick.beep();
% Example:
% b = EV3(); % |br|
% b.connect('bt', 'serPort', '/dev/rfcomm0'); % |br|
% b.beep(); % |br|
%
ev3.handleCommand(@soundPlayTone, 10, 1000, 100);
end
......@@ -300,13 +297,11 @@ classdef EV3 < MaskedHandle
% frequency (numeric in [250, 10000]): in Hertz
% duration (numeric > 0): in milliseconds
%
%
% ::
%
% Example:
% brick = EV3();
% brick.connect('bt', 'serPort', '/dev/rfcomm0');
% brick.playTone(40, 5000, 1000); % Plays tone with 40% volume and 5000Hz for 1 second.
% Example:
% b = EV3(); % |br|
% b.connect('bt', 'serPort', '/dev/rfcomm0'); % |br|
% b.playTone(40, 5000, 1000); % Plays tone with 40% volume and 5000Hz for 1
% second. |br|
%
ev3.handleCommand(@soundPlayTone, volume, frequency, duration);
end
......@@ -314,14 +309,11 @@ classdef EV3 < MaskedHandle
function stopTone(ev3)
% Stops tone currently played.
%
%
% ::
%
% Example:
% brick = EV3();
% brick.connect('bt', 'serPort', '/dev/rfcomm0');
% brick.playTone(10,100,100000000);
% brick.stopTone(); % Stops tone immediately.
% Example:
% b = EV3(); % |br|
% b.connect('bt', 'serPort', '/dev/rfcomm0'); % |br|
% b.playTone(10,100,100000000); % Accidentally given wrong tone duration :) |br|
% b.stopTone(); % Stops tone immediately. |br|
%
ev3.handleCommand(@soundStopTone);
end
......@@ -332,16 +324,12 @@ classdef EV3 < MaskedHandle
% Returns:
% status (bool): True if a tone is being played
%
%
% ::
%
% Example:
% brick = EV3();
% brick.connect('bt', 'serPort', '/dev/rfcomm0');
% brick.playTone(10, 100, 1000);
% pause(0.5);
% % Small pause necessary since tone not startong immediately
% brick.tonePlayed(); % -> Outputs 1 to console.
% Example
% b = EV3(); % |br|
% b.connect('bt', 'serPort', '/dev/rfcomm0'); % |br|
% b.playTone(10, 100, 1000); % |br|
% pause(0.5); % Small pause is necessary as tone does not start instantaneously |br|
% b.tonePlayed(); % -> Outputs 1 to console. |br|
%
status = ev3.handleCommand(@soundTest);
end
......@@ -393,14 +381,11 @@ classdef EV3 < MaskedHandle
% debug (numeric in {0,1,2}): see EV3.debug *[OPTIONAL]*
% batteryMode (string in {'Voltage'/'Percentage'}): see EV3.batteryMode *[OPTIONAL]*
%
%
% ::
%
% Example:
% brick = EV3();
% brick.connect('bt', 'serPort', '/dev/rfcomm0');
% brick.setProperties('debug', 'on', 'batteryMode', 'Voltage');
% % Instead of: b.debug = 'on'; b.batteryMode = 'Voltage';
% Example:
% b = EV3(); % |br|
% b.connect('bt', 'serPort', '/dev/rfcomm0'); % |br|
% b.setProperties('debug', 'on', 'batteryMode', 'Voltage'); % |br|
% % Instead of: b.debug = 'on'; b.batteryMode = 'Voltage'; % |br|
%
% See also EV3.DEBUG, EV3.BATTERYMODE / :attr:`debug`, :attr:`batteryMode`
......@@ -532,4 +517,4 @@ classdef EV3 < MaskedHandle
end
end
end
end
end
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment