Note
It is assumed that the channel was already initialized
public static TPCANStatus Reset(
ushort Channel
)
Public Shared Function Reset (
Channel As UShort
) As TPCANStatus
public:
static TPCANStatus Reset(
unsigned short Channel
)
The return value is a TPCANStatus value. PCAN_ERROR_OK is returned on success. The typical errors in case of failure are:
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:
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.
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");
Dim result As TPCANStatus
Dim strMsg As System.Text.StringBuilder
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 Then
' 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")
End If
TPCANStatus result;
System::Text::StringBuilder^ strMsg;
strMsg = gcnew 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");