Get Raw CAN Data out of UDS Response

A free API for the communication with control devices according to UDS (ISO 14229-1)
Locked
KEStarDev
Posts: 6
Joined: Thu 13. Jul 2023, 14:37

Get Raw CAN Data out of UDS Response

Post by KEStarDev » Thu 24. Aug 2023, 08:43

Hi,

Is there a way to get out the raw data from an UDS Response?

I tried sending a Testerpresent
"ID = 0x281; D0=02 D1=3E D2=00 D3=55 D4=55 D5=55 D6=55 D7=55"
and the ECU is responding correct with:
"ID = 0x2C1; D0=02 D1=7E D2=00 D3=00 D4=00 D5=00 D6=00 D7=00"

But in my Software (code is below), the datalength of "resp " is only 2 Byte and the data in the "managedArray1" after Marshal.Copy is:
D0 = 0x7E, all other bytes in the message are 0
I would expect a datalength of 8 byte and getting the full raw payload of the response message of the ECU. Is this possible?

Code: Select all


...

uds_msg request = new uds_msg();
uds_msg response_uds = new uds_msg();
uds_msg request_confirmation = new uds_msg();

// send requ. and wait until service has been entered
UDSApi.SvcTesterPresent_2013(handle, config, out request);

UDSApi.WaitForService_2013(handle, ref request, out response_uds, out request_confirmation);

// Get Message from response_uds structure
cantp_msgdata_can resp = response_uds.msg.Msgdata_can_Copy;

// Copy to byte array
byte[] managedArray1 = new byte[64];
Marshal.Copy(resp.data, managedArray1, 0, (int)resp.length);

...

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

Re: Get Raw CAN Data out of UDS Response

Post by K.Wagner » Thu 24. Aug 2023, 09:06

Hello,

there are two ways to do this:
  1. You configure UDS filters to accept the UUDT messages you want to receive (Unacknowledged Unsegmented Data Transfer, a.k.a. single CAN/CAN_FD frames).
    • check the "UUDT Read/Write Example" within the chapter 4.3.3 of the PCAN-UDS documentation. You can also check the sample projects 03_server_response_ecu_reset_UUDT/04_client_request_ecu_reset_UUDT.
  2. You use the underlying PCAN-ISO-TP API to read the CAN message flow used by PCAN-UDS.
    • check the sample projects 13_server_uds_and_can/14_client_uds_and_can.
Best regards,
Keneth

KEStarDev
Posts: 6
Joined: Thu 13. Jul 2023, 14:37

Re: Get Raw CAN Data out of UDS Response

Post by KEStarDev » Thu 21. Sep 2023, 14:52

Hey,

thanks for the response. I managed to get the sample project running.

Now I have a further question:
I want to read out Data from an ecu with the "Read Data by Identifyer" command.

The ECU is already responsing to my request with the data in a flow controll datastream.
The Peak library is also controlling the Dataflow correctly and answers with the flow controll messages correctly.

But how do I access the received data now?
Does the "response" variable contain the data? If yes, how do I get the data out of the structure?

My code looks like the following:

Code: Select all

            response = new uds_msg();
            request_confirmation = new uds_msg();
            request = new uds_msg();

            UDSApi.uds_svc_param_di[] cfgBuffer = { (UDSApi.uds_svc_param_di)0x0105 };

            result = UDSApi.SvcReadDataByIdentifier_2013(cantp_handle.PCANTP_HANDLE_USBBUS1, config, out
            request, cfgBuffer, 1);

            if (UDSApi.StatusIsOk_2013(result))
            {
                result = UDSApi.WaitForService_2013(cantp_handle.PCANTP_HANDLE_USBBUS1, ref request, out
                response, out request_confirmation);
            }

Thanks and BR,
Florian

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

Re: Get Raw CAN Data out of UDS Response

Post by K.Wagner » Thu 21. Sep 2023, 15:30

Hello,

If you check the help for "WaitForService_2013" you will find the following regarding the parameters:
-
Parameters of WaitForService_2013
Parameters of WaitForService_2013
Response.PNG (25.35 KiB) Viewed 4751 times
and then this in the remarks section:
-
Remarks on WaitForService_2013
Remarks on WaitForService_2013
Remarks.PNG (44.17 KiB) Viewed 4751 times
-
In other words, if the call to SvcReadDataByIdentifier_2013 is OK, and then the call to WaitForService_2013 too, then the response to the service is copied into the out parameter "response".

I hope this is more clear now.
Best regards,
Keneth

KEStarDev
Posts: 6
Joined: Thu 13. Jul 2023, 14:37

Re: Get Raw CAN Data out of UDS Response

Post by KEStarDev » Thu 21. Sep 2023, 17:43

Hi,

thanks, yes that helps a lot.
I just tested it. And indeed, after the whole data has been sent by the ECU, the blocking "WaitForService_2013" responses with a success.

Is there also a code snippet, which shows me how I can get the Data out from the response message in c# language? Unfortunately I cannot find anything in the documentation or in the example codes.
I would prefer to have a byte buffer which contains all the received payload data from the transfer without the overhead from UDS and ISO-TP.
Is this possible?

When I have a look into "response.msg.reserved.size", it says, that the messagesize is 0x55 which is way too less for the whole ReadDataByIdentifyer transfer.
Sorry, if it is a dumb question, but I really do not have any idea how I get the payload of the transfer.
Even if I would copy it from "response.msg.msgdata" I do not know the size of the memory behind the pointer.

Thanks and BR,
Florian

KEStarDev
Posts: 6
Joined: Thu 13. Jul 2023, 14:37

Re: Get Raw CAN Data out of UDS Response

Post by KEStarDev » Fri 22. Sep 2023, 08:39

Hello,

I managed to get it running.

This is the working code Snippet, which receives the ECU-Data and stores it into "receiveBuffer":

Code: Select all



            uds_msg response = new uds_msg();
            uds_msg request_confirmation = new uds_msg();
            uds_msg request = new uds_msg();
            uds_status result = uds_status.PUDS_STATUS_OK;


            UDSApi.uds_svc_param_di[] cfgBuffer = { (UDSApi.uds_svc_param_di)0x0105 };

            result = UDSApi.SvcReadDataByIdentifier_2013(cantp_handle.PCANTP_HANDLE_USBBUS1, config, out
            request, cfgBuffer, 1);

            if (UDSApi.StatusIsOk_2013(result))
            {
                result = UDSApi.WaitForService_2013(cantp_handle.PCANTP_HANDLE_USBBUS1, ref request, out
                response, out request_confirmation);
            }

            if (UDSApi.StatusIsOk_2013(result))
            {
                Console.WriteLine("Response was received", "Success");

                byte[] receiveBuffer = new byte[2048];

                if (response.msg.Msgdata != IntPtr.Zero)
                {
                    cantp_msgdata data = response.msg.Msgdata_any_Copy;

                    for (int i = 0; i < data.length; i++)
                    {
                        receiveBuffer[i] = Marshal.ReadByte(data.data, i);
                    }
                }
            }
            
          
Thanks a lot for your help and BR

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

Re: Get Raw CAN Data out of UDS Response

Post by K.Wagner » Fri 22. Sep 2023, 09:38

Hello,

thanks for the feedback. Glad to see that you solved your problem. Closed.
Best regards,
Keneth

Locked