ApiGetValue(PcanChannel, PcanParameter, String) Method

Retrieves a string parameter value from a PCAN Channel.

Definition

Namespace: Peak.Can.Basic
Assembly: PCANBasic.NET (in PCANBasic.NET.dll) Version: 4.9.0
C#
public static PcanStatus GetValue(
	PcanChannel channel,
	PcanParameter parameter,
	out string buffer
)

Parameters

channel  PcanChannel
The handle of a PCAN Channel.
parameter  PcanParameter
The parameter whose value is to be retrieved.
buffer  String

Contains the requested string value.

buffer is only valid, if the returned value of this method is OK.

Return Value

PcanStatus

OK is returned on success. The typical errors in case of failure are:

  • IllegalHandle: Indicates that the channel contains an invalid value.
  • Initialize: Indicates that the channel cannot be used because it was not found in the list of reserved Channels of the calling application.
  • IllegalHardwareHandle: Indicates that the hardware represented by channel is currently not available (detached or disabled).
  • InvalidParameter: Indicates that the requested parameter value is not implemented or is not supported by the given PCAN Channel.

Remarks

Use GetValue(PcanChannel, PcanParameter, String) to get the value of parameters like the ApiVersion, and BitrateFdInformation, among others.

Not all parameters are supported for all PCAN Channels. Using a parameter with a non-compatible Channel ends with an error.

Not all parameters have read access. Using a write-only parameter with GetValue ends with an error.

The value of some parameters can only be retrieved if the channel is initialized. For more information see the PcanParameter section.

Example

The following example shows the use of the GetValue(PcanChannel, PcanParameter, String) method using the USB interface (first PCAN-USB hardware). The name of the hardware represented by a PCAN Channel is requested.

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.

C#
PcanChannel channel = PcanChannel.Usb01;

// The name of the hardware represented by the given handle is retrieved
//
PcanStatus result = Api.GetValue(channel, PcanParameter.HardwareName, out string name);
if (result != PcanStatus.OK)
{
    // An error occurred
    //
    Api.GetErrorText(result, out var errorText);
    Console.WriteLine(errorText);
}
else
{
    // The device ID is shown
    //
    Console.WriteLine($"The name of the hardware represented by the handle {channel} is: {name}.");
}

Exceptions

DllNotFoundExceptionThe underlying PCANBasic.dll library could not be found.
PcanBasicExceptionThe execution of a PCAN-Basic related check operation ended with an unexpected result. Typically, this exception is triggered when a device driver is not installed or is not up to date.

See Also