ApiGetErrorText(PcanStatus, String) Method

Returns a descriptive text of a given error code, using the operating system language, or English, if it is not supported.

Definition

Namespace: Peak.Can.Basic
Assembly: PCANBasic.NET (in PCANBasic.NET.dll) Version: 4.9.0
C#
public static PcanStatus GetErrorText(
	PcanStatus errorCode,
	out string errorText
)

Parameters

errorCode  PcanStatus
The error code which description text is to be retrieved.
errorText  String

Contains the description text of the given errorCode.

The content of errorText is only valid if the returned value of this method is OK.

Return Value

PcanStatus

OK is returned on success. The typical errors in case of failure are:

  • InvalidValue: Indicates that one or more of the values passed to the method are invalid. Possible causes are:
    • The given errorCode is not defined.

Remarks

The "Primary language IDs" are codes used by Windows OS from Microsoft, to identify a human language. Currently, following languages are supported:

LanguagePrimary Language ID
Neutral (System dependent)00h (0)
English09h (9)
German07h (7)
French0Ch (12)
Italian10h (16)
Spanish0Ah (10)

Example

The following example shows the use of the GetErrorText(PcanStatus, String) method. The description of all available error codes are requested.

In case of failure, the returned code will be translated to a text (according with the operating system language) in English, German, Italian, French or Spanish, and it will be shown to the user.

C#
PcanStatus result;
string errorText = String.Empty;

foreach (PcanStatus errorCode in Enum.GetValues(typeof(PcanStatus)))
{
    result = Api.GetErrorText(errorCode, out errorText);
    if(result != PcanStatus.OK)
    {
        // An error occurred
        //
        Console.WriteLine($"  [{((uint)errorCode):X8}] {errorCode}: Error while retrieving --> {result}");
    }
    else
    {
        Console.WriteLine($"  [{((uint)errorCode):X8}] {errorCode}: {errorText}");
    }
}

Exceptions

DllNotFoundExceptionThe underlying PCANBasic.dll library could not be found.
PcanBasicExceptionThe execution of a PCAN-Basic related check operation ended with an unexpected result. Typically, this exception is triggered when a device driver is not installed or is not up to date.

See Also