WorkerGetFilters Method

Retrieves the current configured filtering criteria for the default receive queue (index 0).

Definition

Namespace: Peak.Can.Basic
Assembly: PCANBasic.NET (in PCANBasic.NET.dll) Version: 4.9.0
C#
public FilteringCriterion[] GetFilters()

Return Value

FilteringCriterion
An array containing all registered filtering criteria.

Remarks

The FilteringCriterion returned by this methods cannot be modified. If it is desired to change any already registered filter criterion, it has to be removed first using the RemoveFilter method and added again using the AddFilter method.

Example

The following example shows how to configure the message filter of the default receive queue (index 0) to receive only echo messages with extended ID 0x15. After this, the filtering criteria are read and sent to the console output.

In case of failure, an error messages is written to the console output using English as output language.

C#
// Create the object using the default configuration
//
Worker myWorker = new Worker();

// Set the filter of the default receive queue (index 0) to receive only echo messages
//
FilteringCriterion criterion = new FilteringCriterion();
criterion.SetMessageType(MessageType.Echo, FilterBehavior.Include);
if (!myWorker.AddFilter(criterion))
    Console.WriteLine("The given filter is already registered.");
else
    Console.WriteLine("Filter for Echo messages was configured successfully.");

// Set the filter of the default receive queue (index 0) to receive only
// messages with extended ID 0x00000015
//
criterion.SetSingleId(0x15, FilterMode.Extended);
if (!myWorker.AddFilter(criterion))
    Console.WriteLine("The given filter is already registered.");
else
    Console.WriteLine("Filter for messages with extended ID equals to 0x15 was configured successfully.");

// Get and show the filtering criteria
//
Console.WriteLine("Following criteria are configured:");
foreach (FilteringCriterion item in myWorker.GetFilters())
{
    Console.WriteLine($" -> {item}");
}

See Also