Step 4. Communicate Using Objects; Step 5. Close Objects - National Instruments NI-CAN User Manual

Table of Contents

Advertisement

© National Instruments Corporation

Step 4. Communicate Using Objects

After you open your objects and start communication, you are ready to
transfer data on the CAN network. The manner in which data is transferred
depends on the configuration of the objects you are using. For this example,
assume that you are communicating with a CAN device that periodically
transmits a data frame. To receive this data, assume that a CAN Object is
configured to watch for data frames received for its arbitration ID and store
that data in its read queue.
Step 4a. Wait for Available Data
To wait for the arrival of a data frame from the device, you can call
with the
ncWaitForState
NC_ST_READ_AVAIL
for the CAN Object has been received from the network and placed into the
object's read queue. Another way to wait for the
is to call the
ncCreateNotification
when the state occurs. For more information on
ncCreateNotification
Manual.
When receiving data from the device, if your only requirement is to
obtain the most recent data, you are not required to wait for the
NC_ST_READ_AVAIL
length of the CAN Object to zero during configuration, so that it only holds
the most recent data bytes. Then you can use the
needed to obtain the most recent data bytes received.
Step 4b. Read Data
Read the data bytes using
frames,
returns a timestamp of when the data was received,
ncRead
followed by the actual data bytes (the number of which you configured in
Step 1).
Steps 4a and 4b should be repeated for each data value you want to read
from the CAN device.

Step 5. Close Objects

When you are finished accessing the CAN devices, close all objects using
the
ncCloseObject
Chapter 2
DesiredState
. The
NC_ST_READ_AVAIL
function so you receive a callback
, refer to the NI-CAN Programmer Reference
state. If this is the case, you can set the read queue
. For CAN Objects that receive data
ncRead
function before you exit your application.
2-9
Developing Your Application
parameter set to
state tells you that data
NC_ST_READ_AVAIL
ncWaitForState
function as
ncRead
NI-CAN User Manual
state
and

Advertisement

Table of Contents
loading

Table of Contents