Important
For more information about each available TPCANParameter, please refer to the companion PDF documentation PCAN-Parameter_Documentation.pdf.
public static TPCANStatus SetValue(
ushort Channel,
TPCANParameter Parameter,
ref ulong NumericBuffer,
uint BufferLength
)
Public Shared Function SetValue (
Channel As UShort,
Parameter As TPCANParameter,
ByRef NumericBuffer As ULong,
BufferLength As UInteger
) As TPCANStatus
public:
static TPCANStatus SetValue(
unsigned short Channel,
TPCANParameter Parameter,
unsigned long long% NumericBuffer,
unsigned int BufferLength
)
The return value is a TPCANStatus value. PCAN_ERROR_OK is returned on success. The typical errors in case of failure are:
Use the method SetValue to change the behavior of a PCAN Channel like its Acceptance Filter (Mask/Code). Take in account that not all parameters are supported for all PCAN Channels. The access's type of the parameters can also be different.
For more information about the possible values that can be used for parameter configuration, see Parameter Value Definitions
The following example shows the use of SetValue(UInt16, TPCANParameter, UInt64, UInt32) method on the channel PCAN_USBBUS1 to set an acceptance filter as a 11-bit code and mask, allowing only IDs from 0x100 to 0x103. 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.
TPCANStatus result;
System.Text.StringBuilder strMsg;
UInt64 i64Buffer;
strMsg = new System.Text.StringBuilder(256);
// The acceptance code and mask are packed as 64-bit value
//
i64Buffer = 0x100; // Acceptance code
i64Buffer <<= 32;
i64Buffer |= 0x003; // Acceptance mask
result = PCANBasic.SetValue(PCANBasic.PCAN_USBBUS1, TPCANParameter.PCAN_ACCEPTANCE_FILTER_11BIT, ref 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);
Console.WriteLine(strMsg.ToString());
}
else
Console.WriteLine("The 11-bit acceptance filter was configured successfully");
Dim result As TPCANStatus
Dim strMsg As System.Text.StringBuilder
Dim i64Buffer As UInt64
strMsg = New System.Text.StringBuilder(256)
' ... channel is initialized ...
' The acceptance code and mask are packed as 64-bit value
'
i64Buffer = &H100 ' Acceptance code
i64Buffer <<= 32
i64Buffer = i64Buffer Or &H3 ' Acceptance mask
result = PCANBasic.SetValue(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)
Console.WriteLine(strMsg.ToString)
Else
Console.WriteLine("The 11-bit acceptance filter was configured successfully")
End If
TPCANStatus result;
System::Text::StringBuilder^ strMsg;
UInt64 i64Buffer;
strMsg = gcnew System::Text::StringBuilder(256);
// ... channel is initialized ...
// The acceptance code and mask are packed as 64-bit value
//
i64Buffer = 0x100; // Acceptance code
i64Buffer <<= 32;
i64Buffer |= 0x003; // Acceptance mask
result = PCANBasic::SetValue(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);
Console::WriteLine(strMsg->ToString());
}
else
Console::WriteLine("The 11-bit acceptance filter was configured successfully");