PCANBasicReset Method

Discards all messages contained in the receive and transmit queues of a PCAN Channel.

Definition

Namespace: Peak.Can.Basic.BackwardCompatibility
Assembly: PCANBasic.NET (in PCANBasic.NET.dll) Version: 4.9.0
C#
public static TPCANStatus Reset(
	ushort Channel
)

Parameters

Channel  UInt16
The handle of a PCAN Channel (see PCAN Handle Definitions).

Return Value

TPCANStatus

The return value is a TPCANStatus value. PCAN_ERROR_OK is returned on success. The typical errors in case of failure are:

  • PCAN_ERROR_INITIALIZE: Indicates that the given PCAN channel was not found in the list of initialized channels of the calling application.
  • PCAN_ERROR_ILLHANDLE: Indicates that the given PCAN Channel is not valid.

Remarks

Calling this method ONLY clears the queues of a Channel. A reset of the CAN controller doesn't take place, unless the parameter PCAN_HARD_RESET_STATUS is active.

Normally a reset of the CAN Controller is desired when a bus-off occur. In this case an application cannot use the channel to communicate anymore, until the CAN controller is reset. Consider using the PCAN_BUSOFF_AUTORESET parameter, which instructs the API to automatically reset the CAN controller when a bus-off state is detected.

Another way to reset errors like bus-off, bus-heavy and bus-light:

  • Performing an uninitialize / initialize cycle: This causes a hardware reset, but only when no more clients are connected to that channel.
  • Using the parameter PCAN_HARD_RESET_STATUS: It instructs this method to explicitly perform a hardware reset regardless of whether other clients are connected to that channel.

Example

The following example shows the use of the Reset(UInt16) method on the channel PCAN_PCIBUS1. In case of failure, the returned code will be translated to a text (according with the operating system language) in English, German, Italian, French or Spanish, and it will be shown to the user.

  Note

It is assumed that the channel was already initialized

C#
TPCANStatus result;
System.Text.StringBuilder strMsg;

strMsg = new System.Text.StringBuilder(256);

// ... channel is initialized and communication takes place ...
// ... when needed, the queues are cleared ...

// The PCI Channel is reset
//
result = PCANBasic.Reset(PCANBasic.PCAN_PCIBUS1);
if (result != TPCANStatus.PCAN_ERROR_OK)
{
    // An error occurred, get a text describing the error and show it
    //
    PCANBasic.GetErrorText(result, 0, strMsg);
    Console.WriteLine(strMsg.ToString());
}
else
    Console.WriteLine("PCAN-PCI (Ch-1) was reset");

See Also