udsonip.client
Enhanced UDS-on-IP client with simplified API.
- class udsonip.client.UdsOnIpClient(ecu_ip: str, ecu_address: int, client_ip: str | None = None, client_logical_address: int | None = None, activation_type: int = 0, protocol_version: int = 3, auto_reconnect: bool = False, keep_alive: bool = False, **kwargs)[source]
Bases:
objectUnified UDS-on-IP client providing simplified access to UDS services.
This client wraps both DoIPClient and UDS Client, providing a single interface for automotive diagnostics over DoIP with support for dynamic target address switching.
- Parameters:
ecu_ip – IP address of the DoIP gateway/ECU
ecu_address – Logical address of the target ECU
client_ip – Optional source IP address (auto-detected if None)
client_logical_address – Optional client logical address (required if not provided in kwargs)
activation_type – DoIP activation type (default: 0)
protocol_version – DoIP protocol version (default: 0x03)
auto_reconnect – Automatically reconnect on connection loss
keep_alive – Send keep-alive messages
**kwargs – Additional arguments passed to UDS Client
Example
>>> client = UdsOnIpClient('192.168.1.10', 0x00E0) >>> response = client.read_data_by_identifier(0xF190) >>> print(f"VIN: {response.data.decode()}") >>> client.close()
- change_session(session: int)[source]
Change diagnostic session (service UDS_SID_DIAGNOSTIC_SESSION_CONTROL).
- Parameters:
session – Session type (1=default, 2=programming, 3=extended)
- Returns:
Service response
- clear_dtc(group: int = 16777215)[source]
Clear diagnostic trouble codes (service UDS_SID_CLEAR_DIAGNOSTIC_INFORMATION).
- Parameters:
group – DTC group to clear (default: all DTCs)
- Returns:
Service response
- ecu_reset(reset_type: int = 1)[source]
Request ECU reset (service UDS_SID_ECU_RESET).
- Parameters:
reset_type – Reset type (1=hard reset, 2=key off/on, 3=soft reset)
- Returns:
Service response
- read_data_by_identifier(did: int | list)[source]
Read data by identifier (service UDS_SID_READ_DATA_BY_IDENTIFIER).
- Parameters:
did – Data identifier or list of identifiers
- Returns:
Service response with .data attribute
- read_dtc_information(dtc_status_mask: int = 255)[source]
Read DTC information (service UDS_SID_READ_DTC_INFORMATION).
- Parameters:
dtc_status_mask – DTC status mask
- Returns:
Service response with DTC information
- routine_control(routine_id: int, control_type: int = 1, data: bytes | None = None)[source]
Execute routine control (service UDS_SID_ROUTINE_CONTROL).
- Parameters:
routine_id – Routine identifier
control_type – Control type (1=start, 2=stop, 3=request results)
data – Optional routine data
- Returns:
Service response
- security_access(level: int, key: bytes | None = None)[source]
Request security access (service UDS_SID_SECURITY_ACCESS).
- Parameters:
level – Security level
key – Security key (None for seed request)
- Returns:
Service response
- property target_address: int
Get the current target ECU logical address.
- tester_present(suppress_response: bool = False)[source]
Send TesterPresent service request.
- Parameters:
suppress_response – If True, suppress positive response
- Returns:
Service response
- property uds: Client
Access the underlying UDS client for advanced operations.