Use CAN_Read function in UDS API

A free API for the communication with control devices according to UDS (ISO 14229-1)
Post Reply
NielsBrouwer
Posts: 2
Joined: Sat 1. Apr 2017, 11:30

Use CAN_Read function in UDS API

Post by NielsBrouwer » Sat 1. Apr 2017, 11:50

Hello,

My name is Niels Brouwer and I'm a final years Student Embedded Software at the HAN Arnhem NL. Currently I'm working on my graduation assigment which is basicly a diagnostic program for automotive applications.

I want to use the PCAN basic functions and the PCAN UDS functions both in the same program. I noticed today that when I initialize the PCAN-USB dongle with the CAN_Initialize() the CAN_Read function works fine, but when I initialize the PCAN-USB dongle with the UDS_initialize() the CAN_Read function always returns the QRCEMPTY status.

Now I would like to know if it is even possible and allowed to use the PCAN-basic functions when the PCAN-USB dongle is initialized with UDS_Initialize and if so, which settings do I have to use?

Many thanks in advance,

Niels Brouwer

K.Wagner
Software Development
Software Development
Posts: 1080
Joined: Wed 22. Sep 2010, 13:36

Re: Use CAN_Read function in UDS API

Post by K.Wagner » Mon 3. Apr 2017, 08:39

Hello Niels,

Please note that our high layer protocol APIs (ISO-TP, UDS, OBDII, PassThru) are based on PCAN-Basic, i.e. PCAN-Basic is used for the CAN communication.
NielsBrouwer wrote:I noticed today that when I initialize the PCAN-USB dongle with the CAN_Initialize() the CAN_Read function works fine, but when I initialize the PCAN-USB dongle with the UDS_initialize() the CAN_Read function always returns the QRCEMPTY status.
When you initialize a PCAN-UDS with a channel, this actually does a background PCAN-Basic channel initialization. Since CAN channels have only one receive queue, you will not able to read messages for that channel simultanoeusly from different APIs (CAN and UDS protocols). The first API that call CAN_Read will get the message.
NielsBrouwer wrote:Now I would like to know if it is even possible and allowed to use the PCAN-basic functions when the PCAN-USB dongle is initialized with UDS_Initialize and if so, which settings do I have to use?
Even when it is not prohibed, it is wrong to do that. You will have a race condition between APIs when reading the receive queue of the channel. Since the UDS protocol use fragmentation as well as confirmation messaging, you would destroy the UDS communication if reading from PCAN-Basic, since those messages will not be available for UDS.

To sum up:
  • PCAN-UDS uses internally PCAN-Basic
  • PCAN-UDS internally read the initialized PCAN-Basic channel periodically
  • Channels used in PCAN-Basic have only one receive queue
  • Calling CAN_Read from PCAN-Basic with an channel initialized in PCAN-UDS results in a race condition for reading messages between APIs
  • If some packages are missed within UDS, then the whole UDS communication fails
  • If it is needed to use CAN and UDS simultaneously, then two PCAN devices (2 channels) should be used, e.g. 2 PCAN-USB classic, or 1 PCAN-USB Pro FD --> one channel for each protocol.
Best regards,
Keneth

NielsBrouwer
Posts: 2
Joined: Sat 1. Apr 2017, 11:30

Re: Use CAN_Read function in UDS API

Post by NielsBrouwer » Mon 3. Apr 2017, 19:47

Dear Keneth,

Thank you for this fast and clear answer!

Best regards,

Niels Brouwer

Post Reply