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.2.tar.gz (14.2 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.2-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for canlab-0.1.2.tar.gz
Algorithm Hash digest
SHA256 3ed5d58871548c9cfe3244e9b7db2ce1321b65c9f28ad2efc65407a64e75558a
MD5 ed481385b47929424bb9d8de03842477
BLAKE2b-256 7daae4e065b212b3ff77a0ea308f27a441cb90cc9976bfe09bc1193582e34eb3

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for canlab-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bde8c3877f1ed809030254b2e9824908b5f24ef3ee3aceeea5ae4d526933e203
MD5 20b27dd7a319abd06d4fbe616e14ce47
BLAKE2b-256 fa800317f3e12690ccc793902f0e0086d597f2d22934429348dba1ad159783a9

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