Uninitialize

PCAN-Basic

PCAN-Basic Documentation
Home
PreviousUpNext
Uninitialize

Uninitializes a PCAN Channel.

Syntax
class function Uninitialize(
    Channel: TPCANHandle
    ): TPCANStatus;
[DllImport("PCANBasic.dll", EntryPoint = "CAN_Uninitialize")]
public static extern TPCANStatus Uninitialize(
    [MarshalAs(UnmanagedType.U1)]
    TPCANHandle Channel);
[DllImport("PCANBasic.dll", EntryPoint = "CAN_Uninitialize")]
static TPCANStatus Uninitialize(
    [MarshalAs(UnmanagedType::U1)]
    TPCANHandle Channel);
<DllImport("PCANBasic.dll", EntryPoint:="CAN_Uninitialize")> _
Public Shared Function Uninitialize( _
    <MarshalAs(UnmanagedType.U1)> _
    ByVal Channel As TPCANHandle) As TPCANStatus
End Function
def Uninitialize(
    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 cannot be uninitialized because it was not found in the list of reserved channels of the calling application. 

A PCAN Channel can be released using one of this possibilities: 

Single-Release: Given a handle of a PCAN Channel initialized before with the method Initialize. If the given channel can not be found then an error is returned. 

Multiple-Release: Giving the handle value PCAN_NONEBUS which instructs the API to search for all channels initialized by the calling application and release them all. This option cause no errors if no hardware were uninitialized. 

Transmit-queue at uninitialize: When a PCAN-Basic channel connection is terminated, the underlying hardware's transmit-queue will not immediately be discarded. PCAN-Basic will wait some time before finalizing, so that the hardware has time to send (or try to send) those unsent messages. When the time is up (amount 500 milliseconds), the rest of the messages in the queue (if any) are discarded. 

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 initialize and uninitialize (Single-Release) processes for the PCAN_PCIBUS1 channel. 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: To see an example of Multiple-Release, see the Initialize method. 

C#:  

TPCANStatus result;
StringBuilder strMsg;

strMsg = new StringBuilder(256);

// The Plug & Play Channel (PCAN-PCI) is initialized
//
result = PCANBasic.Initialize(PCANBasic.PCAN_PCIBUS1, TPCANBaudrate.PCAN_BAUD_500K);
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 initialized");

....

// The PCI Channel is released
//
result = PCANBasic.Uninitialize(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 released");

C++/CLR:

TPCANStatus result;
StringBuilder^ strMsg;

strMsg = gcnew StringBuilder(256);

// The Plug & Play Channel (PCAN-PCI) is initialized
//
result = PCANBasic::Initialize(PCANBasic::PCAN_PCIBUS1, TPCANBaudrate::PCAN_BAUD_500K);
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 initialized");

....

// The PCI Channel is released
//
result = PCANBasic::Uninitialize(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 released");

Visual Basic:

Dim result As TPCANStatus
Dim strMsg As StringBuilder

strMsg = New StringBuilder(256)

' The Plug & Play Channel (PCAN-PCI) is initialized
'
result = PCANBasic.Initialize(PCANBasic.PCAN_PCIBUS1, TPCANBaudrate.PCAN_BAUD_500K)
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 initialized")
End If

....

' The PCI Channel is released
'
result = PCANBasic.Uninitialize(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 released")
End If

Pascal OO:

var
 result : TPCANStatus;
 strMsg: array [0..256] of Char;
begin
    // The Plug & Play Channel (PCAN-PCI) is initialized
    //
    result := TPCANBasic.Initialize(TPCANBasic.PCAN_PCIBUS1, PCAN_BAUD_500K);
    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 initialized','Success', MB_OK);

....

    // The PCI Channel is released
    //
    result := TPCANBasic.Uninitialize(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 released','Success', MB_OK);
end;

Python:

# The Plug & Play Channel (PCAN-PCI) is initialized
#
objPCAN = PCANBasic()
result = objPCAN.Initialize(PCAN_PCIBUS1, PCAN_BAUD_500K)
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 initialized"

....

# The PCI Channel is released
#
result = objPCAN.Uninitialize(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 released"

Initialize 

 

Plain function Version: CAN_Uninitialize

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