diff --git a/source/BrickIO.m b/source/BrickIO.m index ebdb054b682f28d8dc5562de9e9dad224011b9ae..a5ee1129a0a23170da017785296ab079924794be 100755 --- a/source/BrickIO.m +++ b/source/BrickIO.m @@ -11,7 +11,7 @@ % - The read function should return a uint8 datatype % - The write function should be given a uint8 datatype as a parameter -classdef BrickIO < handle +classdef BrickIO < MaskedHandle properties (Abstract) % time-out period (if 0, no time-out) timeOut diff --git a/source/CommunicationInterface.m b/source/CommunicationInterface.m index 7c222a597212222473fcdaa81dd71dccbccfc9ac..1ae2fe7306978afcfb648ab6a74f5f6a0c29fbdc 100755 --- a/source/CommunicationInterface.m +++ b/source/CommunicationInterface.m @@ -128,13 +128,6 @@ classdef CommunicationInterface < handle % b = CommunicationInterface(...) is an object that represents a connection % interface to a Lego Mindstorms EV3 brick. % - % Options:: - % 'debug' Debug level, show communications packet - % 'ioType' IO connection type, either usb, wifi or bt - % 'deviceName' Bluetooth brick device name - % 'channel' Bluetooth connection channel - % 'serPort' Serial port connection - % % Notes:: % - Can connect through: usbBrickIO, btBrickIO % - For USB connection: @@ -200,7 +193,7 @@ classdef CommunicationInterface < handle defaultSerPort = '/dev/rfcomm0'; defaultBTDevice = 'EV3'; defaultBTChannel = 1; - if(ispc) + if(ispc && license('test', 'instr_control_toolbox')) defaultBackend = 'instrumentControl'; else defaultBackend = 'serial'; diff --git a/source/btBrickIO.m b/source/btBrickIO.m index 5ed51f7a3615249ff424ad20707af4bea48ad16a..0625c3f7cbf774fd26aca90f263b417975c9ed80 100755 --- a/source/btBrickIO.m +++ b/source/btBrickIO.m @@ -1,44 +1,51 @@ -%btBrickIO Bluetooth interface between MATLAB and the brick -% -% Methods:: -% -% btBrickIO Constructor, initialises and opens the bluetooth connection -% delete Destructor, closes the bluetooth connection -% -% open Open a bluetooth connection to the brick -% close Close the bluetooth connection to the brick -% read Read data from the brick through bluetooth -% write Write data to the brick through bluetooth -% -% Example:: -% btbrick = btBrickIO(1,'/dev/rfcomm0') -% -% Notes:: -% - Connects to the bluetooth module on the host through a serial -% connection. Hence be sure that a serial connection to the bluetooth -% module can be made. Also be sure that the bluetooth module can be paired -% to the brick before MATLAB is opened. -% - Works under mac and potentially linux (have yet to find a suitable -% bluetooth device that can pair with the brick under linux). -% - Does not work under windows (will need to either virtualise the serial -% bluetooth port or use the instrumentation and control toolbox BrickIO -% version). - classdef btBrickIO < BrickIO + % Bluetooth interface between MATLAB and the brick + % + % Notes: + % * Connects to the bluetooth module on the host through a serial + % connection. Hence be sure that a serial connection to the bluetooth + % module can be made. Also be sure that the bluetooth module has been paired + % to the brick before trying to connect. + % * Usage is OS-dependent: + % + % - Windows: the deviceName- & channel-properties are needed for connection. The + % implementation is based on the Instrument Control toolbox. + % - Linux (and potentially Mac): serialPort-property is needed for connection. The + % implementation is based on MATLAB's serial port implementation. + % + % Attributes: + % debug (bool): If true, each open/close/read/write-call will be noted in the console. + % serialPort (string): Path to the serial-port object (default: '/dev/rfcomm0'). Only + % needed when using MATLAB's serial class (i.e. on linux/mac). + % deviceName (string): Name of the BT-device = the brick (default: 'EV3'). Only + % needed when using the Instrument Control toolbox (i.e. on windows). + % channel (numeric > 0): BT-channel of the connected BT-device (default: 1). Only + % needed when using the Instrument Control toolbox (i.e. on windows). + % timeOut (numeric >= 0): seconds after which a timeout-error occurs if no packet could be + % read. + % backend ('serial'|'instrumentControl'): Backend this implementation is based on. Is + % automatically chosend depending on the OS ('serial' for linux/mac, + % 'instrumentControl' for windows). + % + properties - % debug input + % debug (bool): If true, each open/close/read/write-call will be noted in the console. debug; - % bluetooth serial port (used if backend == 'serial') + % Path to the serial-port object (default: '/dev/rfcomm0'). Only + % needed when using MATLAB's serial class (i.e. on linux/mac). serialPort; - % bluetooth brick device name (used if backend == 'instrumentControl') + % deviceName (string): Name of the BT-device = the brick (default: 'EV3'). Only + % needed when using the Instrument Control toolbox (i.e. on windows). deviceName; - % bluetooth connection channel (used if backend == 'instrumentControl') + % channel (numeric > 0): BT-channel of the connected BT-device (default: 1). Only + % needed when using the Instrument Control toolbox (i.e. on windows). channel; - % time-out period in seconds (if 0, no time-out) + % timeOut (numeric > 0): seconds after which a timeout-error occurs if no packet could be + % read. timeOut; - % use implementation based on the serial-connection implementation by MATLAB (should - % work on mac & linux) or based on the Instrumentation & Control Toolbox - % (should work on windows) (-> 'serial'|'instrumentControl') + % backend ('serial'|'instrumentControl'): Backend this implementation is based on. Is + % automatically chosend depending on the OS ('serial' for linux/mac, + % 'instrumentControl' for windows). backend; end @@ -63,7 +70,7 @@ classdef btBrickIO < BrickIO p.addOptional('deviceName', 'EV3'); p.addOptional('channel', 1); p.addOptional('timeOut', 10); - if(ispc == 1) + if(ispc && license('test', 'instr_control_toolbox')) p.addOptional('backend', 'instrumentControl'); else p.addOptional('backend', 'serial'); diff --git a/source/usbBrickIO.m b/source/usbBrickIO.m index 6a7a7c5f95d4707b61b96bbe8c36865755e32db9..d2c5fb245158cebf803fec35ebef9a796e1b49ef 100755 --- a/source/usbBrickIO.m +++ b/source/usbBrickIO.m @@ -1,34 +1,32 @@ -%usbBrickIO USB interface between MATLAB and the brick -% -% Methods:: -% -% usbBrickIO Constructor, initialises and opens the usb connection -% delete Destructor, closes the usb connection -% -% open Open a usb connection to the brick -% close Close the usb connection to the brick -% read Read data from the brick through usb -% write Write data to the brick through usb -% -% Example:: -% usbbrick = usbBrickIO() -% -% Notes:: -% - Uses the hid library implementation in hidapi.m - classdef usbBrickIO < BrickIO + % USB interface between MATLAB and the brick + % + % Notes: + % * Uses the hid library implementation in hidapi.m + % + % Attributes: + % debug (bool): If true, each open/close/read/write-call will be noted in the console. + % vendorID (numeric): = 0x694 for EV3 + % productID (numeric): = 0x0005 for EV3 + % nReadBuffer (numeric): read buffer size + % nWriteBuffer (numeric): write buffer size (1 Byte bigger than actual packet) + % timeOut (numeric >= 0): milliseconds after which a timeout-error occurs if no packet could be + % read. + % + properties - % debug input + % debug (bool): If true, each open/close/read/write-call will be noted in the console. debug = 0; - % vendor ID (EV3 = 0x0694) + % vendorID (numeric): = 0x694 for EV3 vendorID = 1684; - % product ID (EV3 = 0x0005) + % productID (numeric): = 0x0005 for EV3 productID = 5; - % read buffer size + % nReadBuffer (numeric): read buffer size nReadBuffer = 1024; - % write buffer size + % nWriteBuffer (numeric): write buffer size (1 Byte bigger than actual packet) nWriteBuffer = 1025; - % time-out period in milliseconds (if 0, no time-out) + % timeOut (numeric >= 0): milliseconds after which a timeout-error occurs if no packet could be + % read. timeOut = 10000; end