Gets the current BUS status of a PCAN Channel.
class function GetStatus( Channel: TPCANHandle ): TPCANStatus;
[DllImport("PCANBasic.dll", EntryPoint = "CAN_GetStatus")] public static extern TPCANStatus GetStatus( [MarshalAs(UnmanagedType.U1)] TPCANHandle Channel);
[DllImport("PCANBasic.dll", EntryPoint = "CAN_GetStatus")] static TPCANStatus GetStatus( [MarshalAs(UnmanagedType::U1)] TPCANHandle Channel);
<DllImport("PCANBasic.dll", EntryPoint:="CAN_GetStatus")> _ Public Shared Function GetStatus( _ <MarshalAs(UnmanagedType.U1)> _ ByVal Channel As TPCANHandle) As TPCANStatus End Function
def GetStatus( self, 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.
Python Notes
- Class-Method: Unlike the .NET Framework, under Python a variable has to be instantiated with an object of type PCANBasic in order to use the API functionality.
- Python's first argument convention: Under Python, 'self' is a parameter that is automatically included within the call of this method, within a PCANBasic object and hasn't to be indicated in a method call. This parameter represents the calling object itself.
The following example shows the use of the method 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; StringBuilder strMsg; strMsg = new StringBuilder(256); ...... // Check the status of the PCI Channel // result = PCANBasic.GetStatus(PCANBasic.PCAN_PCIBUS1); switch (result) { case TPCANStatus.PCAN_ERROR_BUSLIGHT: MessageBox.Show("PCAN-PCI (Ch-1): Handling a BUS-LIGHT status..."); break; case TPCANStatus.PCAN_ERROR_BUSHEAVY: MessageBox.Show("PCAN-PCI (Ch-1): Handling a BUS-HEAVY status..."); break; case TPCANStatus.PCAN_ERROR_BUSOFF: MessageBox.Show("PCAN-PCI (Ch-1): Handling a BUS-OFF status..."); break; case TPCANStatus.PCAN_ERROR_OK: MessageBox.Show("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); MessageBox.Show(strMsg.ToString()); break; }
C++/CLR:
TPCANStatus result; StringBuilder^ strMsg; strMsg = gcnew StringBuilder(256); ...... // Check the status of the PCI Channel // result = PCANBasic::GetStatus(PCANBasic::PCAN_PCIBUS1); switch (result) { case TPCANStatus::PCAN_ERROR_BUSLIGHT: MessageBox::Show("PCAN-PCI (Ch-1): Handling a BUS-LIGHT status..."); break; case TPCANStatus::PCAN_ERROR_BUSHEAVY: MessageBox::Show("PCAN-PCI (Ch-1): Handling a BUS-HEAVY status..."); break; case TPCANStatus::PCAN_ERROR_BUSOFF: MessageBox::Show("PCAN-PCI (Ch-1): Handling a BUS-OFF status..."); break; case TPCANStatus::PCAN_ERROR_OK: MessageBox::Show("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); MessageBox::Show(strMsg->ToString()); break; }
Visual Basic:
Dim result As TPCANStatus Dim strMsg As StringBuilder strMsg = New StringBuilder(256) ...... ' Check the status of the PCI Channel ' result = PCANBasic.GetStatus(PCANBasic.PCAN_PCIBUS1) Select Case result Case TPCANStatus.PCAN_ERROR_BUSLIGHT MessageBox.Show("PCAN-PCI (Ch-1): Handling a BUS-LIGHT status...") Case TPCANStatus.PCAN_ERROR_BUSHEAVY MessageBox.Show("PCAN-PCI (Ch-1): Handling a BUS-HEAVY status...") Case TPCANStatus.PCAN_ERROR_BUSOFF MessageBox.Show("PCAN-PCI (Ch-1): Handling a BUS-OFF status...") Case TPCANStatus.PCAN_ERROR_OK MessageBox.Show("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) MessageBox.Show(strMsg.ToString) End Select
Pascal OO:
var result : TPCANStatus; strMsg: array [0..256] of Char; begin ...... // Check the status of the PCI Channel // result := TPCANBasic.GetStatus(TPCANBasic.PCAN_PCIBUS1); case result of PCAN_ERROR_BUSLIGHT: MessageBox(0,'PCAN-PCI (Ch-1): Handling a BUS-LIGHT status...','Status',MB_OK); PCAN_ERROR_BUSHEAVY: MessageBox(0,'PCAN-PCI (Ch-1): Handling a BUS-HEAVY status...','Status',MB_OK); PCAN_ERROR_BUSOFF: MessageBox(0,'PCAN-PCI (Ch-1): Handling a BUS-OFF status...','Status',MB_OK); PCAN_ERROR_OK: MessageBox(0,'PCAN-PCI (Ch-1): Status is OK','Status',MB_OK); else begin // An error occurred, get a text describing the error and show it // TPCANBasic.GetErrorText(result, 0, strMsg); MessageBox(0, strMsg, 'Error',MB_OK); end; end;
Python:
...... # Check the status of the PCI Channel # result = objPCAN.GetStatus(PCAN_PCIBUS1) if result == PCAN_ERROR_BUSLIGHT: print "PCAN-PCI (Ch-1): Handling a BUS-LIGHT status..." elif result == PCAN_ERROR_BUSHEAVY: print "PCAN-PCI (Ch-1): Handling a BUS-HEAVY status..." elif result == PCAN_ERROR_BUSOFF: print "PCAN-PCI (Ch-1): Handling a BUS-OFF status..." elif result == PCAN_ERROR_OK: print "PCAN-PCI (Ch-1): Status is OK" else: # An error occurred, get a text describing the error and show it # result = objPCAN.GetErrorText(result) print result[1]
Copyright © 2017. PEAK-System Technik GmbH. All rights reserved.
|
Send feedback to this documentation
|