how to change the TPUDSparameter

A free API for the communication with control devices according to UDS (ISO 14229-1)
Post Reply
H.Tina
Posts: 15
Joined: Tue 8. Jan 2019, 03:14

how to change the TPUDSparameter

Post by H.Tina » Wed 27. Feb 2019, 04:14

Dear sir
I have a question to hope getting your help.First questio: as we all know ,in generally ,we send 10 01/02/03 to set diagnosticSessionControl.but now I want to send 10 81/82/83 to set diagnosticsession.how to change it ?
before I change the defines PUDS_SV_PARAM_DSC_DS =0x01 to PUDS_SV_PARAM_DSC_DS =0x81,it is right?
Seconed question: After I change the defines above,when I set 27 21/22,the key changes 27 A2 and the time between 27/21 and 27/22 is very long ,more than 5s.how to change it ?
best wishes

F.Vergnaud
Software Development
Software Development
Posts: 305
Joined: Mon 9. Sep 2013, 12:21

Re: how to change the TPUDSparameter

Post by F.Vergnaud » Wed 27. Feb 2019, 11:28

Hello H.Tina,

You should not change the definitions in the PCAN-UDS headers! The library is compiled with those definitions, changing them will not change the internal behaviour of the library.

If you want to set a specific diagnostic session simply set the correct parameter 'sessionType' when you call the function: UDS_SvcDiagnosticSessionControl(channel, msgReq, sessionType).

As for your second question, the 5s timeout may be due to the fact that the first "Session change" request was not successfull: since you're not in the right session the security access service may not be available and fail.
Best regards,
Fabrice

H.Tina
Posts: 15
Joined: Tue 8. Jan 2019, 03:14

Re: how to change the TPUDSparameter

Post by H.Tina » Thu 28. Feb 2019, 01:57

Dear sir
you said can not change PCAN-UDS headers.Then how to set the correct parameter 'sessionType' when I used svcDiagnosticSessionControl(m_channel,msReq,sessiontype)?because PCAN-UDS headers didn't include 81/82/83 defines,how can use it ?can you give me an example ?
if I didn't change the PUDS_SV_PARAM_DSC_DS=0x01 to PUDS_SV_PARAM_DSC_DS=0x81,I set it as result = UDSApi.SvcDiagnosticSessionControl(m_PcanHandle, ref UDSMsg, 0x83);there is wrong in this function.the mistake is this can not matched with method
can you help me solve this problem?Thank you very much
best wishes

F.Vergnaud
Software Development
Software Development
Posts: 305
Joined: Mon 9. Sep 2013, 12:21

Re: how to change the TPUDSparameter

Post by F.Vergnaud » Thu 28. Feb 2019, 09:32

You simply have to cast your sessionType's value to the TPUDSSvcParamDSC enumeration like so:
UDSApi.SvcDiagnosticSessionControl(m_PcanHandle, ref UDSMsg, (UDSApi.TPUDSSvcParamDSC)0x83);
Best regards,
Fabrice

H.Tina
Posts: 15
Joined: Tue 8. Jan 2019, 03:14

Re: how to change the TPUDSparameter

Post by H.Tina » Thu 28. Feb 2019, 09:42

Dear sir
if I change like this,then the time between 27 03 and 27 04 can be effected?
and if I want to change 27 03 and 27 04 to 27 21 and 27 22,Can I use the same method?or change PUDS_SVC_PARAM_SA_RSD_3 = 0x03 to PUDS_SVC_PARAM_SA_RSD_3 = 0x21?
thank you very much
best wishes

F.Vergnaud
Software Development
Software Development
Posts: 305
Joined: Mon 9. Sep 2013, 12:21

Re: how to change the TPUDSparameter

Post by F.Vergnaud » Thu 28. Feb 2019, 10:04

Hello H.Tina,

You, first, need to check that your SvcDiagnosticSessionControl request is answered successfully. If your ECU did not change the session, then it may not respond to your next security request (although in general it should answer with a standardized negative response code: you need to check its specifications).

Otherwise, you can safely call SvcSecurityAccess using a cast or a local variable:

Code: Select all

  // request seed
  byte subFuncSeedRequest = 0x21;
  sts = UDSApi.SvcSecurityAccess(Handle, ref msgReq, subFuncSeedRequest, new byte[0], 0);
Best regards,
Fabrice

H.Tina
Posts: 15
Joined: Tue 8. Jan 2019, 03:14

Re: how to change the TPUDSparameter

Post by H.Tina » Thu 28. Feb 2019, 10:37

dear sir
I do it like this

Code: Select all

 status = UDSApi.SvcSecurityAccess(m_PcanHandle, ref request, 0x21, buffer, (ushort)buffer.Length);
            if (status == TPUDSStatus.PUDS_ERROR_OK)
            {
                status = UDSApi.WaitForService(m_PcanHandle, out response, ref request, out request);
                if (status == TPUDSStatus.PUDS_ERROR_OK)
                {
                       //calculate key
                        res = OK;
                }
                else
                {
                    res = ERROR;
                }
            }
            if (OK == res)
            {
                status = UDSApi.SvcSecurityAccess(m_PcanHandle, ref request, 0x22, buffer1, (ushort)buffer1.Length);
why the result is like this
02 27 21 00 00 00 00 00
06 67 21 12 13 12 12 00
06 27 A2 23 32 43 27 00
why 22 become A2?
best wishes
Last edited by M.Gerber on Thu 28. Feb 2019, 10:56, edited 1 time in total.
Reason: Inserted code tag for improved readability.

F.Vergnaud
Software Development
Software Development
Posts: 305
Joined: Mon 9. Sep 2013, 12:21

Re: how to change the TPUDSparameter

Post by F.Vergnaud » Thu 28. Feb 2019, 11:56

Keep in mind that only checking the result of the WaitForService function is not enough ; you need to check that:
  • - the received response is positive (meaning that a message was replied, but it can contain error, see TPUDSMsg.IsPositiveResponse method)
    - and is not a negative answer (message is holding a NRC code, see TPUDSMsg.IsNegativeResponse).
In your case it doesn't seems to be the case (assuming that "06 67 21 12 13 12 12 00" is the ECU's answer). In the future, please provide the complete trace of your CAN bus communication (including CAN IDs) in order to better understand your log.

