Reset

PCAN-Basic

PCAN-Basic Documentation
Home
PreviousUpNext
Reset

Resets the receive and transmit queues of a PCAN Channel.

Syntax
class function Reset(
    Channel: TPCANHandle
    ): TPCANStatus;
[DllImport("PCANBasic.dll", EntryPoint = "CAN_Reset")]
public static extern TPCANStatus Reset(
    [MarshalAs(UnmanagedType.U1)]
    TPCANHandle Channel);
[DllImport("PCANBasic.dll", EntryPoint = "CAN_Reset")]
static TPCANStatus Reset(
    [MarshalAs(UnmanagedType::U1)]
    TPCANHandle Channel);
<DllImport("PCANBasic.dll", EntryPoint:="CAN_Reset")> _
Public Shared Function Reset( _
    <MarshalAs(UnmanagedType.U1)> _
    ByVal Channel As TPCANHandle) As TPCANStatus
End Function
def Reset(
    self,
    Channel)
Parameters 
Description 
Channel 
The handle of a PCAN Channel (see TPCANHandle). 

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

Calling this method ONLY clear the queues of a Channel. A reset of the CAN controller doesn't take place. 

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-Basic parameter 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 initialize again the channel used. This causes a hardware reset, but only when no more clients are connected to that channel. 

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 Reset 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);

......

// 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);
    MessageBox.Show(strMsg.ToString());
}
else
    MessageBox.Show("PCAN-PCI (Ch-1) was reset");

C++/CLR:

TPCANStatus result;
StringBuilder^ strMsg;

strMsg = gcnew StringBuilder(256);

......

// 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);
    MessageBox::Show(strMsg->ToString());
}
else
    MessageBox::Show("PCAN-PCI (Ch-1) was reset");

Visual Basic:

Dim result As TPCANStatus
Dim strMsg As StringBuilder

strMsg = New StringBuilder(256)

......

' 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)
    MessageBox.Show(strMsg.ToString)
Else
    MessageBox.Show("PCAN-PCI (Ch-1) was reset")
End If

Pascal OO:

var
 result : TPCANStatus;
 strMsg: array [0..256] of Char;
begin

......

    // The PCI Channel is reset
    //
    result := TPCANBasic.Reset(TPCANBasic.PCAN_PCIBUS1);
    If (result <> PCAN_ERROR_OK) Then
    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
    else
        MessageBox(0,'PCAN-PCI (Ch-1) was reset','Success', MB_OK);

Python:

......

# The PCI Channel is released
#
result = objPCAN.Reset(PCAN_PCIBUS1)
if result != PCAN_ERROR_OK:
    # An error occurred, get a text describing the error and show it
    #
    result = objPCAN.GetErrorText(result)
    print result[1]
else:
    print "PCAN-PCI (Ch-1) was reset"

Read 

Write 

SetValue 

 

Plain function Version: CAN_Reset

Copyright © 2017. PEAK-System Technik GmbH. All rights reserved.
Send feedback to this documentation