Comments on the PCAN-Basic CAN-FD API

The free CAN Software API (Application Programming Interface) for Windows®
Locked
A.Hartmann
Posts: 19
Joined: Tue 8. Oct 2013, 07:19

Comments on the PCAN-Basic CAN-FD API

Post by A.Hartmann » Mon 20. Nov 2017, 07:59

Hi,

I'm currently extending the PeakCAN plugin in QtSerialBus for CAN FD. While working on it, I noticed some places that could be improved in the PCAN-Basic API.
  • The Parameter TPCANBitrateFD in CAN_InitializeFD should be const char* instead char *. Otherwise the compiler complains when I pass a string constant. In pure C, adding the const should be binary compatible.
  • There is no API function to calculate the CAN FD DLC from size and vice-versa. Within software, I usually don't want to handle low level stuff like DLC. But if I need to do so, it would be nice to have a conversion function.
  • It would have been cool to use the new functions (CAN_InitializeFD, CAN_WriteFD, CAN_ReadFD) with old (non-fd-capable) hardware in CAN 2.0 mode. That way I wouldn't have to duplicate my software to support both kinds of hardware.
  • Setting up CAN FD bitrates is very complicated for the user. In fact, that's the last part missing in my implementation. It would be comfortable to just specify the arbitration and data bitrates, like it can be done for SocketCAN with: ip link set can0 up type can bitrate 500000 dbitrate 4000000
Ok, looks like a large list already, so I'm stopping now. I just wanted to mention the points, as I think the API is already very good but could be improved in these aspects. I'm looking forward hearing your opinions on this.

Best regards,
André

User avatar
PEAK-Support
Sales & Support
Sales & Support
Posts: 1646
Joined: Fri 10. Sep 2010, 19:34

Re: Comments on the PCAN-Basic CAN-FD API

Post by PEAK-Support » Mon 20. Nov 2017, 14:22

The QtSerialBus Interface is not officially supported from PEAK-System - so you need to contact the community.
Your comments are your view - but not the view of all developer - most does not use the QT Environment.

1. If your Environment need const char, instead of the used char* - simpl cast it for your need. We need to use it this way- The PCAN-Basic is a cross plattform and cross language API - some languages (in Windows) need it this way. Could be solved within seconds in your code.

2. As you know it is a simple one line code to do this. But this have nothing to do with the API itself. Add it, if you think you need it, to your Lib.

The 4 Bits used for both formats. CAN-FD is compatible with CAN at data lengths ≤ 7, CAN ignores 3 lsb if DLC = 8 but CAN-FD does not. For lengths ≥ 8, CAN-FD uses the following DLCs:

Code: Select all

1000 = 8 
1001 = 12 
1010 = 16
1011 = 20
1100 = 24
1101 = 32
1110 = 48
1111 = 64
Also could be solved with a simply inline code, or a simple array in seconds.
- use Index at DLC Value, store Data Lenght in Value- But this have nothing to do with the CAN API itself.

3. This is not possible, because the used Structure(s) are different in CAN and CAN FD (Message and Timing).
You look from user side fixed in QT. But we develop from Driver side - cross! not only Linux - please keep in mind.

4. CAN-FD is much more complicated in timing, and so it is much more as simpe "use 500K nominal and 2Mbit data). This will end up into many errors and frustration for the users. The User NEED to be sure that they know EXACT the timing - otherwise they run into trouble in the filed. Also here: The PCAN-Basic API is cross plattorm. We support also Windows and the way we build the API is based on these rules.
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

A.Hartmann
Posts: 19
Joined: Tue 8. Oct 2013, 07:19

Re: Comments on the PCAN-Basic CAN-FD API

Post by A.Hartmann » Mon 20. Nov 2017, 15:25

Dear U.Wilhelm,

thanks for your answer.

It was not my point to affront you or your company. In my introduction I wrote that could be improved
and that's how I meant it. And before writing this post, I have carefully thought about the points,
because I know that an improvement must never break existing things.
The QtSerialBus Interface is not officially supported from PEAK-System - so you need to contact the community.
If you read my post again, you will notice that I only spoke about your API. I'm looking at that API from
a users point. In my case, the user is QtSerialBus - I only wrote that as the first introducing sentence so
you know my background.
Your comments are your view - but not the view of all developer - most does not use the QT Environment.
Yes, they are my view, but as already said, I think these are points will affect a lot of your PCAN-Basic users.
And these are simply suggestions to make things even better. Feel free to ignore them from my side,
sooner or later you may hear them from others.
1. If your Environment need const char, instead of the used char* - simpl cast it for your need. We need to use it this way- The PCAN-Basic is a cross plattform and cross language API - some languages (in Windows) need it this way. Could be solved within seconds in your code.
Excuse me, but no. If a function takes a parameter by reference or as pointer, it is allowed to
modify the content. This is simple 40 year old C standard.

Obviously, CAN_InitializeFD will not change the pointer's content. But neiter the compiler, nor static code analysis tools nor a reviewer in critical environments will like to cast away the constness.

As said, both char * and const char * should be binary compabile in pure C. So in minimal, please change the
public include file for C and C++ compilers, so you swear you don't modify the contents of this pointer.
2. As you know it is a simple one line code to do this. But this have nothing to do with the API itself. Add it, if you think you need it, to your Lib.
It is not just one line of code, it is the conversion table you provided. And it has to do with the API, as your read and write functions operate on DLC, not on data length.

But Ok, can be solved in user code. Just that a lot of your users will have to write the same boiler plate code
as I do.
3. This is not possible, because the used Structure(s) are different in CAN and CAN FD (Message and Timing).
I know that the backend is different, but isn't the whole point of an API to abstract things?
Again, your users will have duplicated code when they need to support both CAN 2.0 and CAN FD hardware.
You look from user side fixed in QT. But we develop from Driver side - cross! not only Linux - please keep in mind.
I'm using your API in Windows and in Linux. That works indeed fine, really good work!
4. CAN-FD is much more complicated in timing, and so it is much more as simpe "use 500K nominal and 2Mbit data). This will end up into many errors and frustration for the users. The User NEED to be sure that they know EXACT the timing - otherwise they run into trouble in the filed.
So, please suggest me: how should I start if I want to be able to set the arbitration bitrates {125, 250, 500, 1000} and fro the data bitrate the same value and arbitration bitrate * 8?

Thanks, and best regards,
André

User avatar
PEAK-Support
Sales & Support
Sales & Support
Posts: 1646
Joined: Fri 10. Sep 2010, 19:34

Re: Comments on the PCAN-Basic CAN-FD API

Post by PEAK-Support » Mon 20. Nov 2017, 16:50

i do not want to start a discussion like this here in the forum - sorry
I will now close the thread - and yes - we know the differnt between by value and by reference...we also have read K&R..
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

Locked