ApiGetAttachedChannels Method

Retrieves information about the PCAN Channels attached to the system.

Definition

Namespace: Peak.Can.Basic
Assembly: PCANBasic.NET (in PCANBasic.NET.dll) Version: 4.9.0
C#
public static PcanStatus GetAttachedChannels(
	out PcanChannelInformation[] buffer
)

Parameters

buffer  PcanChannelInformation
An array of PcanChannelInformation to return information about the PCAN Channels found.

Return Value

PcanStatus

The return value is a PcanStatus value. OK is returned on success.

Remarks

The method GetAttachedChannels is an aid that internally calls the method GetValue to get the amount of attached PCAN Channels and their description as an array of PcanChannelInformation objects.

The involved PCAN parameters are AttachedChannelsCount and AttachedChannelsInformation.

Example

The following example shows the use of the GetAttachedChannels method to retrieve and show the name, PCAN Channel handle, and features of all current attached PCAN devices.

C#
// A list with all registered channels is retrieved
//
PcanStatus result = Api.GetAttachedChannels(out var channels);
if (result != PcanStatus.OK)
{
    // An error occurred
    //
    Api.GetErrorText(result, out var errorText);
    Console.WriteLine(errorText);
}
else
{
    // The information about the registered hardware is shown
    //
    if (channels.Length == 0)
        Console.WriteLine("There are currently no PCAN devices attached to the system...");
    else
        foreach (PcanChannelInformation channelInfo in channels)
            Console.WriteLine($"{channelInfo.DeviceName} (0x{channelInfo.ChannelHandle:X}): {channelInfo.DeviceFeatures}");
}

Exceptions

DllNotFoundExceptionThe underlying PCANBasic.dll library could not be found.

See Also