CAN_RegisterNet

Professional CAN and CAN FD Development Package for Windows®
Locked
dmedore
Posts: 5
Joined: Wed 9. Jun 2021, 05:27

CAN_RegisterNet

Post by dmedore » Fri 14. Jan 2022, 05:23

I am trying to create Nets via C#. I have PCAN-Developer 4 version 4.1.1

Here is my code; trying various things to create a net that has FD settings (500k/2MB) and a net that is just a nominal 500k

Code: Select all

BitrateFD bitrateFD = new BitrateFD();
                    bitrateFD.ClockFrequency = 80;
                    bitrateFD.NominalPrescaler = 1;
                    bitrateFD.NominalTseg1 = 111;
                    bitrateFD.NominalTseg2 = 48;
                    bitrateFD.NominalSyncJumpWidth = 48;

                    bitrateFD.DataPrescaler = 1;
                    bitrateFD.DataTseg1 = 29;
                    bitrateFD.DataTseg2 = 10;
                    bitrateFD.DataSyncJumpWidth = 10;

                    BitrateFD br2 = new BitrateFD(80, 1, 111, 48, 48, 0, 1, 29, 10, 10, 0);

                    BitrateNominal bitrateNominal = new BitrateNominal();
                    bitrateNominal.ClockFrequency = 20;
                    bitrateNominal.Prescaler = 1;
                    bitrateNominal.Tseg1 = 19;
                    bitrateNominal.Tseg2 = 20;
                    bitrateNominal.SyncJumpWidth = 20;

                    CanApi4.RegisterNet(PcanDevice.Usb, 0, "test1", 16, bitrateNominal);
                    CanApi4.RegisterNet(PcanDevice.Usb, 0, "test2", 16, bitrateFD);

                    CanApi4.RegisterNet(PcanDevice.Usb, 0, "test3", 16, br2);
                    CanApi4.RegisterNet(PcanDevice.Usb, 0, "test4", 16, 500000);
You can see the result here:
result.PNG
result.PNG (19.49 KiB) Viewed 402 times
All of the nets are created, none seem to have the baudrates that I want. And all but 1 (test4) are created on the 'Internal' hardware rather than the PCAN-USB FD as I want.

Any insight into what I am doing incorrectly?

Thanks

M.Heidemann
Sales & Support
Sales & Support
Posts: 786
Joined: Fri 20. Sep 2019, 13:31

Re: CAN_RegisterNet

Post by M.Heidemann » Fri 14. Jan 2022, 08:22

Hello,

What's wrong here at first glance is that you give the clock frequency as Mhz, however
it is expected as Hertz, so instead of

Code: Select all

bitrateFD.ClockFrequency = 80;
use

Code: Select all

bitrateFD.ClockFrequency = 80000000; 

That the nets are created as internal Nets could be due to the fact
that the driver doesnt know what to do with your given bitrates,
please change the given clock frequency accordingly and see if that resolves it.

Best Regards

Marvin

dmedore
Posts: 5
Joined: Wed 9. Jun 2021, 05:27

Re: CAN_RegisterNet

Post by dmedore » Fri 14. Jan 2022, 16:42

Well I certainly feel silly for not trying that...

It indeed resolved the issue.

Thanks!

Locked