I am using a dual channel PCI express device to receive messages from a CAN FD device which transmits messages repeatedly. When I use PCAN-view to initialize the device everything works fine and all messages are received and displayed. But I am developing my own tool for that and ran into some issues. The device initialization passes without errors, but after that no messages are received in my application.
Down below is my device initialization code in C#, I trimmed it a bit so there are only lines regarding device setup. Firstly I developed this app for USB devices and everything works fine for ordinary CAN devices, I still haven't properly tested it with USB CAN FD devices. The part of the code dedicated to receiving messages should be fine since it works properly with USB devices.
Code: Select all
var paramBuff = new IntPtr(PCANBasic.PCAN_PARAMETER_ON);
var arbitrationBitrateDivider = CAN_FD_CLOCK_SPEED / canFdConfig!.ArbitrationBitRate;
var dataBitrateDivider = CAN_FD_CLOCK_SPEED / canFdConfig!.DataBitRate;
var peakCanFdConfigString = new string($"f_clock = {CAN_FD_CLOCK_SPEED}," +
$"nom_brp = {arbitrationBitrateDivider}," +
$"nom_tseg1 = {canFdConfig.TSEG1Arbitration}," +
$"nom_tseg2 = {canFdConfig.TSEG2Arbitration}," +
$"nom_sjw = {canFdConfig.SampleJumpWidthArbitration}," +
$"data_brp = {dataBitrateDivider}," +
$"data_tseg1 = {canFdConfig.TSEG1Data}," +
$"data_tseg2 = {canFdConfig.TSEG2Data}," +
$"data_sjw = {canFdConfig.SampleJumpWidthData}");
var initalizeResult = _canInitializeFD(_selectedChannelHandle, peakCanFdConfigString);
_ = _canSetValue(_selectedChannelHandle, TPCANParameter.PCAN_BUSOFF_AUTORESET, ref paramBuff, sizeof(uint));
_ = _canSetValue(_selectedChannelHandle, TPCANParameter.PCAN_ALLOW_ERROR_FRAMES, ref paramBuff, sizeof(uint));
If you need any other information I am open to provide it.
Best regards,
Andrija Matošić