WorkerStart Method

Establishes a connection to a PCAN Channel, configures it for data transmission and starts the read/write processes.

Definition

Namespace: Peak.Can.Basic
Assembly: PCANBasic.NET (in PCANBasic.NET.dll) Version: 4.9.0
C#
public void Start(
	bool ignoreBitrateCheck = false,
	bool deactivateReading = false,
	bool deactivateBroadcasting = false
)

Parameters

ignoreBitrateCheck  Boolean  (Optional)
If the connection should still occur, even if the PCAN channel is already initialized with a different bit rate (FD) as the specified.
deactivateReading  Boolean  (Optional)
If message fetching should be deactivated on connection. After connection, the status of message fetching can be controlled by using the property MessageFetching.
deactivateBroadcasting  Boolean  (Optional)
If message broadcasting should be deactivated on connection. After connection, the status of message broadcasting can be controlled by using the property MessageBroadcasting.

Remarks

About reading:

A Worker object can handle multiple receive queues. Only one receive queue is active by default when the object is created, and its filter is configured to receive any message.

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 configured using the AddBroadcast method. The processing of current registered Broadcast items can be stopped and resumed again using the methods PauseBroadcast and ResumeBroadcast respectively. A specific Broadcast item, or all of them, can be removed using the methods RemoveBroacast and ClearBroadcasts respectively.

Example

The following example shows the activation and deactivation of 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();

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

    // 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

DllNotFoundExceptionThe underlying PCANBasic.dll library could not be found.
PcanBasicExceptionThe execution of a PCAN-Basic related operation ended with an unexpected result.

See Also