PCANBasicGetErrorText Method
Returns a descriptive text for a given
TPCANStatus code, in any of the supported languages.
Namespace: Peak.Can.Basic.BackwardCompatibilityAssembly: PCANBasic.NET (in PCANBasic.NET.dll) Version: 4.9.0
public static TPCANStatus GetErrorText(
TPCANStatus Error,
ushort Language,
StringBuilder StringBuffer
)
Public Shared Function GetErrorText (
Error As TPCANStatus,
Language As UShort,
StringBuffer As StringBuilder
) As TPCANStatus
public:
static TPCANStatus GetErrorText(
TPCANStatus Error,
unsigned short Language,
StringBuilder^ StringBuffer
)
- 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.
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.
TPCANStatus
The return value is a TPCANStatus value. PCAN_ERROR_OK is returned on success. The typical errors in case of failure are:
The "Primary language IDs" are codes used by Windows OS from Microsoft, to identify a human language. Currently,
following languages are supported:
Language | Primary Language ID |
---|
Neutral (System dependent) | 00h (0) |
English | 09h (9) |
German | 07h (7) |
French | 0Ch (12) |
Italian | 10h (16) |
Spanish | 0Ah (10) |
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).
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());
Dim result As TPCANStatus
Dim strMsg As System.Text.StringBuilder
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 Then
' An error occurred, show a message indicating it
'
Console.WriteLine("Error when recovering Error-Code's description")
Else
Console.WriteLine(strMsg.ToString)
End If
TPCANStatus result;
System::Text::StringBuilder^ strMsg;
strMsg = gcnew 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());