National Instruments NI-CAN User Manual page 46

Table of Contents

Advertisement

© National Instruments Corporation
plays the role of the simulated speed display, and the other port plays the
role of the simulated speed sensor.
Example 1 configures one CAN Object to receive data, and configures
another CAN Object to transmit data. Both CAN Objects use arbitration
ID 5. The data is transmitted every second, so the test engineer can view
each period's data as well as its timestamp. Once the engineer completes
the example, he can change it for testing of each device by using one CAN
Object at a time.
The following steps correspond to the program flow chart in Figure 4-1.
1.
The application calls
Interface Objects for both ports (
configuration would be handled using the NI-CAN Configuration
utility, but
ncConfig
self-contained.
2.
The application calls
both ports (
CAN0::STD5
configuration would normally be handled using the NI-CAN
Configuration utility.
3.
The application calls
4.
The application calls
periodic transmission of data. For this example, the same data is
transmitted every period.
5.
The application calls
wait for the
NC_ST_WRITE_SUCCESS
first CAN frame is successfully transmitted to the other CAN Object.
6.
The application calls
wait for the
NC_ST_READ_AVAIL
frame is received from the other CAN Object.
7.
The application calls
contains the value written in step 4, as well as a timestamp of when the
value arrived.
8.
The application loops back to step 6 for a total of 10 periods. Each
period, step 6 waits one second before the next data value is received.
9.
When all 10 loops complete, both CAN Objects are closed using
ncCloseObject
to configure the CAN Network
ncConfig
and
CAN0
is used instead to keep the example
to configure the CAN Objects for
ncConfig
and
CAN1::STD5
to open the two CAN Objects.
ncOpenObject
for
ncWrite
CAN1::STD5
ncWaitForState
state. This state is set when the
ncWaitForState
state. This state is set when a CAN
to read data for
ncRead
.
4-3
Chapter 4
Application Examples
). Normally, this
CAN1
). Once again, such
. This call starts the
for
in order to
CAN1::STD5
for
in order to
CAN0::STD5
. The data
CAN0::STD5
NI-CAN User Manual

Advertisement

Table of Contents
loading

Table of Contents