WorkerSetFilteringState(Int32, FilteringState, Boolean) Method

Configures the behavior of the message filter for a specific receive queue.

Definition

Namespace: Peak.Can.Basic
Assembly: PCANBasic.NET (in PCANBasic.NET.dll) Version: 4.9.0
C#
public void SetFilteringState(
	int queueIndex,
	FilteringState state,
	bool discardCurrentMessages = false
)

Parameters

queueIndex  Int32
Zero-based index that identifies the receive queue to be configured.
state  FilteringState
Indicates the desired filtering behavior for a receive queue.
discardCurrentMessages  Boolean  (Optional)
Indicates if messages currently contained by the receive queue are to be discarded on status change.

Remarks

The Worker registers 'ReceiveQueuesCount' receive queues. These are 0-indexed. The first queue (index 0) is open by default when the object is created, meaning, its message filter is set to PassForAll. All other queues remain closed, that is, their filters are configured as BlockForAll. The methods associated with a receive queue are overloaded, allowing either the direct use of the default queue (index 0) without specifying an index, or the use of a specific queue by passing an index.

Example

The following example shows how to activate a second queue, after creating a Worker object.

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 to discard all messages
//
myWorker.SetFilteringState(FilteringState.BlockForAll);

try
{
    // Activate the worker object
    //
    myWorker.Start();
    Console.WriteLine("The Worker object was activated successfully - Messages are being discarded.");

    // Deactivate the worker object, when it is no longer needed
    //
    myWorker.Stop();
    Console.WriteLine("The Worker object was deactivated.");
}
catch(Exception ex)
{
    Console.WriteLine($"An exception occurred by activating the Worker object. {ex.Message}");
}

Exceptions

IndexOutOfRangeExceptionThe queueIndex parameter value is out of range. This must be in the range [0...ReceiveQueuesCount-1].

See Also