GetValue(TPCANHandle, TPCANParameter, UInt64, UInt32)

PCAN-Basic

PCAN-Basic Documentation
Home
PreviousUpNext
GetValue(TPCANHandle, TPCANParameter, UInt64, UInt32)

Retrieves information from a PCAN Channel in numeric form.

class function GetValue(
    Channel: TPCANHandle;
    Parameter: TPCANParameter;
    NumericBuffer: PUInt64;
    BufferLength: LongWord
    ): TPCANStatus; overload;
[DllImport("PCANBasic.dll", EntryPoint = "CAN_GetValue")]
public static extern TPCANStatus GetValue(
    [MarshalAs(UnmanagedType.U1)]
    TPCANHandle Channel,
    [MarshalAs(UnmanagedType.U1)]
    TPCANParameter Parameter,
    out UInt64 NumericBuffer,
    UInt32 BufferLength);
[DllImport("PCANBasic.dll", EntryPoint = "CAN_GetValue")]
static TPCANStatus GetValue(
    [MarshalAs(UnmanagedType::U1)]
    TPCANHandle Channel,
    [MarshalAs(UnmanagedType::U1)]
    TPCANParameter Parameter,
    UInt64 %NumericBuffer,
    UInt32 BufferLength);
<DllImport("PCANBasic.dll", EntryPoint:="CAN_GetValue")> _
Public Shared Function GetValue( _
    <MarshalAs(UnmanagedType.U1)> _
    ByVal Channel As TPCANHandle, _
    <MarshalAs(UnmanagedType.U1)> _
    ByVal Parameter As TPCANParameter, _
    ByRef NumericBuffer As UInt64, _
    ByVal BufferLength As UInt32) As TPCANStatus
End Function
Parameters 
Description 
Channel 
The handle of a PCAN Channel (see TPCANHandle). 
Parameter 
The code of the information to be retrieved (see TPCANParameter). 
NumericBuffer 
The buffer to return the required 64-bit numeric value. 
BufferLength 
The length in bytes of the given buffer. 

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 'NumericBuffer'; it should point to a 64-bit integer buffer. 
PCAN_ERROR_INITIALIZE: 
Indicates that the given PCAN channel was not found in the list of initialized channels of the calling application. 
PCAN_ERROR_ILLPARAMTYPE: 
Indicates that the requested information is not available for the given PCAN Channel. Check the value of 'Parameter'; some values are not available for all PCAN-Channels or cannot be read. 

Use the method GetValue to get information about PCAN environment as parameters like an Acceptance Filter. Take in account that not all parameters are supported for all PCAN-Channels. The access's type of the parameters can also be different. 

More information about the parameters and values that can be read can be found in Parameter Value Definitions.

The following example shows the use of the method GetValue on the channel PCAN_USBBUS1 to retrieve the configured message filter as 11-bit acceptance code and mask. 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. 

Note: It is assumed that the channel was already initialized. 

C#:  

TPCANStatus result;
StringBuilder strMsg;
UInt64 i64Buffer;
UInt32 iCode, iMask;

strMsg = new StringBuilder(256);

