Important
After a PCAN Channel is initialized, its filter is fully opened, causing any message received by the hardware to be placed in the receive queue of the Channel.
public static PcanStatus FilterMessages(
PcanChannel channel,
uint fromID,
uint toID,
FilterMode mode
)
Public Shared Function FilterMessages (
channel As PcanChannel,
fromID As UInteger,
toID As UInteger,
mode As FilterMode
) As PcanStatus
public:
static PcanStatus FilterMessages(
PcanChannel channel,
unsigned int fromID,
unsigned int toID,
FilterMode mode
)
The lowest value allowed is 0.The highest value allowed is 0x7FF if mode equals to Standard, and 0x1FFFFFFF if mode equals to Extended.
The lowest value allowed is 0. The highest value allowed is 0x7FF if mode equals to Standard, and 0x1FFFFFFF if mode equals to Extended.
OK is returned on success. The typical errors in case of failure are:
Based on the current state of the filter, calling this method results in the following behavior:
Take into account that configuring the message filter causes the CAN controller to enter the reset state. This will affect other applications that communicate with the same PCAN hardware.
The following example shows the use of the FilterMessages method using the USB interface (first PCAN-USB hardware). A Channel is initialized and its filter is configured to get only messages with ID 2,3,4 or 5.
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.
PcanChannel channel = PcanChannel.Usb01;
// The hardware represented by the given handle is initialized with 500 kBit/s bit rate (BTR0/BTR1 0x001C)
//
PcanStatus result = Api.Initialize(channel, Bitrate.Pcan500);
if (result != PcanStatus.OK)
{
// An error occurred
//
Api.GetErrorText(result, out var errorText);
Console.WriteLine(errorText);
}
else
{
// A success message on connection is shown.
//
Console.WriteLine($"The hardware represented by the handle {channel} was successfully initialized.");
// The message filter is fully open after initialization.
// Configuring a custom acceptance range automatically closes the filter first.
// The messages with ID in the range [2,5] is configured.
//
result = Api.FilterMessages(channel, 2, 5, FilterMode.Standard);
if (result != PcanStatus.OK)
{
// An error occurred, get a text describing the error and show it
//
Api.GetErrorText(result, out var errorText);
Console.WriteLine(errorText);
}
else
Console.WriteLine("The message filter was successfully configured for IDs 2,3,4 and 5.");
// The connection to the hardware is finalized when it is no longer needed
//
result = Api.Uninitialize(channel);
if (result != PcanStatus.OK)
{
// An error occurred
//
Api.GetErrorText(result, out var errorText);
Console.WriteLine(errorText);
}
else
Console.WriteLine($"The hardware represented by the handle {channel} was successfully finalized.");
}
Dim channel As PcanChannel = PcanChannel.Usb01
' The hardware represented by the given handle is initialized with 500 kBit/s bit rate (BTR0/BTR1 0x001C)
'
Dim result As PcanStatus = Api.Initialize(channel, Bitrate.Pcan500)
' An error occurred
'
Dim errorText = Nothing
If result <> PcanStatus.OK Then
Api.GetErrorText(result, errorText)
Console.WriteLine(errorText)
Else
' A success message on connection is shown.
'
Console.WriteLine($"The hardware represented by the handle {channel} was successfully initialized.")
' The message filter Is fully open after initialization.
' Configuring a custom acceptance range automatically closes the filter first.
' The messages with ID in the range [2,5] Is configured.
'
result = Api.FilterMessages(channel, 2, 5, FilterMode.Standard)
If result <> PcanStatus.OK Then
' An error occurred, get a text describing the error And show it
'
Api.GetErrorText(result, errorText)
Console.WriteLine(errorText)
Else
Console.WriteLine("The message filter was successfully configured for IDs 2,3,4 and 5.")
End If
' The connection to the hardware is finalized when it is no longer needed
'
result = Api.Uninitialize(channel)
If result <> PcanStatus.OK Then
Api.GetErrorText(result, errorText)
Console.WriteLine(errorText)
Else
Console.WriteLine($"The hardware represented by the handle {channel} was successfully finalized.")
End If
End If
PcanChannel channel = PcanChannel::Usb01;
String^ errorText;
// The hardware represented by the given handle is initialized with 500 kBit/s bit rate (BTR0/BTR1 0x001C)
//
PcanStatus result = Api::Initialize(channel, Bitrate::Pcan500);
if (result != PcanStatus::OK)
{
// An error occurred
//
Api::GetErrorText(result, errorText);
Console::WriteLine(errorText);
}
else
{
// A success message on connection is shown.
//
Console::WriteLine("The hardware represented by the handle {0} was successfully initialized.", channel);
// The message filter is fully open after initialization.
// Configuring a custom acceptance range automatically closes the filter first.
// The messages with ID in the range [2,5] is configured.
//
result = Api::FilterMessages(channel, 2, 5, FilterMode::Standard);
if (result != PcanStatus::OK)
{
// An error occurred, get a text describing the error and show it
//
Api::GetErrorText(result, errorText);
Console::WriteLine(errorText);
}
else
Console::WriteLine("The message filter was successfully configured for IDs 2,3,4 and 5.");
// The connection to the hardware is finalized when it is no longer needed
//
result = Api::Uninitialize(channel);
if (result != PcanStatus::OK)
{
// An error occurred
//
Api::GetErrorText(result, errorText);
Console::WriteLine(errorText);
}
else
Console::WriteLine("The hardware represented by the handle {0} was successfully finalized.", channel);
}
DllNotFoundException | The underlying PCANBasic.dll library could not be found. |
PcanBasicException | The execution of a PCAN-Basic related check operation ended with an unexpected result. Typically, this exception is triggered when a device driver is not installed or is not up to date. |