CAN Input

CompactRIO Reference and Procedures (FPGA Interface)

Edition Date: June 2010

Part Number: 370984T-01

»View Product Info

Wait for a CAN frame to be received, then return that frame.

Complete the following steps to read from a CAN port using CAN Input.

  1. Use the Add Targets and Devices dialog box to add the CAN module to your CompactRIO configuration. Right-click the CAN module in the Project Explorer window and select Properties to specify the configuration properties for the module.
  2. Create an FPGA I/O item for CAN by right-clicking the FPGA target under My Computer in the Project Explorer window, selecting New»FPGA I/O, and then adding CAN»NI 9852»CAN0 (or CAN»NI 9853»CAN0) and/or CAN»NI 9852»CAN1 (or CAN»NI 9853»CAN1) to the FPGA I/O list. Refer to New FPGA I/O dialog box (FPGA Module) for more information about creating and adding FPGA I/O to your CompactRIO configuration.
  3. Place an I/O Node from the FPGA I/O palette onto your FPGA VI diagram.
  4. Right-click the I/O Node and select Select FPGA I/O»CAN»NI 9852»CAN0 (or Select FPGA I/O»CAN»NI 9853»CAN0) or Select FPGA I/O»CAN»NI 9852»CAN1 (or Select FPGA I/O»CAN»NI 9853»CAN1).
  5. Right-click the I/O Node and select Change to Read to use the I/O node for CAN Input.
  6. Right-click the I/O Node and choose Properties to select the Data Type.

Start communication on the CAN port prior to using CAN Input. Enable Auto Start in the Module Configuration, or invoke the Start method to start communication.

The Input Timeout (ms) of the CAN Advanced Port Configuration dialog box specifies how long to wait for a new frame to be received. If you specify Input Timeout (ms) of 0, the CAN Input node will simply check to see if a new frame has arrived (non-blocking).

For information on how CAN Input arbitrates with other CAN nodes, refer to Arbitration.

Note  You can add more than one CAN input port to the FPGA I/O node, and also add analog and digital inputs to the same FPGA I/O node by right-clicking the FPGA I/O node and selecting Add Element. Right-click the created I/O name and choose Select FPGA I/O to specify the I/O name. If you use more than one input per node, LabVIEW will execute them sequentially starting with the top input. If one input is blocked while waiting for the input, subsequent inputs will be delayed. For example, if you read CAN0 and CAN1 with the same CAN Input node, that node will wait for a frame to be received on CAN0, then it will wait for a frame to be received on CAN1. It is more efficient to access each CAN port using a distinct CAN Input node.

Properties Dialog

The Data Type selects the type for the CAN frame returned by the CAN Input node. The available values are Cluster (default) and Array of 6 U32.

The benefits of using the Cluster data type are:

  • Simpler block diagram (easy to use)
  • Fast and efficient, if you limit use to the block diagram only (not front panel)

The benefits of the Array of 6 U32 data type, and handshaking integers to the host VI one at a time, are:

  • Faster for transfer to/from host VI
  • Fewer FPGA gates

Refer to the Using Clusters and Arrays in LabVIEW FPGA Application Note for more information on the use of clusters and arrays. Refer to the CAN examples in NI 9852/NI 9853 Related Documentation for examples using each data type.

Node Inputs

Error In

Optional. Not shown by default. Right-click the node and select Error Terminals to enable.

Node Outputs

Error Out

Optional. Not shown by default. Right-click the node and select Error Terminals to enable.

Unless you set the Input Timeout (ms) to –1 to wait indefinitely, you must use the error terminals to determine whether the CAN Input successfully received a CAN frame.

CANx

If the Data Type is defined as Cluster (default), the CAN frame is represented as a cluster with the following elements:

Timestamp High
Timestamp Low
Timestamp of when the frame was received. The timestamp is acquired at the end of the CAN frame. The high and low U32 represent a single U64 timestamp. The timestamp is large enough to avoid handling rollover. The timestamp is zero-based (relative). The time starts ticking at zero when CAN communication starts. The resolution is 100 ns.
Identifier

Arbitration ID.

If bit 29 (20000000 hexadecimal) is clear, this ID uses the standard format (11-bit). If bit 29 is set, this ID uses extended format (29-bit).

This representation of the CAN identifier is the same as NI-CAN (see NI 9852/NI 9853 Related Documentation and Examples).

Type
Type of frame:
Data Frame0
Remote Frame1
Bus Error6
Transceiver Fault7
InfoA

Reserved for future use.

InfoB

Reserved for future use.

Data Length

For data frames, this indicates the number of bytes in Data (0–8).

For remote frames, this indicates the number of bytes requested.

Data

For data frames, this provides the data bytes. The array uses a fixed size of 8 bytes. For remote frames, the values contained in Data are not valid and should be ignored.

If the Data Type is defined as Array of 6 U32, the CAN frame is represented as the following array of 6 U32 values:
Most significant byte ... ... Least significant byte
Timestamp (upper U32)
Timestamp (lower U32)
Identifier
Type InfoA InfoB DataLength
Data[0] Data[1] Data[2] Data[3]
Data[4] Data[5] Data[6] Data[7]

The meaning of each element is the same as the Cluster data type.

WAS THIS ARTICLE HELPFUL?

Not Helpful