btBrickIO

class btBrickIO(varargin)
List of methods:

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.
  • For general information, see also BrickIO.
debug

If true, each open/close/read/write-call will be shown in the console. Defaults to false.

Type:bool
serialPort

Path to the serial-port object. Only needed when using MATLAB’s serial class (i.e. on linux/mac). Defaults to ‘/dev/rfcomm0’.

Type:string
deviceName

Name of the BT-device = the brick. Only needed when using the Instrument Control toolbox (i.e. on windows). Defaults to ‘EV3’.

Type:string
channel

BT-channel of the connected BT-device. Only needed when using the Instrument Control toolbox (i.e. on windows). Defaults to 1.

Type:numeric > 0
timeOut

seconds after which a timeout-error occurs if no packet could be read. Defaults to 10.

Type:numeric >= 0
backend

Backend this implementation is based on. Is automatically chosen depending on the OS. Defaults to ‘serial’ on linux/mac systems, and to ‘instrumentControl’ on windows systems.

Type:‘serial’|’instrumentControl’
Examples:
    % Connecting on windows
    commHandle = btBrickIO('deviceName', 'MyEV3', 'channel', 1);
    % Connecting on windows using MATLABs default serial port implementation for testing
    commHandle = btBrickIO('deviceName', 'MyEV3', 'channel', 1, 'backend', 'serial');
    % Connecting on mac/linux
    commHandle = btBrickIO('serPort', '/dev/rfcomm0');
close(brickIO)

Closes the bluetooth connection the brick using fclose.

open(brickIO)

Opens the bluetooth connection to the brick using fopen.

read(brickIO)

Reads data from the brick through bluetooth via fread and returns the data in uint8 format.

setProperties(brickIO, varargin)

Sets multiple btBrickIO properties at once using MATLAB’s inputParser.

The syntax is as follows: commHandle.setProperties(‘propertyName1’, propertyValue1, ‘propertyName2’, propertyValue2, …). Valid, optional properties are: debug, serPort, deviceName, channel, timeout.

See also BTBRICKIO.DEBUG, BTBRICKIO.SERIALPORT, BTBRICKIO.DEVICENAME, BTBRICKIO.CHANNEL, BTBRICKIO.TIMEOUT

write(brickIO, wmsg)

Writes data to the brick through bluetooth via fwrite.

Parameters:wmsg (uint8 array) – Data to be written to the brick via bluetooth