Worker Class

PCAN Worker class implementation.

Worker makes use of the Api class to allows reading and writing from and to a PCAN Channel in an automatic way, using timers and events. It allows a more accurate filtering system that the native one, and the use of multiple receive queues with separate filter configuration.

If direct access to the PCAN-Basic interface is desired, use the Api class instead.

Definition

Namespace: Peak.Can.Basic
Assembly: PCANBasic.NET (in PCANBasic.NET.dll) Version: 4.8.2
C#
public class Worker
Inheritance
Object    Worker

Remarks

About reading:

The Worker object does have multiple receive queues. Only one of those receive queues is active by default when the object is created, and its filter is configured to receive any message. The remaining receive queues keep their filters closed.

The reading process is executed in an additional thread, making use of the event notification mechanism to fetch CAN messages. Fetched messages can be dequeued for their further processing using the Dequeue method. If needed, messages stored in one or all receive queues may be discarded using the methods ClearReceiveQueue and ClearAllReceiveQueues respectively.

Each receive queue has its own message filter. This message filter can be configured using several filtering criteria, in form of FilteringCriterion data, by using the AddFilter method. The message filtering in a receive queue can also be temporarily disabled/enabled at any time by using the SetFilteringState method. A specific filtering criterion, or all of them, can be removed using the methods RemoveFilter and ClearFilters respectively.

About writing:

There are two approaches for sending messages to the connected CAN network:

  1. Using the Transmit method, which places a CAN message in the connected Channel's transmit queue for immediate sending.
  2. Using a Broadcast message, which periodically places a configured CAN message in the connected Channel's transmit queue for immediate sending.

New Broadcast items can be registered using the AddBroadcast method. The processing of current registered Broadcast items can be stopped and resumed again using their Active property, or the methods PauseBroadcast and ResumeBroadcast respectively. A specific Broadcast item, or all of them, can be removed using the methods RemoveBroacast and ClearBroadcasts respectively.

Constructors

Worker Initializes a PCAN-Basic Worker object with its default values.
Worker(PcanChannel, Bitrate, Boolean) Initializes a PCAN-Basic Worker object.
Worker(PcanChannel, BitrateFD, Boolean) Initializes a PCAN-Basic Worker object.

Properties

Active Gets the activation status of this Worker object.
AllowEchoFrames Enables or disables receiving echo frames (see Echo).
AllowErrorFrames Enables or disables receiving error frames (see Error).
AllowRemoteRequestFrames Enables or disables receiving remote request frames (see RemoteRequest).
AllowStatusFrames Enables or disables receiving status frames (see Status).
BitrateCan Gets or sets the bit rate used for classic CAN 2.0A/B data transmission (see Bitrate).
BitrateCanFd Gets or sets the bit rate used for CAN FD data transmission (see BitrateFD).
BroadcastCount Retrieves the total amount of periodic messages currently configured within this object.
Channel Gets or set the PCAN Channel used for CAN communication.
ExceptionLanguage Specifies the language used for exception texts formatting.
ListenOnly Configures the CAN feature listen-only in the associated PCAN Channel.
MessageBroadcasting Enables or disables the sending of periodic messages.
MessageFetching Enables or disable the reading of messages.
TotalAvailableMessages Retrieves the total amount of messages currently contained by this object.
TransmissionProtocol Gets or sets the transport protocol used for CAN communication.

Methods

AddBroadcast(Broadcast) Configures a CAN message to be written periodically.
AddBroadcast(PcanMessage, Int32) Configures a CAN message to be written periodically.
AddFilter(FilteringCriterion) Includes an additional filtering criterion to the message filter of the default receive queue (index 0).
AddFilter(Int32, FilteringCriterion) Configures an additional filtering criterion to the message filter of a receive queue.
ClearAllReceiveQueues Discards all available messages from all receive queues.
ClearBroadcasts Removes all entries from the Worker object's broadcast list.
ClearFilters Removes all filtering criteria from the message filter of the default receive queue (index 0).
ClearFilters(Int32) Removes all filtering criteria from the message filter of the specified receive queue.
ClearReceiveQueue Discards all available messages from the default receive queue (index 0).
ClearReceiveQueue(Int32) Discards all available messages from the given receive queue.
Dequeue(PcanMessage, UInt64) Removes and returns a CAN messages and its timestamp from the default receive queue (index 0).
Dequeue(Int32, PcanMessage, UInt64) Removes and returns a CAN messages and its timestamp from a specific receive queue.
EqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Finalize Finalizes this object.
(Overrides ObjectFinalize)
GetAvailableMessagesCount Retrieves the amount of available messages currently contained in the default receive queue (index 0).
GetAvailableMessagesCount(Int32) Retrieves the amount of available messages currently contained in the specified receive queue.
GetBroadcast Retrieves a Broadcast object from the periodic CAN messages list.
GetFilters Retrieves the current configured filtering criteria for the default receive queue (index 0).
GetFilters(Int32) Retrieves the current configured filtering criteria of a specific receive queue.
GetHashCodeServes as the default hash function.
(Inherited from Object)
GetTypeGets the Type of the current instance.
(Inherited from Object)
MemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
PauseBroadcast Temporarily stops sending a periodic CAN message.
RemoveBroacast(Broadcast) Removes a periodic CAN message from the list of registered Broadcast objects.
RemoveBroacast(Int32) Removes a periodic CAN message from the list of registered Broadcast objects.
RemoveFilter(FilteringCriterion) Removes a filtering criterion from the message filter of the default receive queue (index 0).
RemoveFilter(Int32, FilteringCriterion) Removes a filtering criterion from the message filter of the specified receive queue.
ResumeBroadcast Resumes the sending of a paused periodic CAN message.
SetFilteringState(FilteringState, Boolean) Configures the behavior of the message filter for the default receive queue (index 0).
SetFilteringState(Int32, FilteringState, Boolean) Configures the behavior of the message filter for a specific receive queue.
Start Establishes a connection to a PCAN Channel, configures it for data transmission and starts the read/write processes.
Stop Disconnects the used PCAN Channel and stops reading and writing data.
ToStringReturns a string that represents the current object.
(Inherited from Object)
Transmit(PcanMessage) Places a CAN message into the transmit queue of the device driver to be written as soon as possible.
Transmit(PcanMessage, PcanStatus) Places a CAN message into the transmit queue of the device driver to be written as soon as possible.
UpdateBroadcast(Int32, PcanMessage) Adjusts the content of a periodic CAN message from the list of registered Broadcast objects.
UpdateBroadcast(Int32, Int32) Adjusts the sending interval of a periodic CAN message from the list of registered Broadcast objects.
UpdateBroadcast(Int32, Int32, PcanMessage) Adjusts the configuration of a periodic CAN message from the list of registered Broadcast objects.

Events

MessageAvailable Occurs when a message is received, validated and placed in a receive queue.

Fields

MaximumBroadcastCount Indicates the maximum amount of periodic messages that can be handled.
ReceiveQueuesCount Indicates the amount of receive queues available to use.

See Also