PCANBasicUninitialize Method

Uninitializes one or all initialized PCAN Channels.

Definition

Namespace: Peak.Can.Basic.BackwardCompatibility
Assembly: PCANBasic.NET (in PCANBasic.NET.dll) Version: 4.9.0
C#
public static TPCANStatus Uninitialize(
	ushort Channel
)

Parameters

Channel  UInt16
The handle of a PCAN Channel (see PCAN Handle Definitions).

Return Value

TPCANStatus

The return value is a TPCANStatus value. 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.
  • PCAN_ERROR_ILLHANDLE: Indicates that the given PCAN Channel is not valid.

Remarks

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

  • Single-Release: Giving the handle of a PCAN Channel initialized before with the Initialize method. If the given channel cannot be found an error is returned.
  • Multiple-Release: Giving the handle value PCAN_NONEBUS. It instructs the API to uninitialize all channels being used by the calling application. This option does not generate errors if no channel was uninitialized.

Transmit queue on uninitialize: When a connection is terminated, the underlying hardware's transmit-queue will not be immediately discarded. The API will wait some time before terminating, so that the hardware has time to send (or try to send) the unsent messages. When the timer runs out (about 500 milliseconds), the rest of the messages in the queue (if any) are discarded.

Example

The following example shows the initialization and uninitialization (Single-Release) processes for 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

To see an example of Multiple-Release, see the Initialize method.

C#
TPCANStatus result;
System.Text.StringBuilder strMsg;

strMsg = new System.Text.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);
    Console.WriteLine(strMsg.ToString());
}
else
    Console.WriteLine("PCAN-PCI (Ch-1) was initialized");

// .... do communication ...

// 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);
    Console.WriteLine(strMsg.ToString());
}
else
    Console.WriteLine("PCAN-PCI (Ch-1) was released");

See Also