ndStatusToString
- Updated2024-08-07
- 2 minute(s) read
ndStatusToString
Purpose
Returns a description for an error code.
Format
void ndStatusToString( long errorCode, char message[], long *len);
Input
errorCode
The status code (return value) of any other diagnostic functions.
Output
message
Returns a descriptive string for the error code.
len
On input, len must contain the message array length. On return, it contains the number of valid data bytes in the message array.
Description
When the status code returned from an Automotive Diagnostic Command Set function is nonzero, an error or warning is indicated. This function obtains an error/warning description for debugging purposes.
The return code is passed into the errorCode parameter. The len parameter indicates the number of bytes available in the string for the description. The description is truncated to size len if needed, but a size of 1024 characters is large enough to hold any description. The text returned in message is null-terminated, so you can use it with ANSI C functions such as printf. For C or C++ applications, each Automotive Diagnostic Command Set function returns a status code as a signed 32-bit integer. The following table summarizes the Automotive Diagnostic Command Set use of this status.
Status Code Use
Status Code | Definition |
---|---|
Negative | Error—Function did not perform the expected behavior. |
Positive | Warning—Function performed as expected, but a condition arose that may require attention. |
Zero | Success—Function completed successfully. |
The application code should check the status returned from every Automotive Diagnostic Command Set function. If an error is detected, close all Automotive Diagnostic Command Set handles and exit the application. If a warning is detected, you can display a message for debugging purposes or simply ignore the warning.
The following code shows an example of handling Automotive Diagnostic Command Set status during application debugging.
Status = ndOpenDiagnostic ("CAN0", 500000, 0, 0x7E0, 0x7E8, &MyDiagHandle);
PrintStat (status, "ndOpenDiagnostic");
where the function PrintStat has been defined at the top of the program as:
void PrintStat(mcTypeStatus status, char *source)
{
char statusString[1024];
long len = sizeof(statusString);
if (status != 0)
{
ndStatusToString(status, statusString, &len);
printf("\n%s\nSource = %s\n", statusString, source);
if (status < 0)
{
ndCloseDiagnostic(&MyDiagHandle);
exit(1);
}
}
}