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 import load_cantools_dbc, extract_messages

# Load DBC file with cantools
db = load_cantools_dbc("path/to/file.dbc")

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

Encoding CAN Frames

from dbc import DbcData
from encoder import values_to_lsb, values_to_msb

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

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

Decoding CAN Frames

from 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)

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
  • cantools >= 41.0.2
  • 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.4.tar.gz (15.1 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.4-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for canlab-0.1.4.tar.gz
Algorithm Hash digest
SHA256 9280045a3d1a6a01ef898debf89a0e78689f3164b59251f3971400f6a99e55d5
MD5 8db32b8c03a0cab84165e88d90541e58
BLAKE2b-256 bd0fde048411f99ab030e506a31582d4f02ed658cbbe10bcab84e36de647c35f

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for canlab-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 edd42d53f0bc2e67102755813ad60284b64e6b7667f975617f85393d35fcdaef
MD5 1c6175f5dcc9e1d4434080e09c879526
BLAKE2b-256 6c2a4f05cf2d4ac7fc403df84636e020625630743191ad3d7c9563fcc604b1a4

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