public static PcanStatus SetValue(
PcanChannel channel,
PcanParameter parameter,
uint buffer
)
Public Shared Function SetValue (
channel As PcanChannel,
parameter As PcanParameter,
buffer As UInteger
) As PcanStatus
public:
static PcanStatus SetValue(
PcanChannel channel,
PcanParameter parameter,
unsigned int buffer
)
OK is returned on success. The typical errors in case of failure are:
Use SetValue(PcanChannel, PcanParameter, UInt32) to set the value of parameters like the DeviceId, and ReceiveStatus, 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 write access. Using a read-only parameter with SetValue ends with an error.
Except for a few parameters, the channel has to be initialized first, before being able to configure a value on it. For more information see the PcanParameter section.
The following example shows the use of the SetValue(PcanChannel, PcanParameter, UInt32) method using the USB interface (first PCAN-USB hardware). The device ID of the channel is configured to be 7.
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.
PcanChannel channel = PcanChannel.Usb01;
ulong acceptanceFilter = 0x00001000_00000500;
// The hardware represented by the given handle is initialized with 500 kBit/s bit rate (BTR0/BTR1 0x001C)
//
PcanStatus result = Api.Initialize(channel, Bitrate.Pcan500);
if (result != PcanStatus.OK)
{
// An error occurred
//
Api.GetErrorText(result, out var errorText);
Console.WriteLine(errorText);
}
else
{
// A success message on connection is shown.
//
Console.WriteLine($"The hardware represented by the handle {channel} was successfully initialized.");
// Configure the acceptance filter of the device to allow receiving the messages with IDs 1100h, 1400h, and 1500h
//
result = Api.SetValue(channel, PcanParameter.AcceptanceFilter29Bit, acceptanceFilter);
if (result != PcanStatus.OK)
{
// An error occurred
//
Api.GetErrorText(result, out var errorText);
Console.WriteLine(errorText);
}
else
{
Console.WriteLine($"The 29-bit acceptance filter of the hardware represented by the handle {channel} was successfully set to {acceptanceFilter:X16}h.");
}
// The connection to the hardware is finalized when it is no longer needed
//
result = Api.Uninitialize(channel);
if (result != PcanStatus.OK)
{
// An error occurred
//
Api.GetErrorText(result, out var errorText);
Console.WriteLine(errorText);
}
else
Console.WriteLine($"The hardware represented by the handle {channel} was successfully finalized.");
}
Dim channel As PcanChannel = PcanChannel.Usb01
Dim acceptanceFilter As ULong = &H00001000_00000500
' The hardware represented by the given handle is initialized with 500 kBit/s bit rate (BTR0/BTR1 0x001C)
'
Dim result As PcanStatus = Api.Initialize(channel, Bitrate.Pcan500)
' An error occurred
'
Dim errorText = Nothing
If result <> PcanStatus.OK Then
Api.GetErrorText(result, errorText)
Console.WriteLine(errorText)
Else
' A success message on connection is shown.
'
Console.WriteLine($"The hardware represented by the handle {channel} was successfully initialized.")
' Configure the acceptance filter of the device to allow receiving the messages with IDs 1100h, 1400h, and 1500h
'
result = Api.SetValue(channel, PcanParameter.AcceptanceFilter29Bit, acceptanceFilter)
If result <> PcanStatus.OK Then
Api.GetErrorText(result, errorText)
Console.WriteLine(errorText)
Else
Console.WriteLine($"The 29-bit acceptance filter of the hardware represented by the handle {channel} was successfully set to {acceptanceFilter:X16}h.")
End If
' The connection to the hardware is finalized when it is no longer needed
'
result = Api.Uninitialize(channel)
If result <> PcanStatus.OK Then
Api.GetErrorText(result, errorText)
Console.WriteLine(errorText)
Else
Console.WriteLine($"The hardware represented by the handle {channel} was successfully finalized.")
End If
End If
PcanChannel channel = PcanChannel::Usb01;
String^ errorText;
UInt64 acceptanceFilter = 0x00001000'00000500;
// The hardware represented by the given handle is initialized with 500 kBit/s bit rate (BTR0/BTR1 0x001C)
//
PcanStatus result = Api::Initialize(channel, Bitrate::Pcan500);
if (result != PcanStatus::OK)
{
// An error occurred
//
Api::GetErrorText(result, errorText);
Console::WriteLine(errorText);
}
else
{
// A success message on connection is shown.
//
Console::WriteLine("The hardware represented by the handle {0} was successfully initialized.", channel);
// Configure the acceptance filter of the device to allow receiving the messages with IDs 1100h, 1400h, and 1500h
//
result = Api::SetValue(channel, PcanParameter::AcceptanceFilter29Bit, acceptanceFilter);
if (result != PcanStatus::OK)
{
// An error occurred
//
Api::GetErrorText(result, errorText);
Console::WriteLine(errorText);
}
else
{
Console::WriteLine("The 29-bit acceptance filter of the hardware represented by the handle {0} was successfully set to {1:X16}h.", channel, acceptanceFilter);
}
// The connection to the hardware is finalized when it is no longer needed
//
result = Api::Uninitialize(channel);
if (result != PcanStatus::OK)
{
// An error occurred
//
Api::GetErrorText(result, errorText);
Console::WriteLine(errorText);
}
else
Console::WriteLine("The hardware represented by the handle {0} was successfully finalized.", channel);
}
DllNotFoundException | The underlying PCANBasic.dll library could not be found. |
PcanBasicException | The 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. |