You load a J1939 DBC, decode a truck log, and get engine speed from some frames but KeyError or nothing from others. The DBC is fine. The problem is how J1939 IDs work: the DBC stores one full CAN ID per message, and the truck sends the same message with different IDs.

Why exact-ID matching fails

A J1939 CAN ID has three parts: priority, PGN, and source address.

Example
0CF00400  ->  priority 3 | PGN 61444 (EEC1) | source 0x00
0CF00417  ->  priority 3 | PGN 61444 (EEC1) | source 0x17
18F00400  ->  priority 6 | PGN 61444 (EEC1) | source 0x00

All three are EEC1, the electronic engine controller message with engine speed. A DBC stores it once, with one ID such as 0CF00400. A decoder that looks up the exact ID finds the first frame and misses the other two, even though they have the same layout.

This is common in practice:

  • A second engine or a retarder sends the same PGN from another address.
  • Aftermarket devices use their own source address.
  • A J1939 DBC written for one vehicle is used on another, where ECU addresses differ.
  • Priority can be changed, so the top bits of the ID differ too.

The fix is to match on the PGN and ignore priority and source address. If you need a refresher on extracting the PGN, see what a PGN is.

What a J1939 DBC looks like

A J1939 DBC is an ordinary DBC with extended IDs:

Example
BO_ 2364539904 EEC1: 8 Engine
SG_ ActualEnginePercentTorque : 16|8@1+ (1,-125) [-125|125] "%" Vector__XXX
SG_ EngineSpeed : 24|16@1+ (0.125,0) [0|8031.875] "rpm" Vector__XXX
  • 2364539904 is 0x8CF00400: bit 31 marks an extended ID, so the real ID is 0CF00400.
  • Signals are SPNs. Engine speed is SPN 190 in bytes 4–5, 0.125 rpm per bit.
  • J1939 DBCs often store the SPN number as a signal attribute and mark the database as J1939 with a ProtocolType attribute. Tools that understand those attributes match messages by PGN for you; many simpler tools do not.

The full J1939 parameter list is published by SAE, which sells an official J1939 DBC. Treat a J1939 DBC you receive like any other licensed file and do not post it publicly.

Decode by PGN with cantools

cantools has J1939 helpers. pgn_from_frame_id extracts the PGN and handles the PDU1 case where the PS byte is a destination address. Build a lookup by PGN once, then decode every frame through it:

Python
import cantools
from cantools.j1939 import pgn_from_frame_id

db = cantools.database.load_file("j1939.dbc")
messages_by_pgn = {pgn_from_frame_id(m.frame_id): m for m in db.messages if m.is_extended_frame}


def decode_j1939(frame_id: int, data: bytes):
    message = messages_by_pgn.get(pgn_from_frame_id(frame_id))
    if message is None:
        return None
    return message.name, frame_id & 0xFF, message.decode(data, decode_choices=False)


print(decode_j1939(0x0CF00417, bytes.fromhex("FFFF7D401FFFFFFF")))
Example
('EEC1', 23, {'ActualEnginePercentTorque': 0, 'EngineSpeed': 1000.0})

The frame came from source address 0x17, which is not the address in the DBC, and it still decodes. Bytes 4–5 are 40 1F: 0x1F40 = 8000, × 0.125 = 1000 rpm. Byte 3 is 7D = 125, − 125 = 0 % torque.

Return the source address with every decoded value, as above. Without it you cannot tell two engines apart.

Decode a whole log

Combine the lookup with python-can's log reader. This works for BLF, ASC, candump logs, and the other formats python-can reads:

Python
import can

for msg in can.LogReader("truck.blf"):
    if not msg.is_extended_id or msg.is_error_frame:
        continue
    result = decode_j1939(msg.arbitration_id, bytes(msg.data))
    if result:
        name, source, signals = result
        print(f"{msg.timestamp:.3f} {name} from 0x{source:02X}: {signals}")

Two things this loop does not do:

  • Multi-packet messages. DM1 with several faults, the VIN, and other long PGNs arrive as transport protocol frames. Reassemble them first; see the J1939 transport protocol guide.
  • Not-available values. J1939 marks missing data with all-ones: 0xFF in a one-byte parameter, 0xFF00–0xFFFF in a two-byte one. Error values start at 0xFE and 0xFE00. Engine speed 0xFFFF decodes to 8191.875 rpm, which is not a real speed. Filter these before plotting.

A shortcut with frame_id_mask

cantools can also mask IDs before lookup:

Python
db = cantools.database.load_file("j1939.dbc", frame_id_mask=0x03FFFF00)

The mask drops priority and source address, so 0CF00417 and 18F00400 both match 0CF00400. It is simpler, but it keeps the destination byte of PDU1 messages, so it only works for broadcast PGNs (PDU Format 240 and above). The PGN lookup above handles both.

Check the DBC itself

When a J1939 value decodes but looks wrong, the DBC is the next suspect:

  1. Search the DBC by PGN, not by full ID, and check which source address it assumes.
  2. Check the SPN's start byte and length against your documentation. J1939 parameters start at byte boundaries more often than not, so a start bit that is not a multiple of 8 deserves a second look.
  3. Check scale, offset, and unit, for example 0.125 rpm per bit for engine speed and −40 °C offset for coolant temperature.
  4. Check for proprietary PGNs. PGNs 61184 (Proprietary A) and 65280–65535 (Proprietary B) mean different things on every vehicle.

DBC Utility helps with these steps: search by frame ID, see each signal's bytes on the layout grid, and read SPN attributes next to the signal. Its log analyser decodes ASC and BLF recordings with your DBC, and its Unknown IDs view shows which IDs your DBC does not match.

Frequently asked questions

Why does my J1939 DBC not decode all frames?

Because the DBC stores one full CAN ID per message, including a source address and priority. Frames with the same PGN from other addresses, or with another priority, do not match unless your tool looks up messages by PGN.

How do I get the PGN from a J1939 CAN ID?

Take bits 8 to 25. If the PDU Format byte (bits 16–23) is below 240, set the low byte to zero because it is a destination address. In Python, cantools.j1939.pgn_from_frame_id() does this.

Where can I get a J1939 DBC file?

SAE sells an official J1939 DBC, and some logger vendors sell or bundle one. Vehicle and engine makers also publish DBCs or PGN lists for their proprietary messages under their own terms.

References