PCAN-UDS API:WaitForService()doesn't work

A free API for the communication with control devices according to UDS (ISO 14229-1)
Post Reply
Embers
Posts: 12
Joined: Wed 8. Jul 2020, 11:36

PCAN-UDS API:WaitForService()doesn't work

Post by Embers » Wed 8. Jul 2020, 13:02

Hello everyone
I used the PCAN-UDS API:SvcReadDataByIdentifier() to read data from ECU and it send the request message to ECU successful,I can view the response message from ECU in the PCAN-View,this message is correct,But when I used the PCAN-UDS API :WaitForService() to get the response from ECU ,there is an error code(PUDS_ERROR_NO_MESSAGE),it not get the response.Why there is no message when I use this API:WaitForService()?
Any help would be appreciated.

There is my code:

Code: Select all

// Sends a Physical ReadDataByIdentifier Request
            ushort[] buffer = { (ushort)UDSApi.TPUDSSvcParamDI.PUDS_SVC_PARAM_DI_Test };

            result = UDSApi.SvcReadDataByIdentifier(mConnectedChannelHandle, ref request, buffer, (ushort)buffer.Length);------>Send request successful.
             System.Windows.Forms.MessageBox.Show(String.Format("Send Error occured: {0}", (int)result));

            //Get response from ECU
            if (result == TPUDSStatus.PUDS_ERROR_OK)
                result = UDSApi.WaitForService(mConnectedChannelHandle, out response, ref request, out requestConfirmation);------->No message response.        	 
            if (result == TPUDSStatus.PUDS_ERROR_OK)
            {
                System.Windows.Forms.MessageBox.Show(String.Format("Response was received."));
            }
            else
                // An error occurred
                System.Windows.Forms.MessageBox.Show(String.Format("Error occured: {0}", (int)result));

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

Re: PCAN-UDS API:WaitForService()doesn't work

Post by F.Vergnaud » Wed 8. Jul 2020, 14:03

Hello Embers,

Please provide more information regarding the request you are sending (network address information: protocol, source and target address):
depending on those settings, you have to initialize mappings to successfully reveice and transmit segmented messages.
Best regards,
Fabrice

Embers
Posts: 12
Joined: Wed 8. Jul 2020, 11:36

Re: PCAN-UDS API:WaitForService()doesn't work

Post by Embers » Thu 9. Jul 2020, 03:26

Hello Fabrice
I send my request message to ECU successful ,because I can view the request and response(ECU send to my test equipment) in the PCAN-View tool,but now I can't get response message by using the API:WaitForService().


There is my settings:

Code: Select all

 private bool Send_Service()
        {
            int StrSize;
            IntPtr StrPtr;
            TPUDSStatus result;
            TPUDSMsg message;
            bool SendStatus;
            TPUDSMsg request = new TPUDSMsg();
            TPUDSMsg requestConfirmation = new TPUDSMsg();
            TPUDSMsg response = new TPUDSMsg();
            TPUDSMsg confirmation = new TPUDSMsg();
            request.DATA = new byte[4095];

            // initialization
            /*Add mapping for physical request from External_Equipment to ECU_#X : ID=0x727*/
            request.NETADDRINFO.SA = (byte)TPUDSAddress.PUDS_ISO_15765_4_ADDR_TEST_EQUIPMENT;
            request.NETADDRINFO.TA = (byte)TPUDSAddress.PUDS_ISO_15765_4_ADDR_ECU_1;
            request.NETADDRINFO.TA_TYPE = TPUDSAddressingType.PUDS_ADDRESSING_PHYSICAL;
            request.NETADDRINFO.RA = 0x00;
            request.NETADDRINFO.PROTOCOL = TPUDSProtocol.PUDS_PROTOCOL_ISO_15765_2_11B;
            request.LEN = 8;
            // data[0..3] holds CAN ID
            request.DATA[0] = 0x00;
            request.DATA[1] = 0x00;
            request.DATA[2] = 0x07;
            request.DATA[3] = 0x27;
            // data[4..7] holds CAN ID Response
            request.DATA[4] = 0x00;
            request.DATA[5] = 0x00;
            request.DATA[6] = 0x07;
            request.DATA[7] = 0x2F;
            StrSize = Marshal.SizeOf(request);
            StrPtr = Marshal.AllocHGlobal(StrSize);
            Marshal.StructureToPtr(request, StrPtr, false);
            result = UDSApi.SetValue(mConnectedChannelHandle, TPUDSParameter.PUDS_PARAM_MAPPING_ADD, StrPtr, (uint)StrSize);

            // Sends a Physical ReadDataByIdentifier Request
            ushort[] buffer = { (ushort)UDSApi.TPUDSSvcParamDI.PUDS_SVC_PARAM_DI_Test };
            result = UDSApi.SvcReadDataByIdentifier(mConnectedChannelHandle, ref request, buffer, (ushort)buffer.Length);
            System.Windows.Forms.MessageBox.Show(String.Format("Send Error occured: {0}", (int)result)); 
			
	//Get the response from ECU.
	if (result == TPUDSStatus.PUDS_ERROR_OK)
	{
                result = UDSApi.WaitForService(mConnectedChannelHandle, out response, ref request, out requestConfirmation);
		if (result == TPUDSStatus.PUDS_ERROR_OK)
		{
			Response = response;
			System.Windows.Forms.MessageBox.Show(String.Format("Response was received."));
		}
		else
		{
			// An error occurred
			System.Windows.Forms.MessageBox.Show(String.Format("Error occured: {0}", (int)result));
		}
	}
            
           return SendStatus = result == TPUDSStatus.PUDS_ERROR_OK;
   }
Best regards,
Embers

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

Re: PCAN-UDS API:WaitForService()doesn't work

Post by F.Vergnaud » Thu 9. Jul 2020, 09:25

You defined a one way communication as there is only a single mapping from the External Equipment to the ECU.
You need to define another mapping from the ECU to External equipment, which is the other way round:

Code: Select all

            /*Add mapping for physical request from ECU_#X : ID=0x72F to External_Equipment */
            request.NETADDRINFO.SA = (byte)TPUDSAddress.PUDS_ISO_15765_4_ADDR_ECU_1;
            request.NETADDRINFO.TA = (byte)TPUDSAddress.PUDS_ISO_15765_4_ADDR_TEST_EQUIPMENT;
            request.NETADDRINFO.TA_TYPE = TPUDSAddressingType.PUDS_ADDRESSING_PHYSICAL;
            request.NETADDRINFO.RA = 0x00;
            request.NETADDRINFO.PROTOCOL = TPUDSProtocol.PUDS_PROTOCOL_ISO_15765_2_11B;
            request.LEN = 8;
            // data[0..3] holds CAN ID
            request.DATA[0] = 0x00;
            request.DATA[1] = 0x00;
            request.DATA[2] = 0x07;
            request.DATA[3] = 0x2F;
            // data[4..7] holds CAN ID Response
            request.DATA[4] = 0x00;
            request.DATA[5] = 0x00;
            request.DATA[6] = 0x07;
            request.DATA[7] = 0x27;
Best regards,
Fabrice

Embers
Posts: 12
Joined: Wed 8. Jul 2020, 11:36

Re: PCAN-UDS API:WaitForService()doesn't work

Post by Embers » Thu 9. Jul 2020, 09:37

Hello Fabrice
Add another commuction mapping (ECU to test equipment),I have solved my problem. Thank you very much :D



Best regards,
Embers

Post Reply