WorkerResetHardware(PcanStatus) Method

Performs a reset of the CAN controller on the hardware connected by the Worker object.

Definition

Namespace: Peak.Can.Basic
Assembly: PCANBasic.NET (in PCANBasic.NET.dll) Version: 5.1.0
C#
public bool ResetHardware(
	out PcanStatus error
)

Parameters

error  PcanStatus
In case of failure, the PcanStatus error code resulting when trying to reset the hardware.

Return Value

Boolean
true if the Worker object could perform a hardware reset; false otherwise.

Remarks

Performing a hardware reset will cause the CAN controller to go bus off for a while. This can momentarily disrupt CAN communication and affect other clients connected to the same hardware, generating error frames from other nodes and preventing messages from being sent/received.

Resetting the hardware does not discard messages that have already been read by the Worker object. If it is desired to discard the received messages, the ClearAllReceiveQueues method should also be called.

Example

The following example shows how to perform a hardware reset on a PCAN channel connected by 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.");

    // Call the reset method 
    //
    if (myWorker.ResetHardware(out var error))
        Console.WriteLine("The underlying device was successfully reset.");
    else
        Console.WriteLine($"The device couldn't be reset: {error}.");

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

See Also