National Instruments NI-CAN User Manual page 48

Table of Contents

Advertisement

© National Instruments Corporation
CAN as their in-vehicle network. The utility monitors the car's CAN
network traffic to test for defective devices, incorrect sensor data, and so on.
In developing the utility, the test engineer wants two threads. One thread
receives data from the CAN network and places it into a buffer. The other
thread processes the data in the buffer in order to check for erroneous
network traffic.
The following steps correspond to the program flowchart in Figure 4-2.
1.
The application calls
Interface Object used for bus analysis (
comparators are configured such that all CAN data frames are
received. Normally, this configuration would be handled using the
NI-CAN Configuration utility, but
the example self-contained.
2.
The application calls
Interface Object.
3.
The application calls
notification thread, which is used to receive frames into the buffer. This
is done by registering a callback function for the
state. After creating the notification thread, the main thread proceeds
to Step 7.
4.
The notification thread remains idle until its callback function is
invoked by the NI-CAN driver.
5.
If the callback function detects the
is called to read the frame, and the frame is placed into the
ncRead
buffer for processing by the main thread.
6.
If the callback function detects a timeout or error, it indicates the
problem to the main thread, then proceeds to Step 9. If no timeout or
error is detected, the callback function re-enables the notification and
returns to Step 4 (idle).
7.
If the main thread detects a new frame in the buffer (placed there by the
notification thread in Step 5), it processes the frame. For this example,
processing the frame merely entails printing it to the screen.
8.
If the main thread does not detect a timeout or error, it loops back to
Step 7 to wait for more frames.
9.
If a timeout or error occurs, the main thread prints it to the screen.
The timeout occurs if no frame is received within 30 seconds.
10. The application calls
Interface Object.
to configure the CAN Network
ncConfig
CAN0
ncConfig
to open the CAN Network
ncOpenObject
ncCreateNotification
NC_ST_READ_AVAIL
ncCloseObject
4-5
Chapter 4
Application Examples
). The masks and
is used instead to keep
to create the
NC_ST_READ_AVAIL
state,
to close the CAN Network
NI-CAN User Manual

Advertisement

Table of Contents
loading

Table of Contents