function msg = phidgetError(code)
%PHIDGETERROR  Human readable Phidget error message
%   msg = phidgetError(errorCode) translates the Phidget Error code
%   code into a human readable message and returns the message as
%   a character array msg.

global PHIDGET;

if isNull(PHIDGET)
    disp('The global variable PHIDGET is empty; call phidgetInit()');
    return;
end

msg = '';
switch code
    case 0
        msg = 'Function completed successfully';
    case 1
        msg = 'A Phidget matching the type and or serial number could not be found';
    case 2
        msg = 'Memory could not be allocated';
    case 3
        msg = 'Unexpected Error. Contact Phidgets Inc. for support';
    case 4
        msg = 'Invalid argument passed to function';
    case 5
        msg = 'Phidget not physically attached';
    case 6
        msg = 'Read/Write operation was interrupted';
    case 7
        msg = 'The Error Code is not defined';
    case 8
        msg = 'Network Error';
    case 9
        msg = 'Value is Unknown (State not yet received from device, or not yet set by user)';
    case 10
        msg = 'No longer used. Replaced by EEPHIDGET_BADPASSWORD';
    case 11
        msg = 'Not Supported';
    case 12
        msg = 'Duplicated request';
    case 13
        msg = 'Given timeout has been exceeded';
    case 14
        msg = 'Index out of Bounds';
    case 15
        msg = 'A non-null error code was returned from an event handler';
    case 16
        msg = 'A connection to the server does not exist';
    case 17
        msg = 'Function is not applicable for this device';
    case 18
        msg = 'Phidget handle was closed';
    case 19
        msg = 'No longer used. Replaced by EEPHIDGET_BADVERSION';
    otherwise
        msg = 'Unknown error code';
end


end
