Python library for KWP2000 (Keyword Protocol 2000) communication over CAN bus using TP20 transport protocol and J2534 interface
Project description
KWP2000-CAN
A Python library for KWP2000 (Keyword Protocol 2000) communication over CAN bus using TP20 transport protocol and J2534 interface. This library provides a clean, high-level API for automotive ECU diagnostics, similar in design to udsoncan.
Features
- KWP2000 Protocol Support: Full implementation of KWP2000 diagnostic protocol
- TP20 Transport Layer: VW Transport Protocol 2.0 implementation for CAN bus communication
- J2534 Interface: Support for J2534 Pass-Thru devices (e.g., VAG-COM interfaces)
- Clean API: High-level client interface with context manager support
- Service Layer: Comprehensive implementation of KWP2000 services
- Start/Stop Communication
- Diagnostic Sessions
- Routine Control
- Data Reading/Writing
- ECU Reset
- Timing Parameter Access
Installation
pip install kwp2000-can
Quick Start
The easiest way to get started is using the convenience wrapper that handles the full communication chain:
from kwp2000.can import KWP2000_TP20_J2534
# Initialize and connect to ECU
with KWP2000_TP20_J2534() as client:
# Start extended diagnostic session
response = client.startDiagnosticSession(session_type=0x89)
print(f"Session started: {response}")
# Read data by local identifier
data = client.readDataByLocalIdentifier(local_identifier=0x01)
print(f"Data read: {data}")
# Start a routine
routine_result = client.start_routine(routine_id=0x1234)
print(f"Routine result: {routine_result}")
Advanced Usage
For more control, you can build the communication chain manually:
from j2534.can_connection import J2534CanConnection
from tp20.transport import TP20Transport
from kwp2000.client import KWP2000Client
# Create CAN connection
can_conn = J2534CanConnection(
dll_path=None, # Auto-detect J2534 DLL
baudrate=500000
)
# Create TP20 transport
tp20 = TP20Transport(
can_connection=can_conn,
dest=0x01, # ECU logical address
rx_id=0x300, # RX CAN ID
tx_id=0x740 # TX CAN ID
)
# Create KWP2000 client
client = KWP2000Client(tp20)
# Use context managers
with tp20:
with client:
response = client.startDiagnosticSession(session_type=0x89)
print(response)
Protocol Support
KWP2000 Services
| Service | ID | Status |
|---|---|---|
| Start Communication | 0x81 | ✅ |
| Stop Communication | 0x82 | ✅ |
| Start Diagnostic Session | 0x10 | ✅ |
| Stop Diagnostic Session | 0x20 | ✅ |
| ECU Reset | 0x11 | ✅ |
| Read Data By Local Identifier | 0x21 | ✅ |
| Read Data By Identifier | 0x22 | ✅ |
| Write Data By Local Identifier | 0x3B | ✅ |
| Routine Control | 0x31 | ✅ |
| Request Routine Results | 0x33 | ✅ |
| Access Timing Parameter | 0x83 | ✅ |
| Send Data | 0x36 | ✅ |
Transport Protocols
- TP20: VW Transport Protocol 2.0 over CAN ✅
- J2534: Pass-Thru interface support ✅
Examples
See the example/ directory for complete usage examples:
kwp2000_tp20_j2534.py: Convenience wrapper example
Testing
Run the test suite:
python -m pytest test/
Requirements
- Python 3.7+
python-can>=4.0.0- J2534-compatible hardware interface (for hardware testing)
Project Structure
KWP2000-CAN/
├── kwp2000/ # KWP2000 protocol implementation
│ ├── client.py # High-level client API
│ ├── services.py # Service implementations
│ ├── transport.py # Transport interface
│ └── ...
├── tp20/ # TP20 transport protocol
│ ├── transport.py # TP20 implementation
│ └── ...
├── j2534/ # J2534 interface
│ ├── can_connection.py
│ └── ...
└── example/ # Usage examples
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kwp2000_can-0.1.0.tar.gz.
File metadata
- Download URL: kwp2000_can-0.1.0.tar.gz
- Upload date:
- Size: 30.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ceb5b50f50864246418c057ad66bfbde392d023a23bdf07b4839fa71f900cb8
|
|
| MD5 |
e3ca9bb948eabe4f8062f4f3f207b3a2
|
|
| BLAKE2b-256 |
49686a5f857bc3c01cc86c803adfeabbda4caf266d97f9595fc41a82c4267c58
|
Provenance
The following attestation bundles were made for kwp2000_can-0.1.0.tar.gz:
Publisher:
workflow.yml on EliasTuning/KWP2000-CAN
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kwp2000_can-0.1.0.tar.gz -
Subject digest:
9ceb5b50f50864246418c057ad66bfbde392d023a23bdf07b4839fa71f900cb8 - Sigstore transparency entry: 744654991
- Sigstore integration time:
-
Permalink:
EliasTuning/KWP2000-CAN@2ce83a2470450eefb2db88e5d827ace32f63e54f -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/EliasTuning
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@2ce83a2470450eefb2db88e5d827ace32f63e54f -
Trigger Event:
push
-
Statement type:
File details
Details for the file kwp2000_can-0.1.0-py3-none-any.whl.
File metadata
- Download URL: kwp2000_can-0.1.0-py3-none-any.whl
- Upload date:
- Size: 36.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d9f0cded82531c509c78b63c84df5efb4b317aacc5bc650d7cca2aacb87f248
|
|
| MD5 |
8c4f41720b9866f32c194c403fa2db89
|
|
| BLAKE2b-256 |
e2fd9b453b02ea4235a6e589d9c0cffc8dd55c8f97fa9dcbd38de401412f1ac7
|
Provenance
The following attestation bundles were made for kwp2000_can-0.1.0-py3-none-any.whl:
Publisher:
workflow.yml on EliasTuning/KWP2000-CAN
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kwp2000_can-0.1.0-py3-none-any.whl -
Subject digest:
0d9f0cded82531c509c78b63c84df5efb4b317aacc5bc650d7cca2aacb87f248 - Sigstore transparency entry: 744655001
- Sigstore integration time:
-
Permalink:
EliasTuning/KWP2000-CAN@2ce83a2470450eefb2db88e5d827ace32f63e54f -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/EliasTuning
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@2ce83a2470450eefb2db88e5d827ace32f63e54f -
Trigger Event:
push
-
Statement type: