public static PcanStatus Initialize(
PcanChannel channel,
BitrateXL bitrate
)Public Shared Function Initialize (
channel As PcanChannel,
bitrate As BitrateXL
) As PcanStatuspublic:
static PcanStatus Initialize(
PcanChannel channel,
BitrateXL^ bitrate
)OK is returned on success. The typical errors in case of failure are:
The following example shows the initialization and uninitialization processes using the USB interface (first PCAN-USB hardware).
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;
// The hardware represented by the given handle is initialized with 500 kBit/s nominal bit rate, 2 MBit/s flexible data rate, and 8 MBit/s extended field-data rate
//
PcanStatus result = Api.Initialize(channel, (BitrateXL)"f_clock=160000000, brp=1, nom_tseg1=255, nom_tseg2=64, nom_sjw=64, fd_tseg1=63, fd_tseg2=16, fd_sjw=16, fd_ssp_offset=0, xl_tseg1=10, xl_tseg2=9, xl_sjw=9, xl_ssp_offset=10, xl_error_signaling=1, xl_transceiver_mode_switch=0");
if (result != PcanStatus.OK)
{
// An error occurred
//
Api.GetErrorText(result, out var errorText);
Console.WriteLine(errorText);
}
else
{
// A success message is shown
//
Console.WriteLine($"The hardware represented by the handle {channel} was successfully initialized.");
// 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
' The hardware represented by the given handle is initialized with 500 kBit/s nominal bit rate, 2 MBit/s flexible data rate, and 8 MBit/s extended field-data rate
'
Dim result As PcanStatus = Api.Initialize(channel, CType("f_clock=160000000, brp=1, nom_tseg1=255, nom_tseg2=64, nom_sjw=64, fd_tseg1=63, fd_tseg2=16, fd_sjw=16, fd_ssp_offset=0, xl_tseg1=10, xl_tseg2=9, xl_sjw=9, xl_ssp_offset=10, xl_error_signaling=1, xl_transceiver_mode_switch=0", BitrateXL))
If (result <> PcanStatus.OK) Then
' An error occurred
'
Dim errorText As String = String.Empty
Api.GetErrorText(result, errorText)
Console.WriteLine(errorText)
Else
' A success message is shown
'
Console.WriteLine($"The hardware represented by the handle {channel} was successfully initialized.")
' The connection to the hardware is finalized when it is no longer needed
'
result = Api.Uninitialize(channel)
If (result <> PcanStatus.OK) Then
' An error occurred
'
Dim errorText As String = String.Empty
Api.GetErrorText(result, errorText)
Console.WriteLine(errorText)
Else
Console.WriteLine($"The hardware represented by the handle {channel} was successfully finalized.")
End If
End IfString^ errorText;
PcanChannel channel = PcanChannel::Usb01;
// The hardware represented by the given handle is initialized with 500 kBit/s nominal bit rate, 2 MBit/s flexible data rate, and 8 MBit/s extended field-data rate
//
PcanStatus result = Api::Initialize(channel, (BitrateXL^)"f_clock=160000000, brp=1, nom_tseg1=255, nom_tseg2=64, nom_sjw=64, fd_tseg1=63, fd_tseg2=16, fd_sjw=16, fd_ssp_offset=0, xl_tseg1=10, xl_tseg2=9, xl_sjw=9, xl_ssp_offset=10, xl_error_signaling=1, xl_transceiver_mode_switch=0");
if (result != PcanStatus::OK)
{
// An error occurred
//
Api::GetErrorText(result, errorText);
Console::WriteLine(errorText);
}
else
{
// A success message is shown
//
Console::WriteLine("The hardware represented by the handle {0} was successfully initialized.", channel);
// 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. |