1. Controller Area Network Overview
CAN provides an inexpensive, durable network that helps multiple CAN devices communicate with one another. An advantage to this is that electronic control units (ECUs), or other devices that communicate using CAN, can have a single CAN interface rather than analog and digital inputs to every device in the system. This decreases overall cost and weight in automobiles. Each of the devices on the network has a CAN controller chip and is therefore intelligent. All devices on the network see all transmitted messages. Each device can decide if a message is relevant or if it should be filtered. In addition, every message has a priority, so if two nodes try to send messages simultaneously, the one with the higher priority gets transmitted and the one with the lower priority gets postponed.
Figure 1. CAN networks simplify wiring between the many devices connected on the network.
CAN database files are text files that contain scaling information for CAN frames and signal definitions. National Instruments CAN interfaces recognize FIBEX database files (.xml), vector database files (*.dbc), and National Instruments CAN database files (*.ncd).
For each signal, CAN databases define rules for conversion to engineering units. The following data is stored in databases:
- Channel name
- Location (start bit) and size (number of bits) of the channel within a given message
- Byte order (Intel/Motorola)
- Data type (signed, unsigned, and IEEE float)
- Scaling and units string
- Default value
By using a database file for many frames on the CAN network, many CAN APIs (like NI-XNET) can automatically convert the frame information directly to a real-world value. This simplifies application development because you never need to worry about the raw frame values.
For additional information on CAN, view the Controller Area Network (CAN) Overview document.
2. NI CompactDAQ Overview
An NI CompactDAQ system consists of a chassis, NI C Series I/O modules, and software. Chassis can connect to a host computer over USB, Ethernet, or 802.11 Wi-Fi or operate stand-alone with a built-in controller. With over 50 measurement-specific modules and 1-, 4-, and 8-slot chassis, NI CompactDAQ provides a flexible, expandable platform to meet the needs of any electrical or sensor measurement system.
Figure 2. An NI CompactDAQ system combines a single chassis with up to 8 C Series modules for CAN communication and other measurements.
NI CompactDAQ chassis control the timing, synchronization, and data transfer between up to eight C Series I/O modules and an external or built-in computer. A single NI CompactDAQ chassis can manage multiple timing engines to run up to seven separate hardware-timed I/O tasks at different sample rates in the same system. For example, you can install a 75 S/s thermocouple module next to a 51.2 kS/s accelerometer module and acquire from both simultaneously.
3. Programming CAN Communication With NI CompactDAQ
Using the NI-XNET API
CAN communication in the NI CompactDAQ platform is programmed in software using the NI-XNET API. This API is the same API that you can use for CAN, LIN, and FlexRay communication with all of the NI-XNET hardware interfaces in the NI CompactDAQ, NI CompactRIO, PXI, and PCI form factors. Some of the key features of this API are highlighted below.
NI-XNET is a session-based API – The NI-XNET API helps you quickly configure and select the type of communication you want to perform with the CAN hardware. You can easily select the type of session you want to open based on your task, and this information is stored in the API.
Figure 3. With the NI-XNET API, you can select the type of communication you want to perform and create a session based on this selection.
NI-XNET allows multiple sessions per port – You can use the same CAN port for reading and writing on the CAN bus in addition to having multiple read or multiple write sessions on that port. The high-performance NI-XNET hardware can keep up with the communication, and the NI-XNET API simplifies your experience in configuring multiple sessions.
Figure 4. You can use the same CAN interface for several reading or writing sessions.
NI-XNET features tight database integration – The NI-XNET driver allows for both raw frame or signal communication on the CAN bus. You can easily choose an abstracted, or higher-level, view of the bus communication by selecting a CAN database file to reference when getting real-world values from CAN messages. Or you can do more lower-level communication on the bus by just reading and writing raw CAN frames.
Figure 5. The NI-XNET API allows for tight integration and communication with CAN databases.
NI-XNET includes a Bus Monitor – The NI-XNET driver also includes preconfigured tools to help decrease development time and accomplish common and critical tasks for CAN communication. The NI-XNET Bus Monitor gives you a real-time view of the bus traffic on a specific port. You can implement other common tasks like associating the traffic with a database, logging bus traffic, and filtering CAN IDs with the NI-XNET Bus Monitor.
Figure 6. The NI-XNET Bus Monitor shows live traffic on a bus while giving you access to other common tasks.
NI-XNET includes a Database Editor – The NI-XNET Database Editor gives you the ability to configure and edit database files to use with CAN buses. Inside the editor, you can import, create, and configure FIBEX, .DBC, and .NCD files. This tool provides an intuitive user interface for working with CAN databases.
Figure 7. With the NI-XNET Database Editor, you can import, create, and configure CAN database files.
Combining CAN Communication With Other Measurements and Data Acquisition
You can use CAN and other data acquisition in the same software program and in the same NI CompactDAQ chassis at the same time. Even though the different modules use a different API than the CAN communication module, they can both be used at the same time to control the different pieces of hardware.
All NI-XNET ports in a particular NI CompactDAQ chassis share a common timebase with other C Series modules, allowing a better correlation of data and traffic from the chassis. Also, you can route the Start Trigger in an NI CompactDAQ chassis between multiple DAQmx and NI-XNET modules. For example, using the appropriate property nodes, the Start Trigger of an analog input module can be used as a CAN interface Start Trigger.
Figure 8. You can synchronize CAN traffic with other I/O modules and trigger them off analog data using the NI-XNET API.
CAN communication is used in a variety of applications and is often not the only part of the project because other types of measurements are acquired at the same time. The ability to combine CAN with other mixed measurements in the NI CompactDAQ platform makes it easier than ever to have portable USB- or Ethernet-based systems that also provide the inherent timing and synchronization advantage that is part of the NI CompactDAQ platform.