Chapter 4
NI-FBUS CM Software
NI-FBUS Hardware and Software User Manual
4-12
ni.com
Write Your Application
Use the following guidelines to make sure your application uses the
NI-FBUS Communications Manager interface properly.
•
Always call
nifOpenSession
early in your program and check
the return value of the call. This check verifies that the NI-FBUS
Communications Manager process is running, which is a prerequisite
for your application to access the Fieldbus network. If this call fails,
your application should inform the user that the Fieldbus is currently
inaccessible.
•
Always close any descriptors that you open before your program
exits, including session descriptors. The NI-FBUS Communications
Manager requires that your application close all descriptors that
it opens.
•
Always check the return values from NI-FBUS calls. The NI-FBUS
Communications Manager is a high-level API and performs many
operations that can fail because of incorrect parameters, incorrect bus
configuration, or communication failures. An application that fails to
check return values might use output parameters from NI-FBUS calls
that are NULL or uninitialized, leading to incorrect behavior or a
program crash.
•
If you plan to call any of the indefinitely-blocking functions including
nifGetDeviceList
,
nifWaitAlert
,
nifWaitAlert2
, and
nifWaitTrend
, you should probably use a separate descriptor for
these calls. To terminate these calls early, you have to close the
descriptor. Having a separate descriptor will ensure that terminating
these calls does not affect any other NI-FBUS calls your application
has pending.
•
If the NI-FBUS Communications Manager stops for any reason,
any outstanding calls in your application complete with the error
E_SERVER_CONNECTION_LOST
. At this point, all of the descriptors
that you have (including the session) are invalid. If you restart the
NI-FBUS Communications Manager, your application should recover
by opening a new session to the NI-FBUS Communications Manager
and opening all new descriptors. After this recovery procedure, your
application should be fully operational.