Error Handling Techniques

NI-Motion Functions

Error Handling Techniques

Be sure to constantly watch for error conditions. Always check the function return status for a non-zero error code, and react to the error as appropriate. These non-modal errors are easily handled like any other function error in C/C++ or other programming languages. The NI-Motion software includes a utility function, Get Error Description, which you can use to create error description strings for display.

Modal error handling is a bit more involved. Because these errors are rare but can occur at any time, design the application to check for modal errors at various intervals. This is done by calling the Read Communication Status function and checking the Error Message bit. How often to check for modal errors depends upon the application, but you can use the following list as a guideline:

  1. Check for modal errors at the end of each major subroutine or functional block.
  2. Check for modal errors at the end of an initialization procedure. Also, check after each axis initialization. Always check, after executing a Find Reference function, to make sure the sequence completed successfully.
  3. Include a modal error check in every status polling loop. Most applications include a polling loop to display motion status, position, velocity, and so on. This way you are assured of never missing a modal error.
  4. You can always add a modal error check after each NI-Motion API call, but that is inefficient and unnecessary. Remember that a correctly written program does not generate errors.
  5. During debugging, you can run an independent application to check for modal errors. The MAX interactive panels always check modal errors for you when MAX is running.

Refer to the example programs, included with the NI-Motion software, to see how error handling is implemented in practice.