Status code use – National Instruments CAN 372139B-01 User Manual

Page 195

Advertising
background image

Chapter 6

Automotive Diagnostic Command Set API for C

© National Instruments Corporation

6-31

Automotive Diagnostic Command Set User Manual

Status Code Use

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);

}

}

}

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.

Advertising