Peak PCANBasic.NET Exception
Posted: Tue 7. May 2024, 00:30
I am attempting to initialize one of two Peak CAN USB FD devices. I am using PCANBasic.NET version 4.9.0.942 in a .NET Framework 4.8 WPF application.
I used PCAN View to change the device ID for one device to 0 and the other to 1. So in this case I'm trying to initialize the USB CAN FD with device ID 0.
Here is the problem code:
The call to GetCriteriaString results in: "devicetype=PcanUsb,deviceid=0"
On the line which calls Api.LookUpChannel, I am getting an exception:
"The type initializer for 'Peak.Can.Basic.Api' threw an exception."
The Peak driver version is 4.4.0.16619, firmware version 3.4.3 (both devices)
Windows 10 Enterprise version 22H2, build 19045.4291
Please let me know what I can look at to troubleshoot the exception. Thank you!
I used PCAN View to change the device ID for one device to 0 and the other to 1. So in this case I'm trying to initialize the USB CAN FD with device ID 0.
Here is the problem code:
Code: Select all
public void InitializeCANFDByDeviceID(uint deviceID)
{
PcanChannel channel = PcanChannel.None;
PcanDevice deviceType = PcanDevice.PcanUsb;
string parameters = ParameterValue.LookUp.GetCriteriaString(deviceType, deviceID, null, null);
PcanStatus result = Api.LookUpChannel(parameters, out channel);
if (result != PcanStatus.OK)
{
Api.GetErrorText(result, out var errorText);
throw new Exception($"Peak PCAN API Error: {errorText}");
}
if (channel == PcanChannel.None)
{
throw new Exception($"Peak PCAN API Error: no channel returned for ID {deviceID}");
}
FDChannel = (ushort)channel;
result = Api.Initialize((PcanChannel)FDChannel, (BitrateFD)BitrateFD.BitrateSaeJ2284_4);
if (result != PcanStatus.OK)
{
Api.GetErrorText(result, out var errorText);
throw new Exception($"Peak PCAN API Initialization Failure: {errorText}{Environment.NewLine}Check that the PCAN is connected.");
}
IsInitialized = result == PcanStatus.OK;
return;
}
On the line which calls Api.LookUpChannel, I am getting an exception:
"The type initializer for 'Peak.Can.Basic.Api' threw an exception."
The Peak driver version is 4.4.0.16619, firmware version 3.4.3 (both devices)
Windows 10 Enterprise version 22H2, build 19045.4291
Please let me know what I can look at to troubleshoot the exception. Thank you!