Chapter 9 Checking for Errors in LabWindows/CVI
LabWindows/CVI Programmer Reference Manual 9-2
©
National Instruments Corporation
Note Status codes are integer values. These values are either common to an entire
library of functions, or specific to one function. Libraries that have a common set
of codes have a listing at the end of the chapter or manual they appear in. You can
find the error message for each integer value there. In addition, each of these
libraries contains a function you can call to translate the integer value to an error
string. When an error code is specific to a function, you can find a description for
it in the function description in the LabWindows/CVI manual set. The error
description also appears in the online help of the library function panels in
LabWindows/CVI.
Error Checking
LabWindows/CVI functions return status codes in one of two ways—either by a function
return value, or by updating a global variable. In some cases, LabWindows/CVI uses both of
these methods. In either case, it is a good idea to monitor these values so that you can detect
an error and take appropriate action. A common technique for error checking is to monitor the
status of functions, and when a function reports an error, pause the program and report the
error to the user through a pop-up message. For example,
LoadPanel returns a positive
integer when it successfully loads a user interface panel into memory. However, if a problem
occurs, the return value is negative. The following example shows an error message handler
for
LoadPanel.
panelHandle = LoadPanel (0, "main.uir", PANEL);
if (panelHandle < 0) {
ErrorCheck ("Error Loading Main Panel", panelHandle,
GetUILErrorString (panelHandle));
}
When a function reports status through a separate function, as in the RS-232 Library, check
for errors in a similar way. In this case, the status function returns a negative value when the
original function fails.
bytesRead = ComRd (1, buffer, 10);
if (ReturnRS232Error() < 0) {
ErrorCheck ("Error Reading From ComPort #1", ReturnRS232Error(),
GetRS232ErrorString(ReturnRS232Error()));
}
Notice that the above function also returns the number of bytes read from the serial port. You
can compare the number of bytes read to the number you request, and if a discrepancy exists,
take the appropriate action. Notice that the error codes differ between the RS-232 Library and
the User Interface Library. A section describing how each LabWindows/CVI library reports
errors follows this section.
00ProRef.book : 06chap09.fm Page 2 Monday, March 9, 1998 3:23 PM