Page 1 of 1

First byte is lost when it's 0x11?

Posted: Thu 23. Mar 2023, 17:24
by spoekles
I am trying to read a non ISO-TP frame with CANTP_Read_2016.

When the first byte is 0x11 that byte is lost when reading.

A normal frame could look something like "44 0 0 0 11 0 C0 C3" where the first byte represents a status of the connected device which could be anything from 0x00 to 0x44. But if the first one is 0x11 that is removed and I read "0 0 0 11 0 C0 C3 0" instead of "11 0 0 0 11 0 C0 C3".

Any idea's what could be the reason? Am I wrong to assume that CANTP_Read_2016 can also read plain CAN frames that do not follow any standard?

Re: First byte is lost when it's 0x11?

Posted: Fri 24. Mar 2023, 09:15
by K.Wagner
Hello,

this makes no sense. If the message received is a raw CAN, then it is forwarded as is. Please check your code again.

You can use the "07_classic_can_read_write" example that comes with the PCAN-ISO-TP package if you are not sure how to do it. This example initializes 2 USB channels and sends/receives a single byte CAN message between channels. You can easily modify this to send the 8 bytes of data you are testing with, or you can modify this to only receive and verify that the CAN data sent from another participant is read correctly.

You can modify the part for write like this (line 65):

Code: Select all

    uint can_id = 0xA1;
    byte[] data = { 0x11, 0, 0, 0, 0x11, 0, 0xC0, 0xC3 };
    res = CanTpApi.MsgDataInit_2016(out tx_msg, can_id, cantp_can_msgtype.PCANTP_CAN_MSGTYPE_STANDARD, 8, data);
    Console.WriteLine("Initialize tx message : {0}", STATUS_OK_KO(res));
and the reading part like this (line 84):

Code: Select all

    byte[] dataBuffer = new byte[8];
    if (CanTpApi.getData_2016(ref rx_msg, 0, dataBuffer, 8))
    {
        string dataString = "";
        for (int i = 0; i < 8; i++)
            dataString += $"0x{dataBuffer[i]:X2} ";
        Console.WriteLine($"Message data read: {dataString}");
    }
With this modifications I am able to send and receive the specified 8 data bytes.