Example Code

Advanced CAN Frame to Channel Conversion Reference Example

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Driver

  • NI-CAN

Code and Documents

Attachment

Description

Overview


The CAN Frame to Channel Conversion Example is a set of open source VIs for converting CAN frames to scaled channel data.

Introduction

This example shows how CAN frames can be converted to channels providing a high level organization to CAN applications. It is specifically written for use with the NI 9853 CAN module in a cRIO platform, but could be modified for other NI CAN devices and platforms.

It is recommended to use the “Frame Channel Conversion Library” or the NI-CAN Channel API when possible as these API’s are generally faster, more complete, and better tested. Benefits currently specific to using the Native LabVIEW Frame to Channel Conversion Example include:

• Support for mode depended channels on cRIO

• Open source CANdb (Vector database) and NI-CAN database file parsing

• Open source frame to channel conversion

Example Overview

This example is a CAN datalogger utilizing a cRIO controller and the NI 9853 CAN module. It consists of two main VI’s. The “CAN Channel Data Import.VI” (CCDI) and the “Frame to Channel Conversion.VI” (FTCC). The CCDI parses CAN database files into a LabVIEW structure (cluster) that other VI’s can easily interact with. CANdb or Vector files (.dbc) as well as NI-CAN database files (.ncd) are supported. Figure 1 shows the cluster into which the CAN database data is organized.

Figure 1. LabVIEW cluster containing all CAN message and channel data.

The cluster represents one message with an array of channels within each message. Multiple messages would be contained in an array of the cluster. This framework provides a way to add other details to the code if needed. The cluster is saved into a file that the FTCC uses to process raw CAN frames into scaled channel data.

Figures 2 and 3 show the front panel and block diagram of the CCDI. To import the CAN channel data, the user selects a CAN database file which is then parsed and presented in a table format. The messages of interest can be selected which are then saved into a file for the FTCC to use.

Figure 2. Front Panel of CAN Channel Data Import.VI

Figure 3. Block Diagram of CAN Channel Data Import.VI

 

The FTCC VI converts raw CAN frames to scaled channel data using the previously organized message cluster. This example is setup to process frames as they arrive, but could be re-organized to post process frames if desired. Post processing would reduce CPU utilization and allow faster CAN frame capture. Figures 4 and 5 show the front panel and block diagram of the FTCC VI.

 

Figure 4. Front Panel of Frame to Channel Conversion.VI

 

Figure 5. Block Diagram of Frame to Channel Conversion.VI

 

Example Limitations

The software supports only Intel and Motorola Forward byte ordering when parsing CANdb files and does not support all CANdb functionality. Channel to Frame conversion (writing CAN data) is not supported in this example.

National Instruments respects the intellectual property of others, and we ask our users to do the same.  The use of the SOFTWARE is intended only for use with content owned by the user, public domain content or properly licensed content.  By downloading and/or using the SOFTWARE, you agree that you shall only use the SOFTWARE in a manner that complies with all applicable laws in the jurisdictions in which you use the SOFTWARE, including, but not limited to, applicable restrictions concerning copyright and other intellectual property rights.

 

 

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.