PCANBasicGetStatus Method

Gets the current BUS status 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 GetStatus(
	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_ILLHW: Indicates that the hardware represented by the PCAN Channel being used was removed or deactivated.
  • PCAN_ERROR_ILLHANDLE: Indicates that the given PCAN Channel is not valid.
  • PCAN_ERROR_BUSLIGHT: Indicates a bus error within the given PCAN Channel. The hardware is in bus-light status.
  • PCAN_ERROR_BUSHEAVY: Indicates a bus error within the given PCAN Channel. The hardware is in bus-heavy status.
  • PCAN_ERROR_BUSPASSIVE: Indicates a bus error within the given PCAN Channel. The hardware is in bus-passive status.
  • PCAN_ERROR_BUSWARNING: Indicates a bus error within the given PCAN Channel. The hardware is in bus-warning status.
  • PCAN_ERROR_BUSOFF: Indicates a bus error within the given PCAN Channel. The hardware is in bus-off status.
  • PCAN_ERROR_OK: Indicates that the status of the given PCAN Channel is OK.

Remarks

When the hardware status is bus-off, an application cannot communicate anymore. 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-warning and bus-passive:

  • 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 GetStatus 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, check the status of the Channel

// The status of the PCI Channel is checked
//
result = PCANBasic.GetStatus(PCANBasic.PCAN_PCIBUS1);
switch (result)
{
    case TPCANStatus.PCAN_ERROR_BUSLIGHT:
        Console.WriteLine("PCAN-PCI (Ch-1): Handling a BUS-LIGHT status...");
        break;
    case TPCANStatus.PCAN_ERROR_BUSHEAVY:
        Console.WriteLine("PCAN-PCI (Ch-1): Handling a BUS-HEAVY status...");
        break;
    case TPCANStatus.PCAN_ERROR_BUSOFF:
        Console.WriteLine("PCAN-PCI (Ch-1): Handling a BUS-OFF status...");
        break;
    case TPCANStatus.PCAN_ERROR_OK:
        Console.WriteLine("PCAN-PCI (Ch-1): Status is OK");
        break;
    default:
        // An error occurred, get a text describing the error and show it
        //
        PCANBasic.GetErrorText(result, 0, strMsg);
        Console.WriteLine(strMsg.ToString());
        break;
}

See Also