Chapter 3
NI-CAN Programming Techniques
3-4
ni.com
comparator attributes to
NC_CAN_ARBID_NONE
. By doing this, the CAN
communications controller chip is best able to filter out all incoming frames
except those handled by CAN Objects.
Detecting State Changes
You can detect state changes for an object using one of the following
schemes:
•
Call
ncGetAttribute
to get the
NC_ATTR_STATE
attribute.
•
Call
ncWaitForState
to wait for one or more states to occur.
•
Use
ncCreateNotification
to register a callback for one or more
states.
Use the
ncGetAttribute
function when you need to determine the
current state of an object. For example, if you want to determine
whether a background error has occurred for an object, you can use
ncGetAttribute
to obtain the state and check for
NC_ST_ERROR
.
Use the
ncWaitForState
function when your application must wait for a
specific state before proceeding. For example, if you call
ncWrite
to write
a frame, and your application cannot proceed until the frame is successfully
transmitted, you can call
ncWaitForState
to wait for
NC_ST_WRITE_SUCCESS
.
Use the
ncCreateNotification
function when your application must
handle a specific state, but can perform other processing while waiting for
that state to occur. The
ncCreateNotification
function registers a
callback function, which is invoked when the desired state occurs. For
example, a callback function for
NC_ST_READ_AVAIL
can call
ncRead
and place the resulting data in a buffer. Your application can then perform
any tasks desired, and process the CAN data only as needed.