Chapter 2
Developing Your Application
2-12
ni.com
For each NI-CAN function, you can find numeric values for the returned
status code and qualifier in the online description of the function, which
you can access in the Block Diagram by selecting the function and typing
<Ctrl-H>.
Checking Status in C
For applications written in C or C++, you should define a function to handle
NI-CAN warnings and errors. When this function detects an error, it closes
all open objects, then exits the application. When this function detects a
warning, it can display a warning message or simply ignore the warning.
If the function has the following prototype:
void CheckStat(NCTYPE_STATUS stat, char *msg);
then your application invokes it as follows:
if (status != 0)
CheckStat(status, "NI-CAN error or warning");
For an example implementation of the
CheckStat
function, refer to the
C language examples in the NI-CAN
examples
directory.
When accessing the NI-CAN code and qualifier within your application,
you should use the constants defined in
nican.h
. These constants have the
same names as described in the
NI-CAN Programmer Reference Manual
.
For example, to check for a timeout, you would use code such as the
following:
if (NC_STATCODE(status) == NC_ERR_TIMEOUT)
printf("NI-CAN timeout");