Vehicle Network Toolbox
Communicate with in-vehicle networks using CAN, J1939, and XCP protocols
Vehicle Network Toolbox™ provides MATLAB® functions and Simulink® blocks to send, receive, encode, and decode CAN, CAN FD, J1939, and XCP messages. The toolbox lets you identify and parse specific signals using industry-standard CAN database files and then visualize the decoded signals using the CAN Bus Monitor app. Using A2L description files, you can connect to an ECU via XCP on CAN or Ethernet. You can access messages and measurement data stored in MDF files.
The toolbox simplifies communication with in-vehicle networks and lets you monitor, filter, and analyze live CAN bus data or log and record messages for later analysis and replay. You can simulate message traffic on a virtual CAN bus or connect to a live network or ECU. Vehicle Network Toolbox supports CAN interface devices from Vector, Kvaser, PEAK-System, and National Instruments®.
Configuring CAN and CAN FD Channels
CAN channel functions in MATLAB and CAN configuration blocks in Simulink enable you to define a connection to Vector CAN interface hardware that establishes a physical connection with a CAN bus using either the CAN or CAN FD standard. Vehicle Network Toolbox™ provides CAN channel functions to query and configure CAN interface hardware settings, such as bus speed and transceiver settings. You can also verify other CAN channel properties, such as the number of messages available and the number of messages received or transmitted on the channel. By attaching Vector CAN database files to CAN channels, incoming messages are automatically presented using information stored in the database. After defining a CAN channel, you can send and receive CAN messages on the channel.
Sending and Receiving CAN Packets
Standard CAN messages contain properties for storing the CAN message identifier (standard 11-bit or extended 29-bit), the time stamp, and up to 8 bytes of CAN data. A channel configured for CAN FD transmission can hold messages that contain up to 64 bytes of data.
Transmit and receive functions and blocks in the toolbox enable the sending and receiving of CAN messages over CAN channels. For large datasets, you can log CAN messages for offline analysis.
Building and Extracting Signals from CAN Messages
Vehicle Network Toolbox provides functions and blocks for encoding and decoding CAN messages. CAN message data may contain data representing multiple signals. Unpack functions and blocks let the user specify start bit, signal length, data type, and byte ordering. Pack functions and blocks provide the same options for building up data for CAN message transmission.
Logging and Replaying CAN Messages
Using the CAN Log block in the toolbox, you can save CAN messages received by your model to a MAT-file. You can then use the CAN Replay block to replay the messages in another Simulink model. The CAN Replay block preserves the time stamps of the logged data so the replayed data will have the same timing characteristics as the recorded data.
Vehicle Network Toolbox provides functions and blocks for communicating with ECUs via XCP—an automotive calibration protocol—over CAN or Ethernet bus. When communicating with ECUs over XCP, MATLAB or Simulink is the master and the ECUs are slave devices. You can communicate with multiple ECUs by opening multiple XCP channels. For each ECU, you can read and write data to specific memory locations within the ECU. When secured access to an ECU exists, you can use seed and key security to open access to the ECU. The toolbox also provides functions and blocks for linking A2L database files and for creating and viewing dynamic DAQ and STIM measurement lists for an XCP channel. These lists are established based on measurement and event information from the linked A2L file.
Vehicle Network Toolbox provides functions and blocks for communicating via J1939—a CAN-based high-level protocol commonly used in the heavy-duty truck industry. When communicating over J1939, you use MATLAB functions or Simulink blocks to set up the communication. Specifically, functions and blocks are provided to associate a database (.dbc) file to the J1939 communication, to specify the CAN interface hardware, and to transmit and receive J1939 parameter groups. You encode and decode signal data on the network by using parameter groups defined by the database file associated with the connection. Additionally, you can configure Simulink to operate as network nodes with address claiming.
The toolbox provides a Vehicle Network CAN Bus Monitor app for visualizing active traffic on a particular CAN channel. You can use the app while performing other tasks in MATLAB or Simulink. For CAN database files associated with your CAN channel, the app decodes the messages and displays them in their correct engineering units.
When traffic on the network contains more information than needed for your application, you can limit the number of CAN messages received by a CAN channel to a defined range of CAN message identifiers. Using filter functions and mask settings in the toolbox, you receive only the messages needed for your application.
Vehicle Network Toolbox lets you associate a Vector CAN database file with a CAN channel or message from MATLAB or Simulink, enabling you to encode and decode CAN messages using application-specific message and signal names such as EngineMsg and EngineRPM, as well as scaled engineering units. The ability to work with industry-standard database files simplifies the interaction with the CAN bus because the database not only specifies the message list and component signals, but also provides the bit packing and unpacking rules for the associated signals. Because signal data type, start bit, length, and byte order are all predefined for the messages in the database, you can focus on analyzing your signals rather than defining them.
Vehicle Network Toolbox lets you use industry-standard A2L (also known as ASAP2) description files to communicate with ECUs over the XCP protocol from MATLAB or Simulink. Using A2L description files enables you to access internal ECU parameters from a MATLAB program or a Simulink model. A2L description files contain information about the associated memory address for a particular parameter, the storage structure, and the data type. The files also contain rules for converting stored values such as system parameters, sensor characteristics, and correction factors into physical units such as RPM and degrees Celsius. Having this data lets you easily perform calibration and measurement tasks without needing to parse data and decode memory addresses.
With Vehicle Network Toolbox, you can easily import data from measurement data format (MDF) files. The toolbox supports version 3.0 and higher of the MDF standard. When you create an MDF object in MATLAB, you can view the basic properties about the file, including initial time stamp, data size, channel group, and channel name information. To read in a subset of an MDF file, you specify the channel names or the start and stop times. By default, the output format of your result will be returned as a timetable so that you can easily work with the time-stamped data.
For large MDF files that don’t fit in memory, you can create an MDF datastore and preview the data in batches based on parameters that you specify. You can also create a datastore to easily work with a collection of similar MDF files.
You can use virtual CAN and CAN FD channels for testing and simulation of network communications. With a virtual channel, you can test models in a loopback configuration without using physical hardware. Vehicle Network Toolbox supports two kinds of virtual channels: MathWorks virtual channels and those from third-party CAN interface hardware vendors. Virtual channels from third-party vendors such as Vector and Kvaser require the installation of the corresponding vendor driver or hardware support package. MathWorks virtual channels are shipped with the toolbox and require no additional drivers or support packages.
Access MDF files on Linux platform
Event-based Transmission in Simulink
Transmit CAN messages only when a change in message data is detected