Page 1 of 1

ISO TP c# application

Posted: Wed 18. May 2016, 11:06
by nic0311
Hello,
we are developing an app to send and receive messages using TP layer in our end-of-line ECU testing system.

this is our code:

Code: Select all

//MAPPING

	public void ConfigureCAN_ISOTP()
        {
            TPCANTPStatus result;
            // The Plug & Play Channel (PCAN-USB) is initialized
            result = CanTpApi.Initialize(CanTpApi.PCANTP_USBBUS1, TPCANTPBaudrate.PCANTP_BAUD_500K);
            if (result != TPCANTPStatus.PCANTP_ERROR_OK)
                MessageBox.Show("Initialization failed");
            else
            {
                TPCANTPStatus s;
                // Define ISO-TP communication from Client to ECU (physical requests)
                s = CanTpApi.AddMapping(CanTpApi.PCANTP_USBBUS1, 0x400, 0x401,
                                      TPCANTPIdType.PCANTP_ID_CAN_11BIT,
                                      TPCANTPFormatType.PCANTP_FORMAT_NORMAL,
                                      TPCANTPMessageType.PCANTP_MESSAGE_DIAGNOSTIC,
                                      0x8b, 0xf1,
                                      TPCANTPAddressingType.PCANTP_ADDRESSING_PHYSICAL,
                                      0X00);
                MessageBox.Show("PCAN-USB (Ch-1) was initialized");
            }
            // All initialized channels are released
        }
		
		
// MAIN CODE	
		
		
		 ConfigureCAN_ISOTP();

                    TPCANTPStatus result;
                    TPCANTPMsg request = new TPCANTPMsg();
                    
                    TPUDSMsg requestConfirmation = new TPUDSMsg();
                    TPUDSMsg response = new TPUDSMsg();
                    request.DATA = new byte[4095];
                    string CMD_ID = "0130";
                    int CMD_PARAM = 00;
                    byte[] cmdId = HexStringConverter.GetBytes(CMD_ID);
                    UInt32 CMD_ID0 = Convert.ToUInt32(cmdId[0]);
                    UInt32 CMD_ID1 = Convert.ToUInt32(cmdId[1]);
                    request.DATA[0]= HexStringConverter.GetBytes("8B")[0];
                    request.DATA[1] = HexStringConverter.GetBytes("06")[0];
                    request.DATA[2] = Convert.ToByte(CMD_ID0.ToString());
                    request.DATA[3] = Convert.ToByte(CMD_ID1.ToString());
                    request.DATA[4] = Convert.ToByte(CMD_PARAM);
                    request.DATA[5] = Convert.ToByte((0 & 0x01 | 0 << 2 & 0x02 | 0 << 2 & 0x03));
                    request.DATA[6] = 0;
                    request.DATA[7] = 0;
                    //request.DATA[8] = 0;

                    request.LEN = (ushort)request.DATA.Length;
                    request.MSGTYPE = TPCANTPMessageType.PCANTP_MESSAGE_DIAGNOSTIC;
                    request.SA = (byte)0X8b;
                    request.TA = (byte)0Xf1;
                    request.TA_TYPE = TPCANTPAddressingType.PCANTP_ADDRESSING_PHYSICAL;
                    request.RA = 0x00;
                    request.FORMAT = TPCANTPFormatType.PCANTP_FORMAT_NORMAL;
                    request.IDTYPE = TPCANTPIdType.PCANTP_ID_CAN_11BIT;

                    result = CanTpApi.Write(CanTpApi.PCANTP_USBBUS1, ref request);
the message that we send is:

CAN-ID, lenght, Data

400, 8, 1F FF 8B 06 01 30 00 00

we would obtain:

400, 8, 8B 06 01 30 00 00 00 00

Is it possible to achieve this result changing some param ?

Thanks,
N.

Re: ISO TP c# application

Posted: Wed 18. May 2016, 12:09
by PEAK-Support
1. We have moved your post to the seection of ISO-TP
2. We do not exact understand your question - sorry ! could you please explain what exact is your problem using our ISO-TP implementation.
Thanks!

Re: ISO TP c# application

Posted: Wed 18. May 2016, 14:19
by nic0311
Hello Wilhelm,
sorry for my wrong post section :)
I try to explain.
We are developing EOL test system and trying to use peak TP-ISO api to send and receive commands to one of our ECU because we have some embedded SW already written and we would not rewrite it ....

our ECU expect this command:

400, 8, 8B 06 01 30 00 00 00 00

but with the TP implementation (code posted) we have:
400, 8, 1F FF 8B 06 01 30 00 00

is it possible to remove 1F FF from the packet ? for example modifying LEN or some other parameter ?
Thanks,
Nicola.

Re: ISO TP c# application

Posted: Wed 18. May 2016, 14:49
by F.Vergnaud
Hello Nic0311,

In your submitted code, you are specifying a data length of 4095 (0xFFF)

Code: Select all

request.DATA = new byte[4095];
// [...]
request.LEN = (ushort)request.DATA.Length;
But you are trying to send a frame containing only 4 bytes of data... so request.LEN should be 4.

But in any case, with ISO-TP it is not possible to send a segmented frame with the following data "8B 06 01 30 00 00 00 00": the protocol uses one or two bytes of the first data bytes to handle segmentation (among other things you'll see the length of the message, like 0xFFF in your sent message).
What you're trying to send is an unsegmented CAN frame: a classic CAN frame like the ones sent with PCAN-Basic API.

Re: ISO TP c# application

Posted: Wed 18. May 2016, 14:57
by nic0311
Ok,
thank you very much.
Understood.
Next project we will ask to our colleagues to be ISO-TP compliant to use your api.
Bye.