public bool ResetHardware()Public Function ResetHardware As Booleanpublic:
bool ResetHardware()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.
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.
// 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}");
}' Create the object using the default configuration
'
Dim myWorker As Worker = New Worker()
Try
' Activate the worker object
'
myWorker.Start()
Console.WriteLine("The Worker object was activated successfully.")
' Call the reset method
'
Dim [error] = Nothing
If myWorker.ResetHardware([error]) Then
Console.WriteLine("The underlying device was successfully reset.")
Else
Console.WriteLine($"The device couldn't be reset: {[error]}.")
End If
' Deactivate the worker object, when it is no longer needed
'
myWorker.[Stop]()
Console.WriteLine("The Worker object was deactivated.")
Catch ex As Exception
Console.WriteLine($"An exception occurred by activating the Worker object. {ex.Message}")
End Try// Create the object using the default configuration
//
Worker^ myWorker = gcnew Worker();
// Activate the worker object
//
try
{
myWorker->Start(false, false, false);
Console::WriteLine("The Worker object was activated successfully.");
// Create a CAN message and send it
//
PcanStatus error;
if (myWorker->ResetHardware(error))
Console::WriteLine("The underlying device was successfully reset.");
else
Console::WriteLine("The device couldn't be reset: {0}.", error);
// Deactivate the worker object, when it is no longer needed
//
myWorker->Stop(false, false, false);
Console::WriteLine("The Worker object was deactivated.");
}
catch (Exception^ ex)
{
Console::WriteLine("An exception occurred by activating the Worker object. {0}", ex->Message);
}| DllNotFoundException | The underlying PCANBasic.dll library could not be found. |
| PcanBasicException | The 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. |