Skip to main content
Version: 2.3.0

DBC Guide

CanMessenger::DBC parses DBC text and maps signal values to raw CAN bytes.

Load a DBC File

dbc = CanMessenger::DBC.load('example.dbc')

You can also parse inline content:

dbc = CanMessenger::DBC.new(File.read('example.dbc'))

Supported DBC Elements

Current parser support is intentionally narrow and focused:

  • BO_ message definitions.
  • SG_ signal definitions in the common start|length@endian+/- (factor,offset) pattern.
  • Ignores standard metadata directives such as VERSION, NS_, BU_, CM_, VAL_, BA_*, SIG_VALTYPE_, and BO_TX_BU_.

Malformed BO_/SG_ lines and unknown non-empty directives now raise ArgumentError with line context. If your DBC uses advanced constructs (for example multiplexing or uncommon syntax variants), validate with tests before relying on runtime behavior.

Encode by Message Name

frame = dbc.encode_can('Example', Speed: 42)
# => { id: 256, data: [42, ...] }

Validation performed during encoding includes:

  • Unknown message name rejection.
  • Signed/unsigned range checks.
  • Signal bit-bound checks against message DLC.

Decode by CAN ID

decoded = dbc.decode_can(frame[:id], frame[:data])
# => { name: 'Example', signals: { Speed: 42.0 } }

Returns nil if no message with matching CAN ID is found.

Big-endian and Little-endian Signals

  • @1 is treated as little-endian.
  • @0 is treated as big-endian (Motorola/sawtooth indexing).

Current releases include corrected multi-byte big-endian bit mapping and stricter unsigned overflow checks.