CAN, FlexRay, and LIN
- Updated2025-10-10
- 7 minute(s) read
This format is used for CAN, FlexRay, and LIN interfaces. This includes frames for SAE J1939 and CAN FD. Refer to the NI-XNET log file examples for functions and VIs that convert raw frame data to/from LabVIEW clusters for CAN, FlexRay, or LIN frames. Each frame is encoded as one Base Unit, followed by zero or more Payload Units.
Base Unit
In the following table, Byte Offset refers to the offset from the frame start. For example, if the first frame is in raw data bytes 0–23, and the second frame is in bytes 24–47, the second frame Identifier starts at byte 32 (24 + Byte Offset 8).
| Element | Byte Offset | Description | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Timestamp | 0 to 7 |
64-bit timestamp in 100 ns increments. The timestamp format is absolute. The 64-bit element contains the number of 100 ns intervals that have elapsed since 1 January 1601 00:00:00 Coordinated Universal Time (UTC). IN previous releases, this timestamp was called nxTimestamp_t. This element contains a 64-bit unsigned integer (U64) in native byte order. For little-endian computing platforms (for example, Windows), Byte Offset 0 is the least significant byte. For more information, refer to the NI-XNET examples for log file access. |
||||||||||||||||||||||||||||||||||||||||||||||||
| Identifier | 8 to 11 |
The frame identifier. This element contains a 32-bit unsigned integer (U32) in native byte order. When Type specifies a CAN frame, bit 29 (hex 20000000) indicates the CAN identifier format: set for extended, clear for standard. If bit 29 is clear, the lower 11 bits (0–10) contain the CAN frame identifier. If bit 29 is set, the lower 29 bits (0–28) contain the CAN frame identifier. When Type specifies a FlexRay frame, the lower 16 bits contain the slot number. When Type specifies a LIN frame, this element contains a number in the range 0–63 (inclusive). This number is the LIN frame's ID (unprotected). For SAE J1939 frames, the PGN and address fields are mapped to the Extended CAN identifier and written in the same way as for CAN. All unused bits are 0. |
||||||||||||||||||||||||||||||||||||||||||||||||
| Type | 12 |
The frame type. This element specifies the fundamental frame type. The Identifier, Flag, and Info element interpretations are different for each type. The upper 3 bits of this element specify the protocol. The valid values in
decimal are:
The lower 5 bits of this element contain the specific type.
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Flags | 13 | Eight Boolean flags that qualify the frame type. Bit 7 (hex 80) is protocol independent (supported in CAN, FlexRay, and LIN frames). If set, the frame is echoed (returned from the appropriate nxRead function or XNET Read VI after NI-XNET transmitted on the network). If clear, the frame was received from the network (from a remote ECU). For FlexRay frames:
For LIN frames:
All unused bits are zero. |
||||||||||||||||||||||||||||||||||||||||||||||||
| Info | 14 | Information that qualifies the frame Type. This element is not used for CAN. For FlexRay frames, this element provides the frame cycle count (0–63). For LIN frames read for a non-stream input session, if bit 0 of the Flags element is clear, the Info element is unused (0). If bit 0 of the Flags element is set (event-triggered entry), the Info element contains the event-triggered frame ID, and the Identifier element contains the Unconditional ID from the first payload byte. For LIN frames read for a stream input session, if Interface:LIN:Checksum to Input Stream? is false (default), the Info element contains 0 for each frame. If true, the Info element contains the received checksum for each frame. For SAE J1939 frames, the three lowest bits of this element contain the three highest bits of the PayloadLength. |
||||||||||||||||||||||||||||||||||||||||||||||||
| Payload Length | 15 | The PayloadLength indicates the number of valid data bytes in Payload. For all standard CAN and LIN frames, PayloadLength cannot exceed 8. Because this base unit always contains 8 bytes of payload data, the entire frame is contained in the base unit, and no additional payload units exist. For CAN FD frames, PayloadLength can be 0–8, 12, 16, 20, 24, 32, 48, or 64. For FlexRay frames, PayloadLength is 0–254 bytes. For SAE J1939 frames, PayloadLength is 0–1785 bytes; the low 8 bits are in this element, and the high three bits are found in the low bits of the Info field. If PayloadLength is 0–8, only the base unit exists. If PayloadLength is 9 or greater, one or more payload units follow the base unit. Additional payload units are provided in increments of 8 bytes, to optimize efficiency for DMA transfers. For example, if PayloadLength is 12, bytes 0–7 are in the base unit Payload, bytes 8–11 are in the first half of the next payload unit, and the last 4 bytes of the next payload unit are ignored. In other words, each raw data frame can vary in length. You can calculate each frame size (in bytes) using the following pseudocode: U16 FrameSize; // maximum 272 for largest FlexRay frame
FrameSize = 24; // 24 byte base unit
if (PayloadLength > 8)
FrameSize = FrameSize +
(U16)(PayloadLength - 1) AND 0xFFF8;The last pseudocode line subtracts 1 and truncates to the nearest multiple of 8 (using bitwise AND). This adds bytes for additional payload units. For example, PayloadLength of 9 through 16 requires one additional payload unit of 8 bytes. The NI-XNET example code helps you handle the variable-length frame encoding details. |
||||||||||||||||||||||||||||||||||||||||||||||||
| Payload | 16 to 23 | This element always uses 8 bytes in the log file, but PayloadLength determines the number of valid bytes. |
Payload Unit
The base unit PayloadLength element determines the number of additional payload units (0–31).
| Element | Byte Offset | Description |
|---|---|---|
| Payload | 0 to 7 | This element always uses 8 bytes in the log file, but PayloadLength determines the number of valid bytes. |
Related Information
- Frame Input Queued Mode
- Frame Input Single-Point Mode
- Frame Input Stream Mode
A frame input stream session reads all frames received from the network using a single stream. It typically is used for analyzing or logging all frame traffic on the network.
- Frame Output Queued Mode
- Frame Output Single-Point Mode
- Frame Output Stream Mode
A frame output stream session transmits an arbitrary sequence of frame values using a single stream. The frame values are not limited to a single frame—they can transmit any frame.
- TDMS