| Component | Options |
|---|---|
| Hardware | Peak PCAN-USB or Vector CANalyzer; or SocketCAN on Linux (vcan0 for simulation) |
| Software | Python-UDS library (pip install python-uds); or CANoe with CAPL; or ETAS INCA |
| ECU simulator | udsoncan library with simulated ECU (pip install udsoncan); or AUTOSAR RTA-BSW demo |
| Connection | OBD-II connector → CAN interface; physical (0x726/0x72E) or functional (0x7DF) addressing |
Lab Setup
Exercise 1: Open Session and Read VIN
#!/usr/bin/env python3
# UDS Lab 01: Enter Extended Session + Read VIN (DID 0xF190)
import udsoncan
from udsoncan.connections import PythonIsoTpConnection
from udsoncan.client import Client
import isotp, can
# Setup: CAN interface (change 'vcan0' to your interface)
bus = can.Bus('vcan0', bustype='socketcan')
tp_addr = isotp.Address(isotp.AddressingMode.Normal_11bits,
rxid=0x7E8, txid=0x726)
stack = isotp.CanStack(bus=bus, address=tp_addr)
conn = PythonIsoTpConnection(stack)
config = dict(udsoncan.configs.default_client_config)
config['request_timeout'] = 2 # seconds
with Client(conn, config=config) as client:
# 1. Enter Extended Diagnostic Session
resp = client.change_session(udsoncan.services.DiagnosticSessionControl.Session.extendedDiagnosticSession)
print(f"Session: {'OK' if resp.positive else 'FAILED'}")
# 2. Read VIN (DID 0xF190)
resp = client.read_data_by_identifier(0xF190)
if resp.positive:
vin_bytes = resp.service_data.values[0xF190]
print(f"VIN: {vin_bytes.decode('ascii', errors='replace')}")
else:
print(f"ReadDID failed: NRC 0x{resp.code:02X}")
# 3. Read ECU Software Version (DID 0xF189)
resp = client.read_data_by_identifier(0xF189)
if resp.positive:
sw_ver = resp.service_data.values[0xF189]
print(f"SW Version: {sw_ver.hex()}")Exercise 2: Decode a Multi-Frame Response Manually
#!/usr/bin/env python3
# Manually decode ISO 15765-2 multi-frame CAN trace
# Scenario: captured from CAN bus; DID 0xF190 VIN read
frames = [
# Raw CAN frame bytes (8 bytes each)
bytes.fromhex("101462F190574241"), # FF: total=20, SID=0x62, DID=F190, data starts
bytes.fromhex("3000000000000000"), # FC from tester: BS=0, STmin=0
bytes.fromhex("213132333435363738"),# CF seq=1
bytes.fromhex("223930313233340000"),# CF seq=2 (last; 2 padding bytes)
]
def decode_cantp(frames):
ff = frames[0]
total_len = ((ff[0] & 0x0F) << 8) | ff[1]
print(f"FF: total length = {total_len} bytes")
payload = bytearray(ff[2:]) # 6 bytes from FF
seq_expected = 1
for f in frames[2:]: # skip FC
if (f[0] & 0xF0) == 0x20: # CF
seq = f[0] & 0x0F
assert seq == seq_expected % 16, f"Sequence error: got {seq} expected {seq_expected}"
payload.extend(f[1:])
seq_expected += 1
payload = bytes(payload[:total_len])
print(f"Reassembled UDS payload ({len(payload)} bytes): {payload.hex()}")
# Decode UDS response
sid = payload[0]
if sid == 0x62: # positive response to 0x22
did = (payload[1] << 8) | payload[2]
data = payload[3:]
print(f"ReadDataByIdentifier response: DID=0x{did:04X}")
print(f"Data: {data.hex()} = {data.decode('ascii', errors='replace')}")
decode_cantp(frames)Exercise 3: Trigger and Clear a DTC
#!/usr/bin/env python3
# Trigger a DTC, read it, then clear it
import udsoncan
from udsoncan.connections import PythonIsoTpConnection
from udsoncan.client import Client
import isotp, can
bus = can.Bus('vcan0', bustype='socketcan')
tp_addr = isotp.Address(isotp.AddressingMode.Normal_11bits, rxid=0x7E8, txid=0x726)
conn = PythonIsoTpConnection(isotp.CanStack(bus=bus, address=tp_addr))
with Client(conn, config=dict(udsoncan.configs.default_client_config)) as client:
# Enter Extended Session
client.change_session(udsoncan.services.DiagnosticSessionControl.Session.extendedDiagnosticSession)
# Read all active DTCs (0x19 0x02 0xFF: all DTCs, any status)
resp = client.get_dtc_by_status_mask(0xFF)
if resp.positive:
print(f"Active DTCs: {len(resp.service_data.dtcs)}")
for dtc in resp.service_data.dtcs:
print(f" DTC: P{dtc.id:04X} Status: 0x{dtc.status.byte:02X}")
else:
print("ReadDTC failed")
# Clear all DTCs (0x14 0xFFFFFF)
resp = client.clear_dtc(0xFFFFFF) # group=0xFFFFFF = all DTCs
print(f"ClearDTC: {'OK' if resp.positive else 'FAILED NRC 0x' + format(resp.code, '02X')}")
# Re-read to confirm cleared
resp = client.get_dtc_by_status_mask(0xFF)
remaining = len(resp.service_data.dtcs) if resp.positive else -1
print(f"DTCs after clear: {remaining} (expected: 0)")Summary
Three exercises map to three fundamental diagnostic workflows: session management + data reading, transport-layer decoding (essential for understanding bus traces and CDD validation), and DTC management. The python-uds library abstracts the ISO 15765-2 segmentation, but understanding the raw frames (Exercise 2) is essential for diagnosing failures that appear at the transport layer — wrong sequence numbers, missing Flow Control, or incorrect total length fields are common integration bugs that require frame-level analysis.
🔬 Deep Dive — Core Concepts Expanded
This section builds on the foundational concepts covered above with additional technical depth, edge cases, and configuration nuances that separate competent engineers from experts. When working on production ECU projects, the details covered here are the ones most commonly responsible for integration delays and late-phase defects.
Key principles to reinforce:
- Configuration over coding: In AUTOSAR and automotive middleware environments, correctness is largely determined by ARXML configuration, not application code. A correctly implemented algorithm can produce wrong results due to a single misconfigured parameter.
- Traceability as a first-class concern: Every configuration decision should be traceable to a requirement, safety goal, or architecture decision. Undocumented configuration choices are a common source of regression defects when ECUs are updated.
- Cross-module dependencies: In tightly integrated automotive software stacks, changing one module's configuration often requires corresponding updates in dependent modules. Always perform a dependency impact analysis before submitting configuration changes.
🏭 How This Topic Appears in Production Projects
- Project integration phase: The concepts covered in this lesson are most commonly encountered during ECU integration testing — when multiple software components from different teams are combined for the first time. Issues that were invisible in unit tests frequently surface at this stage.
- Supplier/OEM interface: This is a topic that frequently appears in technical discussions between Tier-1 ECU suppliers and OEM system integrators. Engineers who can speak fluently about these details earn credibility and are often brought into critical design review meetings.
- Automotive tool ecosystem: Vector CANoe/CANalyzer, dSPACE tools, and ETAS INCA are the standard tools used to validate and measure the correct behaviour of the systems described in this lesson. Familiarity with these tools alongside the conceptual knowledge dramatically accelerates debugging in real projects.
⚠️ Common Mistakes and How to Avoid Them
- Assuming default configuration is correct: Automotive software tools ship with default configurations that are designed to compile and link, not to meet project-specific requirements. Every configuration parameter needs to be consciously set. 'It compiled' is not the same as 'it is correctly configured'.
- Skipping documentation of configuration rationale: In a 3-year ECU project with team turnover, undocumented configuration choices become tribal knowledge that disappears when engineers leave. Document why a parameter is set to a specific value, not just what it is set to.
- Testing only the happy path: Automotive ECUs must behave correctly under fault conditions, voltage variations, and communication errors. Always test the error handling paths as rigorously as the nominal operation. Many production escapes originate in untested error branches.
- Version mismatches between teams: In a multi-team project, the BSW team, SWC team, and system integration team may use different versions of the same ARXML file. Version management of all ARXML files in a shared repository is mandatory, not optional.
📊 Industry Note
Engineers who master both the theoretical concepts and the practical toolchain skills covered in this course are among the most sought-after professionals in the automotive software industry. The combination of AUTOSAR standards knowledge, safety engineering understanding, and hands-on configuration experience commands premium salaries at OEMs and Tier-1 suppliers globally.