CAN_GetStatus

PCAN-Basic

PCAN-Basic Documentation
Home
PreviousUpNext
CAN_GetStatus

Gets the current BUS status of a PCAN Channel.

Syntax
TPCANStatus __stdcall CAN_GetStatus(
        TPCANHandle Channel
);
Parameters 
Description 
Channel 
The handle of a PCAN Channel (see TPCANHandle). 

The return value is a TPCANStatus code. The typical return values 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_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_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. 

When the hardware status is bus-off, an application cannot communicate anymore. Consider using the PCAN-Basic property PCAN_BUSOFF_AUTORESET 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, is to uninitialize and initialise again the channel used. This causes a hardware reset.

The following example shows the use of CAN_GetStatus 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;
char strMsg[256];

// Check the status of the PCI Channel
//
result = CAN_GetStatus(PCAN_PCIBUS1);
switch(result)
{
    case PCAN_ERROR_BUSLIGHT:
        MessageBox("PCAN-PCI (Ch-1): Handling a BUS-LIGHT status...");
        break;
    case PCAN_ERROR_BUSHEAVY:
        MessageBox("PCAN-PCI (Ch-1): Handling a BUS-HEAVY status...");
        break;
    case PCAN_ERROR_BUSOFF:
        MessageBox("PCAN-PCI (Ch-1): Handling a BUS-OFF status...");
        break;
    case PCAN_ERROR_OK:
        MessageBox("PCAN-PCI (Ch-1): Status is OK");
        break;
    default:
        // An error occurred, get a text describing the error and show it
        //
        CAN_GetErrorText(result, 0, strMsg);
        MessageBox(strMsg);
        break;
}
Copyright © 2017. PEAK-System Technik GmbH. All rights reserved.
Send feedback to this documentation