Chapter 4
Application Examples
©
National Instruments Corporation
4-7
(such as
CAN0
), as well as the communication baud rate (such as 125000).
All frames received are displayed in an array of
Received Frames
. If you
want to transmit a specific frame, you can enter the desired
Arbitration
Id
,
Is Remote
flag (off means CAN data frame),
Data Length
, and
Data
bytes, then select
WRITE
to transmit.
The
interact.vi
front panel also supports an optional CAN Object
configured as Transmit Data Periodically. Before running the example,
select
Configure Periodic Transmit
to use this object, and also select the
Arbitration Id
,
Data Length
, and
Period
to configure. While the
example is running, you can use the
Periodic Transmit Data
control to
update the data transmitted each period.
For more information on how to use the front panel of
interact.vi
,
scroll up to the help text located above the front panel controls.
If you do not have a CAN device with which to experiment using
interact.vi
, but you have a two-port CAN interface (such as the
PCI-CAN/2), you can use two copies of
interact.vi
to experiment. Save
a separate copy of the example (such as
interact2.vi
), then run one
copy on one port (such as
CAN0
) and the other copy on the other port (such
as
CAN1
).
The following steps correspond to the program flowchart in Figure 4-3.
1.
The application calls
ncConfig
to configure the CAN Network
Interface Object. The name of the object and its baud rate are obtained
from front panel controls.
2.
The application calls
ncOpenObject
to open the CAN Network
Interface Object.
3.
If
Configure Periodic Transmit
is checked, the application calls
ncConfig
to configure the CAN Object. The name of the object is
obtained using the front panel arbitration ID. The data length and
period are also obtained from front panel controls.
4.
If
Configure Periodic Transmit
is checked, the application calls
ncOpenObject
to open the CAN Object.
5.
If the
WRITE
button has been selected, the front panel arbitration ID,
remote/data flag, data length, and data are used to call
ncWrite
for the
CAN Network Interface Object.
6.
The
ncRead
function is called for the CAN Network Interface Object,
to see if a CAN frame has been received. If
ncRead
returns a code of
zero (success) in its
error out
cluster, the received CAN frame is
inserted into the
Received Frames
array.