// The 11-bit acceptance filter of the PCAN-USB Channel 1 is asked
//
result = PCANBasic.GetValue(PCANBasic.PCAN_USBBUS1, TPCANParameter.PCAN_ACCEPTANCE_FILTER_11BIT, out i64Buffer, sizeof(UInt64));
if (result != TPCANStatus.PCAN_ERROR_OK)
{
    // An error occurred, get a text describing the error and show it
    //
    PCANBasic.GetErrorText(result, 0, strMsg);
    MessageBox.Show(strMsg.ToString());
}
else
{
    // Code and mask are extracted from the 64-bit numeric value
    //
    iCode = Convert.ToUInt32((i64Buffer >> 32);
    iMask = Convert.ToUInt32(i64Buffer & UInt32.MaxValue);

    // A text is shown giving information about the 11-bit mask and code of the acceptance filter
    //
    MessageBox.Show(string.Format("Configured 11-bit acceptance filter: Code: {0:X8} | Mask: {1:X8}", iCode, iMask));
}

C++/CLR:

TPCANStatus result;
StringBuilder^ strMsg;
UInt64 i64Buffer;
UInt32 iCode, iMask;

strMsg = gcnew StringBuilder(256);

// The 11-bit acceptance filter of the PCAN-USB Channel 1 is asked
//
result = PCANBasic::GetValue(PCANBasic::PCAN_USBBUS1, TPCANParameter::PCAN_ACCEPTANCE_FILTER_11BIT, i64Buffer, sizeof(i64Buffer));
if (result != TPCANStatus::PCAN_ERROR_OK)
{
    // An error occurred, get a text describing the error and show it
    //
    PCANBasic::GetErrorText(result, 0, strMsg);
    MessageBox::Show(strMsg->ToString());
}
else
{
    // Code and mask are extracted from the 64-bit numeric value
    //
    iCode = Convert::ToUInt32((i64Buffer >> 32);
    iMask = Convert::ToUInt32(i64Buffer & UInt32::MaxValue);

    // A text is shown giving information about the 11-bit mask and code of the acceptance filter
    //
    MessageBox::Show(String::Format("Configured 11-bit acceptance filter: Code: {0:X8} | Mask: {1:X8}", iCode, iMask));
}

Visual Basic:

Dim result As TPCANStatus
Dim strMsg As StringBuilder
Dim i64Buffer As UInt64
Dim iCode As UInt32
Dim iMask As UInt32

strMsg = New StringBuilder(256)

' The 11-bit acceptance filter of the PCAN-USB Channel 1 is asked
'
result = PCANBasic.GetValue(PCANBasic.PCAN_USBBUS1, TPCANParameter.PCAN_ACCEPTANCE_FILTER_11BIT, i64Buffer, CType(System.Runtime.InteropServices.Marshal.SizeOf(i64Buffer), UInteger))
If result <> TPCANStatus.PCAN_ERROR_OK Then
    ' An error occurred, get a text describing the error and show it
    '
    PCANBasic.GetErrorText(result, 0, strMsg)
    MessageBox.Show(strMsg.ToString())
Else
    ' Code and mask are extracted from the 64-bit numeric value
    '
    iCode = Convert.ToUInt32(i64Buffer >> 32)
    iMask = Convert.ToUInt32(i64Buffer And UInt32.MaxValue)

    ' A text is shown giving information about the 11-bit mask and code of the acceptance filter
    '
    MessageBox.Show(String.Format("Configured 11-bit acceptance filter: Code: {0:X8} | Mask: {1:X8}", iCode, iMask))
End If

Pascal OO:

var
    result : TPCANStatus;
    strMsg: array [0..256] of Char;
    i64Buffer: UInt64;
    iCode, iMask: LongWord;
begin
    // The 11-bit acceptance filter of the PCAN-USB Channel 1 is asked
    //
    result := TPCANBasic.GetValue(TPCANBasic.PCAN_USBBUS1, PCAN_ACCEPTANCE_FILTER_11BIT, PUInt64(@i64Buffer), sizeof(i64Buffer));
    If (result <> PCAN_ERROR_OK) Then
    begin
        // An error occurred, get a text describing the error and show it
        //
        TPCANBasic.GetErrorText(result, 0, strMsg);
        MessageBox(0, strMsg, 'Error',MB_OK);
    end
    else
    begin
        // Code and mask are extracted from the 64-bit numeric value
        //
        iCode := i64Buffer shr 32;
        iMask := (i64Buffer And $FFFFFFFF);

        // A text is shown giving information about the 11-bit mask and code of the acceptance filter
        //
        MessageBox(0, PChar(Format('Configured 11-bit acceptance filter: Code: %.8X | Mask: %.8X', [iCode, iMask])), 'Success',MB_OK);
    end;
end;
Copyright © 2017. PEAK-System Technik GmbH. All rights reserved.
Send feedback to this documentation