diff --git a/docs/initialBytecodes.odt b/docs/initialBytecodes.odt new file mode 100644 index 0000000000000000000000000000000000000000..1654003debefd1f54e7e639a33ffc898ac1b83d7 Binary files /dev/null and b/docs/initialBytecodes.odt differ diff --git a/docs/relevanteBytecodes.odt b/docs/relevanteBytecodes.odt new file mode 100644 index 0000000000000000000000000000000000000000..9bc75cc235238b207de3823692696bca2b55d799 Binary files /dev/null and b/docs/relevanteBytecodes.odt differ diff --git a/typedata.ods b/docs/typedata.ods similarity index 100% rename from typedata.ods rename to docs/typedata.ods diff --git a/initialBytecodes.odt b/initialBytecodes.odt deleted file mode 100644 index ff55540b55caf7cf2ed4500e609c40a4cd16c19f..0000000000000000000000000000000000000000 Binary files a/initialBytecodes.odt and /dev/null differ diff --git a/relevanteBytecodes.odt b/relevanteBytecodes.odt deleted file mode 100644 index b2af85419ac97c13e11dbb376ea1e7b9f0aa8b70..0000000000000000000000000000000000000000 Binary files a/relevanteBytecodes.odt and /dev/null differ diff --git a/source/ByteCodes.m b/source/ByteCodes.m index 455c26e7dd59cd56a7fb9dd17af006db8005248d..e35a2985fd97342a8b7fb1210f3f30bb993bd891 100644 --- a/source/ByteCodes.m +++ b/source/ByteCodes.m @@ -97,10 +97,10 @@ classdef ByteCodes < uint8 % %Communications - COMReady (208) % = 0xD0 @MMI + COMReady (208) % = 0xD0 COMGet (211) % = 0xD3, COMSet (212) % = 0xD4, - COMTest (213) % = 0xD5 @MMI + COMTest (213) % = 0xD5 % %Mailbox MailboxOpen (216) % = 0xD8, diff --git a/source/CommunicationInterface.m b/source/CommunicationInterface.m index 65869b81eb47ed71584ec130139000e3eca03ae2..8c47af53aeb0167a4474403e9f7324ff852fb348 100755 --- a/source/CommunicationInterface.m +++ b/source/CommunicationInterface.m @@ -44,10 +44,6 @@ classdef CommunicationInterface < handle % inputRead @MMI: Reads a connected sensor at a layer, NO, type and mode in percentage % inputReadSI Reads a connected sensor at a layer, NO, type and mode in SI units % - % plotSensor Plots a sensor readings over time - % displayColor Displays the color from a color sensor - % - % % outputStop Stops motor at a layer, NOS and brake % outputStopAll Stops all the motors % outputPower Sets motor output power at a layer, NOS and speed @@ -1797,129 +1793,6 @@ classdef CommunicationInterface < handle end brick.soundPlayTone(volume, 1000, duration); end - - function playThreeTones(brick) - % Brick.playThreeTones Play three tones on the brick - % - % Brick.playThreeTones() plays three tones consequentively on - % the brick with one upload command. - % - % Example:: - % b.playThreeTones(); - - cmd = Command(); - cmd.addHeaderDirect(42,0,0); - cmd.opSOUND_TONE(5,440,500); - cmd.opSOUND_READY(); - cmd.opSOUND_TONE(10,880,500); - cmd.opSOUND_READY(); - cmd.opSOUND_TONE(15,1320,500); - cmd.opSOUND_READY(); - cmd.addLength(); - % print message - fprintf('Sending three tone message ...\n'); - brick.send(cmd); - end - - function plotSensor(brick,layer,no,mode) - % Brick.plotSensor plot the sensor output - % - % Brick.plotSensor(layer,no,mode) plots the sensor output - % to MATLAB. - % - % Notes:: - % - layer is the usb chain layer (usually 0). - % - NO is the output port number from [0..3] or sensor port - % number minus 1. - % - mode is the sensor mode from types.html. (-1=don't change) - % - % Example:: - % b.plotSensor(0,SensorPort.Sensor1,Device.USDistCM) - % b.plotSensor(0,SensorPort.Sensor1,Device.GyroAng) - - % start timing - tic; - % create figure - hfig = figure('name','EV3 Sensor'); - % init the the data - t = 0; - x = 0; - hplot = plot(t,x); - % one read to set the mode - reading = brick.inputReadSI(layer,no,mode); - % set the title - name = brick.inputDeviceGetName(layer,no); - title(['Device name: ' name]); - % set the y label - name = brick.inputDeviceSymbol(layer,no); - ylabel(['Sensor value (' name(1:end-1) ')']); - % set the x label - xlabel('Time (s)'); - % set the x axis - xlim([0 10]); - % wait until the figure is closed - while(findobj('name','EV3 Sensor') == 1) - % get the reading - reading = brick.inputReadSI(layer,no,mode); - t = [t toc]; - x = [x reading]; - set(hplot,'Xdata',t) - set(hplot,'Ydata',x) - drawnow - % reset after 10 seconds - if (toc > 10) - % reset - t = 0; - x = x(end); - tic - end - end - end - - function displayColor(brick,layer,no) - % Brick.displayColor display sensor color - % - % Brick.displayColor(layer,no) displays the color read from the - % color sensor in a MATLAB figure. - % - % Notes:: - % - layer is the usb chain layer (usually 0). - % - NO is the output port number from [0..3] or sensor port - % number minus 1. - % - % Example:: - % b.displayColor(0,SensorPort.Sensor1) - - % create figure - hfig = figure('name','EV3 Color Sensor'); - % wait until the figure is closed - while(findobj('name','EV3 Color Sensor') == 1) - % read the color sensor in color detection mode - color = brick.inputReadSI(layer,no,Device.ColColor); - % change the figure background according to the color - switch color - case Device.NoColor - set(hfig,'Color',[0.8,0.8,0.8]) - case Device.BlackColor - set(hfig,'Color',[0,0,0]) - case Device.BlueColor - set(hfig,'Color',[0,0,1]) - case Device.GreenColor - set(hfig,'Color',[0,1,0]) - case Device.YellowColor - set(hfig,'Color',[1,1,0]) - case Device.RedColor - set(hfig,'Color',[1,0,0]) - case Device.WhiteColor - set(hfig,'Color',[1,1,1]) - case Device.BrownColor - set(hfig,'Color',[0.6,0.3,0]) - otherwise - set(hfig,'Color',[0.8,0.8,0.8]) - end - drawnow - end - end end methods (Access = private) diff --git a/source/EV3.m b/source/EV3.m index 1f598f140be075531b495c05f871978e610c5117..5b36c75b9caf0cfcbf1b05e885c9a68587052c1f 100644 --- a/source/EV3.m +++ b/source/EV3.m @@ -468,7 +468,7 @@ classdef EV3 < MaskedHandle % Resets Motors and Sensors. % % Notes: - % * Gets called automatically by EV3.delete. + % * Gets called automatically by EV3.disconnect. % % See also MOTOR.RESETPHYSICALMOTOR, SENSOR.RESETPHYSICALSENSOR diff --git a/source/Motor.m b/source/Motor.m index b8edd40c5a801aa43a2fc8d44454dd5aca4454e2..e087e8375d57101b45ae5b4e179c9da52c8ca396 100644 --- a/source/Motor.m +++ b/source/Motor.m @@ -843,15 +843,6 @@ classdef Motor < MaskedHandle & dynamicprops end function conn = get.physicalMotorConnected(motor) -% try -% conn = motor.isPhysicalMotorConnected(); -% catch ME -% if ~isempty(strfind(ME.identifier, 'NotConnected')) -% conn = DeviceType.Unknown; -% else -% throw(ME); -% end -% end currentType = motor.type; conn = (currentType==DeviceType.MediumMotor || currentType==DeviceType.LargeMotor); end @@ -1036,6 +1027,11 @@ classdef Motor < MaskedHandle & dynamicprops methods (Access = ?EV3) function resetPhysicalMotor(motor) + % Stop motor, release brakes and reset all tacho counts. + % + % Notes: + % * This is called automatically on disconnect + % Do nothing if there is either no connection or no motor connected to port if ~motor.ev3Handle.isConnected || ~motor.physicalMotorConnected return; diff --git a/source/OutputStreamSend.class b/source/OutputStreamSend.class deleted file mode 100755 index 50aa9f9f6fe5e3e3ad9d43e454f3d4da298ef3bb..0000000000000000000000000000000000000000 Binary files a/source/OutputStreamSend.class and /dev/null differ diff --git a/source/OutputStreamSend.java b/source/OutputStreamSend.java deleted file mode 100755 index 2249b5dee071d7dd4100d60e899e398121247fe3..0000000000000000000000000000000000000000 --- a/source/OutputStreamSend.java +++ /dev/null @@ -1,53 +0,0 @@ -import java.io.*; - -public class OutputStreamSend { - public static byte[] buffer = null; - public static int counter = 0; - - public OutputStreamSend(int length) { - buffer = new byte[length]; - clear(); - } - - public OutputStreamSend() { - this(128); - } - - public void addtoBuffer(char v) { - buffer[counter] = (byte)v; - counter++; - } - - public void addtoBufferN(char[] v, int len) { - for(int i=0; i<len; i++) - { - buffer[counter] = (byte)v[i]; - counter++; - } - } - - public void display() { - for(int i=0;i<counter;i++) - { - System.out.print(buffer[i]); - } - } - - public void clear() { - for(int i=0;i<counter;i++) - { - buffer[i] = 0; - } - counter = 0; - } - - public void send(OutputStream output) throws IOException { - try { - output.write(buffer,0,counter); - output.flush(); - this.clear(); - - } catch (Exception e) {} - } - -} diff --git a/source/Sensor.m b/source/Sensor.m index a52638e991da960523abad11e9736000e4af2a59..5e6ac9fe283051a0bf4ac8d61703648213e8bb33 100644 --- a/source/Sensor.m +++ b/source/Sensor.m @@ -254,15 +254,14 @@ classdef Sensor < MaskedHandle type = sensor.type; if ~isModeValid(mode, type) error('Invalid sensor mode.'); - else - sensor.mode = mode; - - if ~strcmp(class(mode),'DeviceMode.Default') && sensor.ev3Handle.isConnected - try - sensor.setMode(mode); % Update physical brick's mode parameter - catch - % Ignore - end + end + + sensor.mode = mode; + if ~strcmp(class(mode),'DeviceMode.Default') && sensor.ev3Handle.isConnected + try + sensor.setMode(mode); % Update physical brick's mode parameter + catch + % Ignore end end end @@ -279,9 +278,9 @@ classdef Sensor < MaskedHandle function set.port(sensor, port) if ~isPortStrValid(class(sensor),port) error('Given port is not a valid port.'); - else - sensor.port = str2PortParam(class(sensor), port); end + + sensor.port = str2PortParam(class(sensor), port); end function setProperties(sensor, varargin) @@ -332,10 +331,9 @@ classdef Sensor < MaskedHandle %% Getter function value = get.value(sensor) value = 0; - defaultMode = -1; if sensor.ev3Handle.isConnected - value = sensor.getValue(defaultMode); + value = sensor.getValue(); if isnan(value) warning('Could not detect sensor at port %d.', ... sensor.port+1); @@ -369,34 +367,15 @@ classdef Sensor < MaskedHandle sensor.handleCommand(@inputReadSI, true, 0, sensor.port, mode); % Reading a value implicitly sets the mode. end - function val = getValue(sensor, varargin) + function val = getValue(sensor) %getValue Reads value from sensor % % Notes: % * After changing the mode, sensors initially always send an invalid value. In % this case, the inputReadSI-opCode is sent again to get the correct value. % - - if ~isempty(varargin) - defaultMode = varargin{1}; - - % 5 is numerically highest available number of modes for a sensor(NXT Color) - if ~isnumeric(defaultMode) || defaultMode > 5 - error('Invalid mode'); - end - else - defaultMode = -1; - end - - if defaultMode ~= -1 - mode = defaultMode; - else - mode = sensor.mode; - end - val = sensor.handleCommand(@inputReadSI, false, 0, sensor.port, sensor.mode); - if strcmp(class(sensor.mode), 'DeviceMode.Color') if sensor.mode == DeviceMode.Color.Col val = Color(val); @@ -417,6 +396,8 @@ classdef Sensor < MaskedHandle function [type,mode] = getTypeMode(sensor) type = DeviceType.Error; + % In very rare cases, the brick sends an invalid type-no - try to get a valid one up + % to ten times (I know, I know, another ugly workaround :( ) for i = 1:10 try [typeNo,modeNo] = sensor.handleCommand(@inputDeviceGetTypeMode, false, 0, sensor.port); @@ -424,6 +405,7 @@ classdef Sensor < MaskedHandle catch ME continue; end + break; end @@ -467,6 +449,11 @@ classdef Sensor < MaskedHandle methods (Access = ?EV3) function resetPhysicalSensor(sensor) + % Reset mode to default and reset sensor value + % + % Notes: + % * This is called automatically on disconnect + if ~sensor.ev3Handle.isConnected || ~sensor.physicalSensorConnected return end diff --git a/source/btBrickIO.m b/source/btBrickIO.m index 639ea0c8d8d69092f10c18a8a8b8417fb93b869a..2e955475bd2a1a8ecc715a88dd20fb099672578d 100644 --- a/source/btBrickIO.m +++ b/source/btBrickIO.m @@ -289,6 +289,9 @@ classdef btBrickIO < BrickIO if(ispc && license('test', 'instr_control_toolbox')) % Choose 'backend'-default depending on OS p.addOptional('backend', 'instrumentControl'); else + if ispc + warning('Instrument&Control-Toolbox not installed. Using MATLAB default backend for BT communication. This could lead to errors on Windows!'); + end p.addOptional('backend', 'serial'); end diff --git a/source/hidapi_old.h b/source/hidapi_old.h deleted file mode 100755 index 6c8c48396496ac4083ec81739fe0245db4e53066..0000000000000000000000000000000000000000 --- a/source/hidapi_old.h +++ /dev/null @@ -1,383 +0,0 @@ -/******************************************************* - HIDAPI - Multi-Platform library for - communication with HID devices. - - Alan Ott - Signal 11 Software - - 8/22/2009 - - Copyright 2009, All Rights Reserved. - - At the discretion of the user of this library, - this software may be licensed under the terms of the - GNU Public License v3, a BSD-Style license, or the - original HIDAPI license as outlined in the LICENSE.txt, - LICENSE-gpl3.txt, LICENSE-bsd.txt, and LICENSE-orig.txt - files located at the root of the source distribution. - These files may also be found in the public source - code repository located at: - http://github.com/signal11/hidapi . -********************************************************/ - -/** @file - * @defgroup API hidapi API - */ - -#ifndef HIDAPI_H__ -#define HIDAPI_H__ - -#include <wchar.h> - -#ifdef _WIN32 - #define HID_API_EXPORT __declspec(dllexport) - #define HID_API_CALL -#else - #define HID_API_EXPORT /**< API export macro */ - #define HID_API_CALL /**< API call macro */ -#endif - -#define HID_API_EXPORT_CALL HID_API_EXPORT HID_API_CALL /**< API export and call macro*/ - -#ifdef __cplusplus -extern "C" { -#endif - struct hid_device_; - typedef struct hid_device_ hid_device; /**< opaque hidapi structure */ - - /** hidapi info structure */ - struct hid_device_info { - /** Platform-specific device path */ - char *path; - /** Device Vendor ID */ - unsigned short vendor_id; - /** Device Product ID */ - unsigned short product_id; - /** Serial Number */ - wchar_t *serial_number; - /** Device Release Number in binary-coded decimal, - also known as Device Version Number */ - unsigned short release_number; - /** Manufacturer String */ - wchar_t *manufacturer_string; - /** Product string */ - wchar_t *product_string; - /** Usage Page for this Device/Interface - (Windows/Mac only). */ - unsigned short usage_page; - /** Usage for this Device/Interface - (Windows/Mac only).*/ - unsigned short usage; - /** The USB interface which this logical device - represents. Valid on both Linux implementations - in all cases, and valid on the Windows implementation - only if the device contains more than one interface. */ - int interface_number; - - /** Pointer to the next device */ - struct hid_device_info *next; - }; - - - /** @brief Initialize the HIDAPI library. - - This function initializes the HIDAPI library. Calling it is not - strictly necessary, as it will be called automatically by - hid_enumerate() and any of the hid_open_*() functions if it is - needed. This function should be called at the beginning of - execution however, if there is a chance of HIDAPI handles - being opened by different threads simultaneously. - - @ingroup API - - @returns - This function returns 0 on success and -1 on error. - */ - int HID_API_EXPORT HID_API_CALL hid_init(void); - - /** @brief Finalize the HIDAPI library. - - This function frees all of the static data associated with - HIDAPI. It should be called at the end of execution to avoid - memory leaks. - - @ingroup API - - @returns - This function returns 0 on success and -1 on error. - */ - int HID_API_EXPORT HID_API_CALL hid_exit(void); - - /** @brief Enumerate the HID Devices. - - This function returns a linked list of all the HID devices - attached to the system which match vendor_id and product_id. - If @p vendor_id and @p product_id are both set to 0, then - all HID devices will be returned. - - @ingroup API - @param vendor_id The Vendor ID (VID) of the types of device - to open. - @param product_id The Product ID (PID) of the types of - device to open. - - @returns - This function returns a pointer to a linked list of type - struct #hid_device, containing information about the HID devices - attached to the system, or NULL in the case of failure. Free - this linked list by calling hid_free_enumeration(). - */ - struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned short vendor_id, unsigned short product_id); - - /** @brief Free an enumeration Linked List - - This function frees a linked list created by hid_enumerate(). - - @ingroup API - @param devs Pointer to a list of struct_device returned from - hid_enumerate(). - */ - void HID_API_EXPORT HID_API_CALL hid_free_enumeration(struct hid_device_info *devs); - - /** @brief Open a HID device using a Vendor ID (VID), Product ID - (PID) and optionally a serial number. - - If @p serial_number is NULL, the first device with the - specified VID and PID is opened. - - @ingroup API - @param vendor_id The Vendor ID (VID) of the device to open. - @param product_id The Product ID (PID) of the device to open. - @param serial_number The Serial Number of the device to open - (Optionally NULL). - - @returns - This function returns a pointer to a #hid_device object on - success or NULL on failure. - */ - HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsigned short product_id, wchar_t *serial_number); - - /** @brief Open a HID device by its path name. - - The path name be determined by calling hid_enumerate(), or a - platform-specific path name can be used (eg: /dev/hidraw0 on - Linux). - - @ingroup API - @param path The path name of the device to open - - @returns - This function returns a pointer to a #hid_device object on - success or NULL on failure. - */ - HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path); - - /** @brief Write an Output report to a HID device. - - The first byte of @p data[] must contain the Report ID. For - devices which only support a single report, this must be set - to 0x0. The remaining bytes contain the report data. Since - the Report ID is mandatory, calls to hid_write() will always - contain one more byte than the report contains. For example, - if a hid report is 16 bytes long, 17 bytes must be passed to - hid_write(), the Report ID (or 0x0, for devices with a - single report), followed by the report data (16 bytes). In - this example, the length passed in would be 17. - - hid_write() will send the data on the first OUT endpoint, if - one exists. If it does not, it will send the data through - the Control Endpoint (Endpoint 0). - - @ingroup API - @param device A device handle returned from hid_open(). - @param data The data to send, including the report number as - the first byte. - @param length The length in bytes of the data to send. - - @returns - This function returns the actual number of bytes written and - -1 on error. - */ - int HID_API_EXPORT HID_API_CALL hid_write(hid_device *device, const unsigned char *data, size_t length); - - /** @brief Read an Input report from a HID device with timeout. - - Input reports are returned - to the host through the INTERRUPT IN endpoint. The first byte will - contain the Report number if the device uses numbered reports. - - @ingroup API - @param device A device handle returned from hid_open(). - @param data A buffer to put the read data into. - @param length The number of bytes to read. For devices with - multiple reports, make sure to read an extra byte for - the report number. - @param milliseconds timeout in milliseconds or -1 for blocking wait. - - @returns - This function returns the actual number of bytes read and - -1 on error. - */ - int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds); - - /** @brief Read an Input report from a HID device. - - Input reports are returned - to the host through the INTERRUPT IN endpoint. The first byte will - contain the Report number if the device uses numbered reports. - - @ingroup API - @param device A device handle returned from hid_open(). - @param data A buffer to put the read data into. - @param length The number of bytes to read. For devices with - multiple reports, make sure to read an extra byte for - the report number. - - @returns - This function returns the actual number of bytes read and - -1 on error. - */ - int HID_API_EXPORT HID_API_CALL hid_read(hid_device *device, unsigned char *data, size_t length); - - /** @brief Set the device handle to be non-blocking. - - In non-blocking mode calls to hid_read() will return - immediately with a value of 0 if there is no data to be - read. In blocking mode, hid_read() will wait (block) until - there is data to read before returning. - - Nonblocking can be turned on and off at any time. - - @ingroup API - @param device A device handle returned from hid_open(). - @param nonblock enable or not the nonblocking reads - - 1 to enable nonblocking - - 0 to disable nonblocking. - - @returns - This function returns 0 on success and -1 on error. - */ - int HID_API_EXPORT HID_API_CALL hid_set_nonblocking(hid_device *device, int nonblock); - - /** @brief Send a Feature report to the device. - - Feature reports are sent over the Control endpoint as a - Set_Report transfer. The first byte of @p data[] must - contain the Report ID. For devices which only support a - single report, this must be set to 0x0. The remaining bytes - contain the report data. Since the Report ID is mandatory, - calls to hid_send_feature_report() will always contain one - more byte than the report contains. For example, if a hid - report is 16 bytes long, 17 bytes must be passed to - hid_send_feature_report(): the Report ID (or 0x0, for - devices which do not use numbered reports), followed by the - report data (16 bytes). In this example, the length passed - in would be 17. - - @ingroup API - @param device A device handle returned from hid_open(). - @param data The data to send, including the report number as - the first byte. - @param length The length in bytes of the data to send, including - the report number. - - @returns - This function returns the actual number of bytes written and - -1 on error. - */ - int HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *device, const unsigned char *data, size_t length); - - /** @brief Get a feature report from a HID device. - - Make sure to set the first byte of @p data[] to the Report - ID of the report to be read. Make sure to allow space for - this extra byte in @p data[]. - - @ingroup API - @param device A device handle returned from hid_open(). - @param data A buffer to put the read data into, including - the Report ID. Set the first byte of @p data[] to the - Report ID of the report to be read. - @param length The number of bytes to read, including an - extra byte for the report ID. The buffer can be longer - than the actual report. - - @returns - This function returns the number of bytes read and - -1 on error. - */ - int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *device, unsigned char *data, size_t length); - - /** @brief Close a HID device. - - @ingroup API - @param device A device handle returned from hid_open(). - */ - void HID_API_EXPORT HID_API_CALL hid_close(hid_device *device); - - /** @brief Get The Manufacturer String from a HID device. - - @ingroup API - @param device A device handle returned from hid_open(). - @param string A wide string buffer to put the data into. - @param maxlen The length of the buffer in multiples of wchar_t. - - @returns - This function returns 0 on success and -1 on error. - */ - int HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *device, wchar_t *string, size_t maxlen); - - /** @brief Get The Product String from a HID device. - - @ingroup API - @param device A device handle returned from hid_open(). - @param string A wide string buffer to put the data into. - @param maxlen The length of the buffer in multiples of wchar_t. - - @returns - This function returns 0 on success and -1 on error. - */ - int HID_API_EXPORT_CALL hid_get_product_string(hid_device *device, wchar_t *string, size_t maxlen); - - /** @brief Get The Serial Number String from a HID device. - - @ingroup API - @param device A device handle returned from hid_open(). - @param string A wide string buffer to put the data into. - @param maxlen The length of the buffer in multiples of wchar_t. - - @returns - This function returns 0 on success and -1 on error. - */ - int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *device, wchar_t *string, size_t maxlen); - - /** @brief Get a string from a HID device, based on its string index. - - @ingroup API - @param device A device handle returned from hid_open(). - @param string_index The index of the string to get. - @param string A wide string buffer to put the data into. - @param maxlen The length of the buffer in multiples of wchar_t. - - @returns - This function returns 0 on success and -1 on error. - */ - int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *device, int string_index, wchar_t *string, size_t maxlen); - - /** @brief Get a string describing the last error which occurred. - - @ingroup API - @param device A device handle returned from hid_open(). - - @returns - This function returns a string containing the last error - which occurred or NULL if none has occurred. - */ - HID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *device); - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/source/wfBrickIO.m b/source/wfBrickIO.m deleted file mode 100755 index b234c566e96d57a98539f5b2182997912d2f317d..0000000000000000000000000000000000000000 --- a/source/wfBrickIO.m +++ /dev/null @@ -1,189 +0,0 @@ -%wfBrickIO Wifi interface between MATLAB and the brick -% -% Methods:: -% -% wfBrickIO Constructor, initialises and opens the wifi connection -% delete Destructor, closes the wifi connection -% -% open Open a wifi connection to the brick -% close Close the wifi connection to the brick -% read Read data from the brick through wifi -% write Write data to the brick through wifi -% -% Example:: -% wfbrick = wfBrickIO(1,'192.168.1.104',5555,'0016533dbaf5') -% -% Notes:: -% - Java string casting is inconsistent in MATLAB across different -% operating systems. The purpose of OutputStreamSend is to ensure that the -% correct string sequence is sent to the brick, no matter what operating -% system MATLAB is running under. -% - The OutputStreamSend class file will need to be present in the java -% path before a wfBrickIO object is made. -% - This class works across all 3 operating systems. - -classdef wfBrickIO < BrickIO - properties - % debug input - debug = 0; - % socket input strem - inputStream - % socket output stream - outputStream - % brick IP address - addr = '192.168.1.104'; - % brick tcp port (default is 5555) - port = 5555; - % brick serial number - serialNum = '0016533dbaf5'; - end - - properties (Access = 'protected') - % connection handle - handle - end - - methods - - function brickIO = wfBrickIO(debug,addr,port,serialNum) - %wfBrickIO.wfBrickIO Create a wfBrickIO object - % - % wfbrick = wfBrickIO(debug,addr,port,serialNum) is an object - % which initialises and opens a wifi connection between MATLAB - % and the brick using java functions. The following string is - % sent to the brick - % ['GET /target?sn=' brickIO.serialNum ' VMTP1.0' char(10) 'Protocol: EV3'] - % which initialises the conncetion. The brick returns - % ['Accept:EV340'] - % - % Notes:: - % - debug is a flag specifying output printing (0 or 1). - % - addr is the IP address of the brick - % - port is the TCP port of the brick (default is 5555) - % - serialNum is the serial number of the brick. The serial - % number can be found in the menu on the EV3 brick or obtained - % through the emitted UDP packet on port 3015. - - if nargin > 0 - brickIO.debug = debug; - brickIO.addr = addr; - brickIO.port = port; - brickIO.serialNum = serialNum; - end - if brickIO.debug > 0 - fprintf('wfBrickIO init\n'); - end - % import the required java libraries - import java.io.*; - import java.net.*; - % add the java path to the class path - javaaddpath . - % open the brick IO connection - brickIO.handle = Socket(brickIO.addr, brickIO.port); - % set the input stream - brickIO.inputStream = DataInputStream(brickIO.handle.getInputStream); - % set the output stream - brickIO.outputStream = OutputStreamSend(); - % connection message to the brick - wmsg = ['GET /target?sn=' brickIO.serialNum ' VMTP1.0' char(10) 'Protocol: EV3']; - if brickIO.debug > 0 - fprintf('Sent: [ %s ]\n',char(wmsg)); - end - % send the connection message - brickIO.write(wmsg); - % receive the reply - rmsg = brickIO.read; - if brickIO.debug > 0 - fprintf('Returned: [ %s ]\n',char(rmsg)); - end - end - - function delete(brickIO) - %wfBrickIO.delete Delete the wfBrickIO object - % - % delete(brickIO) closes the wifi connection handle - - if brickIO.debug > 0 - fprintf('wfBrickIO delete\n'); - end - % delete the wf handle - brickIO.close - end - - function handle = open(brickIO) - %wfBrickIO.open Open the wfBrickIO object - % - % handle = wfBrickIO.open() returns a handle to the wifi - % socket connection using the initialised IP address and TCP - % port values from the wfBrickIO constructor. - - if brickIO.debug > 0 - fprintf('wfBrickIO open\n'); - end - % open the socket handle - handle = Socket(brickIO.addr, brickIO.port); - end - - function close(brickIO) - %wfBrickIO.close Close the wfBrickIO object - % - % wfBrickIO.close() closes the wifi socket connection - - if brickIO.debug > 0 - fprintf('wfBrickIO close\n'); - end - % close the close handle - brickIO.handle.close(); - end - - function rmsg = read(brickIO) - %wfBrickIO.read Read data from the wfBrickIO object - % - % rmsg = wfBrickIO.read() reads data from the brick through wifi - % and returns the data in uint8 format. - % - % Notes:: - % - This function is blocking with no time out in the current - % implementation. - - if brickIO.debug > 0 - fprintf('wfBrickIO read\n'); - end - % block until bytes have been received - while (brickIO.inputStream.available == 0) - - end - % get the number of bytes to be read from the input stream - nLength = brickIO.inputStream.available; - % read the bytes from the input stream - rmsg = zeros(1,nLength); - for ii=1:nLength - rmsg(ii) = brickIO.inputStream.readByte; - end - % convert from double to int8 - rmsg = cast(rmsg,'int8'); - % change from int8 to uint8 (cannot do this in one step) - rmsg = typecast(rmsg,'uint8'); - end - - function write(brickIO,wmsg) - %wfBrickIO.write Write data to the wfBrickIO object - % - % wfBrickIO.write(wmsg) writes data to the brick through wifi. - % - % Notes:: - % - wmsg is the data to be written to the brick via wifi in - % uint8 format. - - if brickIO.debug > 0 - fprintf('wfBrickIO write\n'); - end - % add the message to the output stream - brickIO.outputStream.addtoBufferN(char(wmsg),length(wmsg)); - % send the output stream data - brickIO.outputStream.send(brickIO.handle.getOutputStream()); - % clear the output stream - brickIO.outputStream.clear(); - end - end -end \ No newline at end of file