GetErrorText(TPCANStatus,UInt16,String)

PCAN-Basic

PCAN-Basic Documentation
Home
PreviousUpNext
GetErrorText(TPCANStatus,UInt16,String)

Gets a descriptive text for an error code.

Syntax
class function GetErrorText(
    AnError: TPCANStatus;
    Language: Word;
    StringBuffer: PChar
    ): TPCANStatus;
[DllImport("PCANBasic.dll", EntryPoint = "CAN_GetErrorText")]
public static extern TPCANStatus GetErrorText(
    [MarshalAs(UnmanagedType.U4)]
    TPCANStatus AnError,
    UInt16 Language,
    StringBuilder StringBuffer);
[DllImport("PCANBasic.dll", EntryPoint = "CAN_GetErrorText")]
static TPCANStatus GetErrorText(
    [MarshalAs(UnmanagedType::U4)]
    TPCANStatus AnError,
    UInt16 Language,
    StringBuilder^ StringBuffer);
<DllImport("PCANBasic.dll", EntryPoint:="CAN_GetErrorText")> _
Public Shared Function GetErrorText( _
    <MarshalAs(UnmanagedType.U4)> _
    ByVal AnError As TPCANStatus, _
    ByVal Language As UInt16, _
    ByVal StringBuffer As StringBuilder) As TPCANStatus
End Function
Parameters 
Description 
AnError 
A TPCANStatus error code. 
Language 
Indicates a "Primary language ID". 
StringBuffer 
A buffer for a null-terminated char array. 

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

PCAN_ERROR_ILLPARAMVAL: 
Indicates that the parameters passed to the method are invalid. Check the parameter 'Buffer'; it should point to a char array, big enough to allocate the text for the given error code. 

The "Primary language IDs" are codes used by Windows OS from Microsoft, to identify a human language. The PCAN-Basic API currently support the following languages:

Language 
Primary Language ID 
Neutral (System dependant) 
00h (0) 
English 
09h (9) 
German 
07h (7) 
French 
0Ch (12) 
Italian 
10h (16) 
Spanish 
0Ah (10) 

Note: If the buffer is to small for the resulting text, the error PCAN_ERROR_ILLPARAMVAL is returned. Even when only short texts are being currently returned, a text within this function can have a maximum of 255 characters. For this reason it is recommended to use a buffer with a length of at least 256 bytes.

The following example shows the use of the method GetErrorText to get the description of an error. The language of the description's text will be the same used by the operating system (if its language is supported; otherwise English is used). 

C#:  

TPCANStatus result;
StringBuilder strMsg;

strMsg = new 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
    //
    MessageBox.Show("Error when recovering Error-Code's description");
else
    MessageBox.Show(strMsg.ToString());

C++/CLR:

TPCANStatus result;
StringBuilder^ strMsg;

strMsg = gcnew 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
    //
    MessageBox::Show("Error when recovering Error-Code's description");
else
    MessageBox::Show(strMsg->ToString());

Visual Basic:

Dim result As TPCANStatus
Dim strMsg As StringBuilder

strMsg = New 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
    '
    MessageBox.Show("Error when recovering Error-Code's description")
Else
    MessageBox.Show(strMsg.ToString)
End If

Pascal OO:

var
 result : TPCANStatus;
 strMsg: array [0..256] of Char;
begin

    // Gets the description text for PCAN_ERROR_INITIALIZE using the Neutral language
    //
    result := TPCANBasic.GetErrorText(PCAN_ERROR_INITIALIZE, 0, strMsg);
    If (result <> PCAN_ERROR_OK) Then
        // An error occurred, show a message indicating it
        //
        MessageBox(0, Error when recovering Error-Code's description','Error',MB_OK)
    else
        MessageBox(0,strMsg,'Success', MB_OK);

Primary Language ID 

 

Plain function Version: CAN_GetErrorText

Copyright © 2017. PEAK-System Technik GmbH. All rights reserved.
Send feedback to this documentation