Handling of TestWaitForDiagResponse Function (CANoe only)
|1||a response (positive or negative) has been received (P2 or P2* timeouts of ECU have not occurred)|
|0||the timeout specified in the TestWaitForTimeout has occurred|
|-92||Errors in the transport layer have occurred:
this is also the error code for P2 or P2* timeouts!
|<0||errors in the diagnostic or transport layer have occurred.|
You have to differentiate between this function’s timeout and P2 or P2* timeouts of the ECU. These are both independent timeouts. In case that a P2 or P2* timeout has occurred, the TestWaitForDiagResponse function will return -92 (even when the timeout specified in the function call has not occurred yet), in case of the occurrence of the specified timeout, the function will return 0. CANoe will consider the reception of „Response Pending“ responses from the ECU before returning a TP level error.
Hints for the calculation of the timeout parameter of the TestWaitForDiagResponse function:
It should be equal or larger than the P2 timing of the ECU, better at least the P2* timing. If it is too small, you can get timeouts even when the ECUs is conformant to its specification. Setting this value too high results in longer test execution time, but it matters only when responses are not sent by the ECU (frequently). You have to adjust this value to your situation.
Diagrequest Door.SerialNumber_Read req;
ret = testWaitForDiagRequestSent(req, 2000); // Wait until the request has been completely sent
if(ret == 1) // Request sent
write("Request has been successfully sent");
ret2=TestWaitForDiagResponse(req, 5000); // Wait for a response, here for 5000ms. Note: This is no P2 timeout!
if(ret2==1) // Response received
if(ret3==-1) // It is a positive response
buffer,elCount(buffer)); // Retrieve the serial number from the response
write("Serial Number: 0x%02X%02X%02X%02X",
else // It is a negative response
write("Negative Response, NRC: 0x%02X",(byte)ret3);
if(ret2==0) // Timeout. No response received
write("Timeout specified in TestWaitForDiagResponse expired");
if(ret2<0) // Error e.g. transport protocol level
write("TP level error %d, probably P2 or P2* timeout", ret2);
write("Error %d in the diagnostic or transport layer", ret2);
write("Timeout expired while trying to send request");
write("Internal error %d occured while trying to send request", ret);