Skip to content
Snippets Groups Projects
Commit 595d4c75 authored by Tim Stadtmann's avatar Tim Stadtmann
Browse files

HIDAPI-interface now creates shorter error IDs

... without using the ID()-function. Fixes issue #50.
parent 23e350ae
No related branches found
No related tags found
No related merge requests found
...@@ -116,7 +116,7 @@ classdef hidapi < handle ...@@ -116,7 +116,7 @@ classdef hidapi < handle
end end
catch ME catch ME
% Create own exception for clarification % Create own exception for clarification
id = [ID(), ':', 'LoadingLibraryError']; id = [hid.slib, ':', 'LoadingLibraryError'];
msg = strcat({'Could not load library '}, {hid.slib}, {'.'}); msg = strcat({'Could not load library '}, {hid.slib}, {'.'});
exception = MException(id, msg); exception = MException(id, msg);
...@@ -124,7 +124,7 @@ classdef hidapi < handle ...@@ -124,7 +124,7 @@ classdef hidapi < handle
if isempty(findstr(ME.identifier, 'LoadFailed')) ... if isempty(findstr(ME.identifier, 'LoadFailed')) ...
&& isempty(findstr(ME.identifier, 'ErrorLoadingLibrary')) ... && isempty(findstr(ME.identifier, 'ErrorLoadingLibrary')) ...
&& isempty(findstr(ME.identifier, 'ErrorInHeader')) && isempty(findstr(ME.identifier, 'ErrorInHeader'))
id = [ID(), ':', 'InvalidFileNameOrFileMissing']; id = [hid.slib, ':', 'InvalidFileNameOrFileMissing'];
msg = 'Invalid file names were given or files are not available.'; msg = 'Invalid file names were given or files are not available.';
cause = MException(id, msg); cause = MException(id, msg);
exception = addCause(exception, cause); exception = addCause(exception, cause);
...@@ -221,7 +221,7 @@ classdef hidapi < handle ...@@ -221,7 +221,7 @@ classdef hidapi < handle
% (MMI) Assert error case (hid_open returns null-pointer in error case) % (MMI) Assert error case (hid_open returns null-pointer in error case)
assert(isLibPointerValid(newHandle)==1, ... assert(isLibPointerValid(newHandle)==1, ...
[ID(), ':', 'CommError'], ... [hid.slib, ':', 'CommError'], ...
'Failed to connect to USB device.'); 'Failed to connect to USB device.');
hid.handle = newHandle; hid.handle = newHandle;
...@@ -243,7 +243,7 @@ classdef hidapi < handle ...@@ -243,7 +243,7 @@ classdef hidapi < handle
% (MMI) Check if pointer is (unexpectedly) already invalidated % (MMI) Check if pointer is (unexpectedly) already invalidated
assert(isLibPointerValid(hid.handle)==1, ... assert(isLibPointerValid(hid.handle)==1, ...
[ID(), ':', 'InvalidHandle'], ... [hid.slib, ':', 'InvalidHandle'], ...
'Failed to close USB-connection because pointer to USB-device is already invalidated.'); 'Failed to close USB-connection because pointer to USB-device is already invalidated.');
% Close the connection % Close the connection
...@@ -275,7 +275,7 @@ classdef hidapi < handle ...@@ -275,7 +275,7 @@ classdef hidapi < handle
% (MMI) Check if pointer is (unexpectedly) already invalidated % (MMI) Check if pointer is (unexpectedly) already invalidated
assert(isLibPointerValid(hid.handle)==1, ... assert(isLibPointerValid(hid.handle)==1, ...
[ID(), ':', 'InvalidHandle'], ... [hid.slib, ':', 'InvalidHandle'], ...
'Failed to read USB-data because pointer to USB-device is invalidated.'); 'Failed to read USB-data because pointer to USB-device is invalidated.');
% Read data from HID device % Read data from HID device
...@@ -284,7 +284,7 @@ classdef hidapi < handle ...@@ -284,7 +284,7 @@ classdef hidapi < handle
% (MMI) Check the response (No assert as there are multiple cases) % (MMI) Check the response (No assert as there are multiple cases)
if res < 1 if res < 1
% Error occurred % Error occurred
id = [ID(), ':', 'CommError']; id = [hid.slib, ':', 'CommError'];
% Narrow error down % Narrow error down
if res == -1 if res == -1
msg = 'Connection error (probably lost connection to device)'; msg = 'Connection error (probably lost connection to device)';
...@@ -335,7 +335,7 @@ classdef hidapi < handle ...@@ -335,7 +335,7 @@ classdef hidapi < handle
% (MMI) Check if pointer is (unexpectedly) already invalidated % (MMI) Check if pointer is (unexpectedly) already invalidated
assert(isLibPointerValid(hid.handle)==1, ... assert(isLibPointerValid(hid.handle)==1, ...
[ID(), ':', 'InvalidHandle'], ... [hid.slib, ':', 'InvalidHandle'], ...
'Failed to write to USB because pointer to USB-device is invalidated.'); 'Failed to write to USB because pointer to USB-device is invalidated.');
% Write the message % Write the message
...@@ -343,7 +343,7 @@ classdef hidapi < handle ...@@ -343,7 +343,7 @@ classdef hidapi < handle
% (MMI) Check the response % (MMI) Check the response
assert(res == length(wmsg), ... assert(res == length(wmsg), ...
[ID(), ':', 'CommError'], ... [hid.slib, ':', 'CommError'], ...
'Failed to write data via USB.'); 'Failed to write data via USB.');
end end
...@@ -374,7 +374,7 @@ classdef hidapi < handle ...@@ -374,7 +374,7 @@ classdef hidapi < handle
% (MMI) Check if pointer is (unexpectedly) already invalidated % (MMI) Check if pointer is (unexpectedly) already invalidated
assert(isLibPointerValid(hid.handle)==1, ... assert(isLibPointerValid(hid.handle)==1, ...
[ID(), ':', 'InvalidHandle'], ... [hid.slib, ':', 'InvalidHandle'], ...
'Failed to read USB-data because pointer to USB-device is invalidated.'); 'Failed to read USB-data because pointer to USB-device is invalidated.');
% Get the HID info string % Get the HID info string
...@@ -382,7 +382,7 @@ classdef hidapi < handle ...@@ -382,7 +382,7 @@ classdef hidapi < handle
% (MMI) Check the response % (MMI) Check the response
assert(res~=-1, ... assert(res~=-1, ...
[ID(), ':', 'CommError'], ... [hid.slib, ':', 'CommError'], ...
'Failed to read HID info string.'); 'Failed to read HID info string.');
% Return the string value % Return the string value
...@@ -408,7 +408,7 @@ classdef hidapi < handle ...@@ -408,7 +408,7 @@ classdef hidapi < handle
% (MMI) Check if pointer is (unexpectedly) already invalidated % (MMI) Check if pointer is (unexpectedly) already invalidated
assert(isLibPointerValid(hid.handle)==1, ... assert(isLibPointerValid(hid.handle)==1, ...
[ID(), ':', 'InvalidHandle'], ... [hid.slib, ':', 'InvalidHandle'], ...
'Failed to set USB-read-mode to non-blocking because pointer to USB-device is invalidated.'); 'Failed to set USB-read-mode to non-blocking because pointer to USB-device is invalidated.');
% Set non blocking % Set non blocking
...@@ -416,7 +416,7 @@ classdef hidapi < handle ...@@ -416,7 +416,7 @@ classdef hidapi < handle
% (MMI) Check the response % (MMI) Check the response
assert(res~=-1, ... assert(res~=-1, ...
[ID(), ':', 'CommError'], ... [hid.slib, ':', 'CommError'], ...
'Failed to set USB-read-mode to non-blocking.'); 'Failed to set USB-read-mode to non-blocking.');
end end
...@@ -436,7 +436,7 @@ classdef hidapi < handle ...@@ -436,7 +436,7 @@ classdef hidapi < handle
fprintf('hidapi init\n'); fprintf('hidapi init\n');
end end
warning([ID(), ':', 'RedundantCall'], ... warning([hid.slib, ':', 'RedundantCall'], ...
'The init-function gets called automatically when connecting!'); 'The init-function gets called automatically when connecting!');
% Init device % Init device
...@@ -444,7 +444,7 @@ classdef hidapi < handle ...@@ -444,7 +444,7 @@ classdef hidapi < handle
% (MMI) Check the response % (MMI) Check the response
assert(res~=-1, ... assert(res~=-1, ...
[ID(), ':', 'CommError'], ... [hid.slib, ':', 'CommError'], ...
'Failed to init USB-device.'); 'Failed to init USB-device.');
end end
...@@ -463,7 +463,7 @@ classdef hidapi < handle ...@@ -463,7 +463,7 @@ classdef hidapi < handle
fprintf('hidapi exit\n'); fprintf('hidapi exit\n');
end end
warning([ID(), ':', 'RedundantCall'], ... warning([hid.slib, ':', 'RedundantCall'], ...
'The exit-function gets called automatically when disconnecting!'); 'The exit-function gets called automatically when disconnecting!');
% Exit device % Exit device
...@@ -471,7 +471,7 @@ classdef hidapi < handle ...@@ -471,7 +471,7 @@ classdef hidapi < handle
% (MMI) Check the response % (MMI) Check the response
assert(res~=-1, ... assert(res~=-1, ...
[ID(), ':', 'CommError'], ... [hid.slib, ':', 'CommError'], ...
'Failed to exit USB-device.'); 'Failed to exit USB-device.');
end end
...@@ -494,7 +494,7 @@ classdef hidapi < handle ...@@ -494,7 +494,7 @@ classdef hidapi < handle
% (MMI) Check if pointer is (unexpectedly) already invalidated % (MMI) Check if pointer is (unexpectedly) already invalidated
assert(isLibPointerValid(hid.handle)==1, ... assert(isLibPointerValid(hid.handle)==1, ...
[ID(), ':', 'InvalidHandle'], ... [hid.slib, ':', 'InvalidHandle'], ...
'Failed to read USB-error-data because pointer to USB-device is invalidated.'); 'Failed to read USB-error-data because pointer to USB-device is invalidated.');
[~,str] = calllib(hid.slib,'hid_error',hid.handle); [~,str] = calllib(hid.slib,'hid_error',hid.handle);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment