PCI express not receiving messages

PCI Express to CAN Interface
Post Reply
aMatosic
Posts: 5
Joined: Tue 6. Jun 2023, 09:57

PCI express not receiving messages

Post by aMatosic » Wed 15. Nov 2023, 09:39

Hi,

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));

I am using PCANBasic64.dll version 4.4.0.288, are there any extra steps when initializing PCI devices compared to USB ones?

If you need any other information I am open to provide it.

Best regards,

Andrija Matošić

G.Lang
Support
Support
Posts: 169
Joined: Wed 22. Sep 2010, 14:58

Re: PCI express not receiving messages

Post by G.Lang » Wed 15. Nov 2023, 13:00

Hi,

as a first step it´s recommend to use the latest PCANBasic API (version 4.8.x), please download it from the following URL: https://www.peak-system.com/fileadmin/m ... -basic.zip

If this don´t solve your problem then check if the C# examples inside the PCANBasic\Samples directory will properly work.

If they work properly then there must be something wrong inside your code. If the examples also don´t properly work then contact us via emal (use the "info@peak-system" address) and referr to this post.

regards
Gunther

Post Reply