Anyway, as far as I can tell it seems that you have set the request's member "NO_POSITIVE_RESPONSE_MSG" to "PUDS_SUPPR_POS_RSP_MSG_INDICATION_BIT" flag: it adds the value 0x80 to the first parameter of the request (0xA2 = 0x80 + 0x22).
Since you re-use the same object for your calls to SvcSecurityAccess, please make sure that the member NO_POSITIVE_RESPONSE_MSG of your object "request" is set to 0.
Best regards,
Fabrice

H.Tina
Posts: 15
Joined: Tue 8. Jan 2019, 03:14

Re: how to change the TPUDSparameter

Post by H.Tina » Fri 1. Mar 2019, 02:44

Dear sir
I want to know how to set the NO_POSITIVE_RESPONSE_MSG =0.I do like this :

Code: Select all

 status = UDSApi.SvcSecurityAccess(m_PcanHandle, ref request, 0x21, buffer, (ushort)buffer.Length);
            if (status == TPUDSStatus.PUDS_ERROR_OK)
            {
                status = UDSApi.WaitForService(m_PcanHandle, out response, ref request, out request);
                if (status == TPUDSStatus.PUDS_ERROR_OK)
                {
                   //postivite response
                    if (response.DATA[0] == 0x67 && response.DATA[1] == 0x21)
                    {
                        res = OK;
                    }
                }
                else
                {
                    res = ERROR;
                }
            }
            if (OK == res)
            {
                status = UDSApi.SvcSecurityAccess(m_PcanHandle, ref request, 0x22, buffer1, (ushort)buffer1.Length);
                if (status == TPUDSStatus.PUDS_ERROR_OK)
                {
                    status = UDSApi.WaitForService(m_PcanHandle, out response, ref request, out request);
                    if (status == TPUDSStatus.PUDS_ERROR_OK)
                    {
                        if (response.DATA[0] == 0x67)
                        {
                            res = OK;
                        }
                        else
                        {
                            res = ERROR;
                        }
                    }
                }
            }
the result is the same as the last topic,the second is still 27 A2.can you tell me how to change it ?
in my mind ,I have a method to solve it ,but I don't know is it right?After send 27 21 and receive positive response ,then I set "request =new request" again like this

Code: Select all

 status = UDSApi.SvcSecurityAccess(m_PcanHandle, ref request, 0x21, buffer, (ushort)buffer.Length);
            if (status == TPUDSStatus.PUDS_ERROR_OK)
            {
                status = UDSApi.WaitForService(m_PcanHandle, out response, ref request, out request);
                if (status == TPUDSStatus.PUDS_ERROR_OK)
                {
                    if (response.DATA[0] == 0x67 && response.DATA[1] == 0x21)
                    {
                        res = OK;
                    }
                }
                else
                {
                    res = ERROR;
                }
            }
            if (OK == res)
            {
                request = new TPUDSMsg();
                request.NETADDRINFO.SA = (byte)TPUDSAddress.PUDS_ISO_15765_4_ADDR_TEST_EQUIPMENT;
                request.NETADDRINFO.TA = (byte)TPUDSAddress.PUDS_ISO_15765_4_ADDR_ECU_8;
                request.NETADDRINFO.TA_TYPE = TPUDSAddressingType.PUDS_ADDRESSING_PHYSICAL;
                request.NETADDRINFO.RA = 0x00;
                request.NETADDRINFO.PROTOCOL = TPUDSProtocol.PUDS_PROTOCOL_ISO_15765_2_11B;
                status = UDSApi.SvcSecurityAccess(m_PcanHandle, ref request, 0x22, buffer1, (ushort)buffer1.Length);
                if (status == TPUDSStatus.PUDS_ERROR_OK)
                {
                    status = UDSApi.WaitForService(m_PcanHandle, out response, ref request, out request);
               }
is this method right?if it is wrong ,please tell the right method to solve this problem.

I have find that if I send 10 01/02/03 didn't 10 81/82/83,even if I re-use the same request and don't new it again,it has no this problem.it still send 27 22
Last edited by F.Vergnaud on Fri 1. Mar 2019, 09:19, edited 1 time in total.
Reason: Inserted code tag for improved readability.

F.Vergnaud
Software Development
Software Development
Posts: 305
Joined: Mon 9. Sep 2013, 12:21

Re: how to change the TPUDSparameter

Post by F.Vergnaud » Fri 1. Mar 2019, 09:28

Simply use the following:

Code: Select all

request.NO_POSITIVE_RESPONSE_MSG = 0;
Otherwise your alternative solution is also ok.
The function UDSApi.WaitForService(m_PcanHandle, out response, ref request, out request); uses the 'out' keyword for the last parameter, this explains why the object 'request' can be modified.
Best regards,
Fabrice

Post Reply