PCANBasicGetErrorText Method

Returns a descriptive text for a given TPCANStatus code, in any of the supported languages.

Definition

Namespace: Peak.Can.Basic.BackwardCompatibility
Assembly: PCANBasic.NET (in PCANBasic.NET.dll) Version: 4.9.0
C#
public static TPCANStatus GetErrorText(
	TPCANStatus Error,
	ushort Language,
	StringBuilder StringBuffer
)

Parameters

Error  TPCANStatus
The error code to translate.
Language  UInt16
The ID of the language to use for the output.
StringBuffer  StringBuilder
A buffer for the output text with a capacity of at least 256 bytes.

  Important

Even when currently only short texts are being returned, a text within this method can have a maximum of 255 characters plus termination. Using small buffers could lead to exceptions like an access violation in future versions of the API.

Return Value

TPCANStatus

The return value is a TPCANStatus value. PCAN_ERROR_OK is returned on success. The typical errors in case of failure are:

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 GetErrorText(TPCANStatus, UInt16, StringBuilder) method to get the description of the error code PCAN_ERROR_INITIALIZE. The language used for the text will be the same as used by the operating system (if its language is supported; otherwise English is used).

C#
TPCANStatus result;
System.Text.StringBuilder strMsg;

strMsg = new System.Text.StringBuilder(256);

// Gets the description text for PCAN_ERROR_INITIALIZE using the Neutral language
//
result = PCANBasic.GetErrorText(TPCANStatus.PCAN_ERROR_INITIALIZE, 0, strMsg);
if (result != TPCANStatus.PCAN_ERROR_OK)
    // An error occurred, show a message indicating it
    //
    Console.WriteLine("Error when recovering Error-Code's description");
else
    Console.WriteLine(strMsg.ToString());

See Also