Page 1 of 1

WaitForService doesn't end

Posted: Fri 30. Sep 2016, 09:51
by Daniel.
Hello,

I use Visual Basic in Visual Studio 2013.I have a problem with the function WaitForService, which I use behind the function SvcInputOutputControlByIdentifier to receive the answer of my DUT, similar the example in the PCAN-UDS API - User Guide. If I start my programm, the first hours it's work fine. But after some hours and any Messages, the function WaitForService doesn't exit. The debugger shows me, that my program is in this function. The timeouts are set to 10000 (10s). After any minutes the programm is still at the same position. Another thread with Messages (CAN and UDS) work fine. The thread send and receive messages, so that I don't think that the problem is in the interface or the DUT. I tested my program several times and always after any hours and any runs of this function, the WaitForService function doen't ends.

Where is the problem or what I have to do, so that the function ends and return an answer? Thank you for your help!

Best regars,
Daniel

Re: WaitForService doesn't end

Posted: Mon 3. Oct 2016, 14:33
by F.Vergnaud
Hello,

It seems that the WaitForService function is waiting infinitely either for the request confirmation or the ECU's response and that message is never received..

Can you tell us the values of the following parameters when the function WaitForService doesn't end (for instance in your other working thread):
- The timeout request for the channel,
- The timeout response for the channel,
- The current UDS session,
- The flag "SuppressPositiveResponse" of your request that makes the WaitForService waits infinitely.

Here is an example in C++ to retrieve those parameters:

Code: Select all

// Define the following variables according to your application's specification
// TPUDSCANHandle CanChannel;
// TPUDSMsg* MessageRequest;   // a request similar to the one that was used with the function WaitForService 

// retrieve user-defined timeout
DWORD timeoutRequest = 0;
DWORD timeoutResponse = 0;
TPUDSSessionInfo sessionInfo = {};

// Get request timeout (maximum time to wait for the confirmation of the request)
UDS_GetValue(CanChannel, PUDS_PARAM_TIMEOUT_REQUEST, &timeoutRequest, sizeof(timeoutRequest));
// Get response timeout (maximum time to wait for a response after a request was confirmed)
UDS_GetValue(CanChannel, PUDS_PARAM_TIMEOUT_RESPONSE, &timeoutResponse, sizeof(timeoutResponse));

// Get server session information (member TIMEOUT_P2CAN_SERVER_MAX stores the maximum time allowed to the ECU to process the request) (note: it requires the Network Address Information used when sending a request to the ECU)
sessionInfo.NETADDRINFO = MessageRequest->NETADDRINFO;
UDS_GetValue(CanChannel, PUDS_PARAM_SESSION_INFO, &sessionInfo, sizeof(sessionInfo));

Re: WaitForService doesn't end

Posted: Tue 4. Oct 2016, 11:21
by Daniel.
Hello Fabrice,

Yes, of course. I logged the Informations like your example and the example in the documentation of the Api:
PUDS_PARAM_TIMEOUT_REQUEST = 16
PUDS_PARAM_TIMEOUT_RESPONSE = 16
SESSION_TYPE = 3
TIMEOUT_P2CAN_SERVER_MAX = 50

Sorry, I have to correct my first post, I thought the timeout was set on 10, but it was in hex code, my mistake!

I hope that are the informations, do you need. I'm not sure, what you mean with the flag "SuppressPositiveResponse" and how I have to read this flag.

If you need more informations, please ask me for it. I'll try to supply this informations. It's very important for me, to find the bug as fast as possible.

Thank you for your help!

Best regard
Daniel

Re: WaitForService doesn't end

Posted: Tue 4. Oct 2016, 12:38
by F.Vergnaud
Hello Daniel,

Sorry about the "SuppressPositiveResponse" flag, I meant the value of the member NO_POSITIVE_RESPONSE_MSG in your TPUDSMsg request. In any case your timeouts should not lead to an infinite waiting loop:
- setting the timeout request to 0ms will make the WaitForService function wait until the confirmation is received,
- setting the timeout response and the session TIMEOUT_P2CAN_SERVER_MAX to 0ms will make the WaitForService function wait until a response is received,
- setting the session TIMEOUT_P2CAN_SERVER_MAX to 0ms and making a request with the flag NO_POSITIVE_RESPONSE_MSG to 1 (stating you do not requre a positive response from the ECU) will make the WaitForService function wait until a response is received.

A final way to be in an infinite waiting state would be the following very specific case:
- the function WaitForService reads an "indication" response (response with a MSGTYPE set to PUDS_MESSAGE_TYPE_INDICATION), this means that the message is pending. It is a fragmented message and it can take some time to be fully transmitted.
- if you have another thread that reads received UDS message, it is possible that it reads that completed message before the function WaitForService...the message is removed from the receive queue and the WaitForService function will never receive the message !

Since you mention you have another thread handling CAN and UDS message, you should check if this case does not occur.


Finally here is a temporary solution to force the function WaitForService function to exit: you can call the function UDS_Reset. It will reset the receive and transmit queues and make all waiting functions to exit.