Skip to main content

A general CAN framework API for Python - encode/decode CAN frames, parse DBC files, and work with CAN log files

Project description

canlab

A general CAN framework API for Python - encode/decode CAN frames, parse DBC files, and work with CAN log files.

Installation

pip install canlab

or

uv add canlab

Quick Start

Loading a DBC File

from dbc.dbc_loader import extract_messages

# Extract messages into MessageData objects
messages = extract_messages("path/to/file.dbc")

# Access message signals
for message in messages:
    print(f"Message ID: {message.dbc_id}")
    for signal in message.signals:
        print(f"  Signal: {signal.name}")

Encoding CAN Frames

from dbc.dbc_data import DbcData
from encoder.frame_encoder import values_to_lsb, values_to_msb

# Create a signal
signal = DbcData(
    value=98.6,
    startBit=0,
    numBits=16,
    scale=0.1,
    offset=0.0,
    isSigned=False,
    name="temperature",
    isLSB=True
)

# Encode to LSB (Intel) format
frame = values_to_lsb([signal])

# Encode to MSB (Motorola) format
msb_signal = DbcData(
    value=50.0,
    startBit=0,
    numBits=16,
    scale=0.1,
    offset=0.0,
    isSigned=False,
    name="speed",
    isLSB=False
)
frame = values_to_msb([msb_signal])

Decoding CAN Frames

from decoder.frame_decoder import lsb_to_value, msb_to_value

# Decode from LSB format
value = lsb_to_value(frame, signal)

# Decode from MSB (Motorola) format
value = msb_to_value(frame, signal)

# Or use MessageData.decode() for automatic decoding
decoded_values = message.decode(frame)
# Returns: {"signal_name": physical_value, ...}

Parsing ASC Log Files

from log_reader.asc import parseASC, read_asc

# Parse ASC file filtering by message IDs
target_ids = [0x100, 0x200]
df = parseASC("log.asc", target_ids)

# Read all messages from ASC file
df = read_asc("log.asc")

Features

  • Load and parse DBC files
  • Encode physical values to CAN frames (LSB and MSB formats)
  • Decode CAN frames to physical values
  • Parse ASC log files
  • Convert between DBC IDs and bus IDs

Requirements

  • Python >= 3.12
  • polars >= 1.36.1

License

MIT License - see LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

canlab-0.1.6.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

canlab-0.1.6-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file canlab-0.1.6.tar.gz.

File metadata

  • Download URL: canlab-0.1.6.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.4.27

File hashes

Hashes for canlab-0.1.6.tar.gz
Algorithm Hash digest
SHA256 73789782cdbf27a2e41e2f88a3a602c72fbc63560bef9838635707284a47d5f0
MD5 6c480507c78ef8fce97a7aaaf3e0de10
BLAKE2b-256 4547915c1f42aad0dbbde859e627d2f73e6ca669d704b0f6abdb66cb4b7f6cda

See more details on using hashes here.

File details

Details for the file canlab-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: canlab-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.4.27

File hashes

Hashes for canlab-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 6ff380c58afb33bf4118c45eadad22a4d48779d547968f63a222be62d32e490e
MD5 c668768092f601304a0fe16193b7c6e2
BLAKE2b-256 bd125b09bbb7827dea449393fdc6028a012f12c24587f6e3683fefd2f996f2cd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page