I have created one Windows Forms form to send and read CAN messages of an ECU. When I created a function to clear all DTCs with the command 0x14 0xFF 0xFF 0xFF, the message response was 7F 14 78 (request correctly received – response pending).
I add Thread.Sleep to wait for the response, but it doesn't work very well.
if (receivedMes.DATA[0] == 0x7F && receivedMes.DATA[2] == 0x78)
{
clsLogManager.LogWarning("Received NRC 0x78, waiting for extended time...");
Thread.Sleep(m_nIOTimeOut * 50);
receivedMes = GetResponseClearDTC(ECU_DID.ClearDTCInformation, m_nIOTimeOut);
if (receivedMes == null || receivedMes.ID == 0 || receivedMes.LENGTH == 0)
return false;
}
How can I fix it?
Every UDS command can take longer than P2ServerMax. In that case, on every NRC BUSY, you will need to wait up to P2*ServerMax until the final response will come. These values are ECU-specific and you get them as the response to a diagnostic session control (e.g., 10 01).