Note
It is assumed that the channel was already initialized
public static TPCANStatus GetStatus(
ushort Channel
)
Public Shared Function GetStatus (
Channel As UShort
) As TPCANStatus
public:
static TPCANStatus GetStatus(
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:
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:
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.
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;
}
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, check the status of the Channel
' The status of the PCI Channel is checked
'
result = PCANBasic.GetStatus(PCANBasic.PCAN_PCIBUS1)
Select Case result
Case TPCANStatus.PCAN_ERROR_BUSLIGHT
Console.WriteLine("PCAN-PCI (Ch-1): Handling a BUS-LIGHT status...")
Case TPCANStatus.PCAN_ERROR_BUSHEAVY
Console.WriteLine("PCAN-PCI (Ch-1): Handling a BUS-HEAVY status...")
Case TPCANStatus.PCAN_ERROR_BUSOFF
Console.WriteLine("PCAN-PCI (Ch-1): Handling a BUS-OFF status...")
Case TPCANStatus.PCAN_ERROR_OK
Console.WriteLine("PCAN-PCI (Ch-1): Status is OK")
Case Else
' An error occurred, get a text describing the error and show it
'
PCANBasic.GetErrorText(result, 0, strMsg)
Console.WriteLine(strMsg.ToString)
End Select
TPCANStatus result;
System::Text::StringBuilder^ strMsg;
strMsg = gcnew 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;
}