### Install python-udsoncan Source: https://github.com/pylessard/python-udsoncan/blob/master/README.rst Command to install the library using pip. ```bash pip install udsoncan ``` -------------------------------- ### Interact with UDS Server Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/index.md Example demonstrating interaction with a UDS server using the udsoncan library. Requires setup of IsoTPSocketConnection and Client with appropriate configuration. Handles potential exceptions like NegativeResponseException and InvalidResponseException. ```python import SomeLib.SomeCar.SomeModel as MyCar import udsoncan import isotp from udsoncan.connections import IsoTPSocketConnection from udsoncan.client import Client from udsoncan.exceptions import * from udsoncan.services import * udsoncan.setup_logging() conn = IsoTPSocketConnection('can0', isotp.Address(isotp.AddressingMode.Normal_11bits, rxid=0x123, txid=0x456)) with Client(conn, request_timeout=2, config=MyCar.config) as client: try: client.change_session(DiagnosticSessionControl.Session.extendedDiagnosticSession) # integer with value of 3 client.unlock_security_access(MyCar.debug_level) # Fictive security level. Integer coming from fictive lib, let's say its value is 5 client.write_data_by_identifier(udsoncan.DataIdentifier.VIN, 'ABC123456789') # Standard ID for VIN is 0xF190. Codec is set in the client configuration print('Vehicle Identification Number successfully changed.') client.ecu_reset(ECUReset.ResetType.hardReset) # HardReset = 0x01 except NegativeResponseException as e: print('Server refused our request for service %s with code "%s" (0x%02x)' % (e.response.service.get_name(), e.response.code_name, e.response.code)) except (InvalidResponseException, UnexpectedResponseException) as e: print('Server sent an invalid payload : %s' % e.response.original_payload) ``` -------------------------------- ### Using UDS over aioisotp with Virtual CAN Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/examples.md Demonstrates using SyncAioIsotpConnection with a virtual CAN interface. Ensure both python-can and aioisotp are installed. ```python from udsoncan.connections import SyncAioIsotpConnection from udsoncan.client import Client import logging logging.basicConfig(level=logging.DEBUG) conn = SyncAioIsotpConnection(interface="virtual", channel=0, bitrate=500000, rx_id=0x123, tx_id=0x456) with Client(conn) as client: with client.suppress_positive_response: client.change_session(3) # ... ``` -------------------------------- ### Start Routine using UDS Client Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/examples.md Employs the high-level `Client` interface to start a routine, abstracting away the underlying UDS service details. The client automatically validates echoed parameters. Error handling is done via exceptions. ```python try: response = client.start_routine(routine_id=0x1234) # control_type_echo and routine_id_echo are validated by the client. print('Success!') except Exception: print('Start of routine 0x1234 failed') ``` -------------------------------- ### Initialize UDS over python-can Connection Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/examples.md Sets up a UDS connection over ISO-TP using the `python-can` library and a fictive Vector interface. Requires `python-can` and `can-isotp` to be installed. ```python import can from can.interfaces.vector import VectorBus from udsoncan.connections import PythonIsoTpConnection from udsoncan.client import Client import udsoncan.configs import isotp ``` -------------------------------- ### Define Custom Security Algorithm in Client Configuration Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/examples.md Implement a custom security algorithm by defining a Python function and assigning it to 'security_algo' in the client configuration. The 'security_algo_params' can be used to pass necessary parameters to the algorithm. This example uses a simple XOR operation, which is not secure and is for demonstration purposes only. ```python def myalgo(level, seed, params): """ Builds the security key to unlock a security level. Returns the seed xor'ed with pre-shared key. """ output_key = bytearray(seed) xorkey = bytearray(params['xorkey']) for i in range(len(seed)): output_key[i] = seed[i] ^ xorkey[i%len(xorkey)] return bytes(output_key) client.config['security_algo'] = myalgo client.config['security_algo_params'] = dict(xorkey=b'\x12\x34\x56\x78') ``` -------------------------------- ### Perform UDS diagnostic operations Source: https://github.com/pylessard/python-udsoncan/blob/master/README.rst Example demonstrating how to connect to a CAN interface, change diagnostic sessions, unlock security access, write data, and reset an ECU. ```python import SomeLib.SomeCar.SomeModel as MyCar import udsoncan import isotp from udsoncan.connections import IsoTPSocketConnection from udsoncan.client import Client from udsoncan.exceptions import * from udsoncan.services import * udsoncan.setup_logging() conn = IsoTPSocketConnection('can0', isotp.Address(isotp.AddressingMode.Normal_11bits, rxid=0x123, txid=0x456)) with Client(conn, request_timeout=2, config=MyCar.config) as client: try: client.change_session(DiagnosticSessionControl.Session.extendedDiagnosticSession) # integer with value of 3 client.unlock_security_access(MyCar.debug_level) # Fictive security level. Integer coming from fictive lib, let's say its value is 5 client.write_data_by_identifier(udsoncan.DataIdentifier.VIN, 'ABC123456789') # Standard ID for VIN is 0xF190. Codec is set in the client configuration print('Vehicle Identification Number successfully changed.') client.ecu_reset(ECUReset.ResetType.hardReset) # HardReset = 0x01 except NegativeResponseException as e: print('Server refused our request for service %s with code "%s" (0x%02x)' % (e.response.service.get_name(), e.response.code_name, e.response.code)) except (InvalidResponseException, UnexpectedResponseException) as e: print('Server sent an invalid payload : %s' % e.response.original_payload) ``` -------------------------------- ### InputOutputControlByIdentifier Composite DID Configuration Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/examples.md Configure and use InputOutputControlByIdentifier with a composite Data Identifier (DID). This example defines a custom codec for a composite DID and demonstrates how to build the 'ioconfig' dictionary, including masks and mask sizes, which can be complex. ```python # Example taken from UDS standard class MyCompositeDidCodec(DidCodec): def encode(self, IAC_pintle, rpm, pedalA, pedalB, EGR_duty): pedal = (pedalA << 4) | pedalB return struct.pack('>BHBB', IAC_pintle, rpm, pedal, EGR_duty) def decode(self, payload): vals = struct.unpack('>BHBB', payload) return { 'IAC_pintle': vals[0], 'rpm' : vals[1], 'pedalA' : (vals[2] >> 4) & 0xF, 'pedalB' : vals[2] & 0xF, 'EGR_duty' : vals[3] } def __len__(self): return 5 ioconfig = { 0x132 : MyDidCodec, 0x456 : '> 4 # Do some stuff (reversed) def __len__(self): return 4 # encoded payload is 4 byte long. config = dict(udsoncan.configs.default_client_config) config['data_identifiers'] = { 'default' : '>H', # Default codec is a struct.pack/unpack string. 16bits little endian 0x1234 : MyCustomCodecThatShiftBy4, # Uses own custom defined codec. Giving the class is ok 0x1235 : MyCustomCodecThatShiftBy4(), # Same as 0x1234, giving an instance is good also 0xF190 : udsoncan.AsciiCodec(17) # Codec that read ASCII string. We must tell the length of the string } # IsoTPSocketconnection only works with SocketCAN under Linux. Use another connection if needed. conn = IsoTPSocketConnection('vcan0', rxid=0x123, txid=0x456) with Client(conn, request_timeout=2, config=config) as client: response = client.read_data_by_identifier([0xF190]) print(response.service_data.values[0xF190]) # This is a dict of DID:Value # Or, if a single DID is expected, a shortcut to read the value of the first DID vin = client.read_data_by_identifier_first(0xF190) print(vin) # 'ABCDEFG0123456789' (17 chars) ``` -------------------------------- ### Configure IsoTP and UDS Client Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/examples.md Sets up IsoTP parameters, a CAN bus, a notifier for debugging, and the UDS client connection. This configuration is for the network and transport layers (IsoTP protocol). ```python isotp_params = { 'stmin': 32, 'blocksize': 8, 'wftmax': 0, 'tx_data_length': 8, 'tx_data_min_length': None, 'tx_padding': 0, 'rx_flowcontrol_timeout': 1000, 'rx_consecutive_frame_timeout': 1000, 'override_receiver_stmin': None, 'max_frame_size': 4095, 'can_fd': False, 'bitrate_switch': False, 'rate_limit_enable': False, 'rate_limit_max_bitrate': 1000000, 'rate_limit_window_size': 0.2, 'listen_mode': False, } uds_config = udsoncan.configs.default_client_config.copy() bus = VectorBus(channel=0, bitrate=500000) notifier = can.Notifier(bus, [can.Printer()]) tp_addr = isotp.Address(isotp.AddressingMode.Normal_11bits, txid=0x123, rxid=0x456) stack = isotp.NotifierBasedCanStack(bus=bus, notifier=notifier, address=tp_addr, params=isotp_params) conn = PythonIsoTpConnection(stack) with Client(conn, config=uds_config) as client: client.change_session(1) # ... ``` -------------------------------- ### Configure ReadDataByIdentifier DID Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/services.md Define DID configurations using struct format strings, custom codec classes, or codec instances. ```python didconfig = { 0x1111 : ' ``` -------------------------------- ### SecuredDataTransmission (0x84) Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/services.md This service is for secured data transmission but is not implemented. ```APIDOC ## SecuredDataTransmission (0x84) ### Description Service for secured data transmission. ### WARNING Not implemented. ``` -------------------------------- ### Configure Server Memory Location Format Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/examples.md Sets the server address and memory size format for the UDS client configuration. Explicitly declared MemoryLocation objects will use these formats, otherwise default values are used. ```python client.config['server_address_format'] = 16 client.config['server_memorysize_format'] = 8 memloc1 = MemoryLocation(address=0x1234, memorysize=0x10, address_format=16, address_format=8) memloc2 = MemoryLocation(address=0x1234, memorysize=0x10) response = client.read_memory_by_address(memloc1) response = client.read_memory_by_address(memloc2) ``` -------------------------------- ### ReadScalingDataByIdentifier (0x24) Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/services.md This service is for reading scaling data by identifier but is not implemented. ```APIDOC ## ReadScalingDataByIdentifier (0x24) ### Description Service for reading scaling data by identifier. ### WARNING Not implemented. ``` -------------------------------- ### Create and Parse UDS Response Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/request_response.md Instantiate a Response object with service, code, and data, then convert it to a payload. Recreate a Response object from a payload. ```python response = Response(service=ECUReset, code=Response.Code.PositiveResponse, data=b'\x11\x22') payload = response.get_payload() print(payload) # b'\x51\x11\x22' response2 = Response.from_payload(payload) print(response2) # ``` -------------------------------- ### Tolerate Zero Padding Configuration Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/client.md Configuration to ignore trailing zeros in response data for services like ReadDataByIdentifier and ReadDTCInformation. ```APIDOC ## tolerate_zero_padding (bool) ### Description This value will be passed to the services ‘interpret_response’ when the parameter is supported as in [ReadDataByIdentifier](services.md#readdatabyidentifier), [ReadDTCInformation](services.md#readdtcinformation). It has to ignore trailing zeros in the response data to avoid falsely raising [InvalidResponseException](exceptions.md#invalidresponseexception) if the underlying protocol uses some zero-padding. ``` -------------------------------- ### make_request() Subfunction Parameters Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/services.md A reference table of parameters required for different DTC reporting subfunctions in the python-udsoncan library. ```APIDOC ## make_request() Subfunctions ### Description This endpoint defines the parameter requirements for various subfunctions used to retrieve Diagnostic Trouble Code (DTC) information. ### Parameters | Subfunction | status_mask | severity_mask | dtc | snapshot_record_number | extended_data_record_number | | :--- | :--- | :--- | :--- | :--- | :--- | | reportNumberOfDTCByStatusMask | Yes | - | - | - | - | | reportDTCByStatusMask | Yes | - | - | - | - | | reportDTCSnapshotRecordByDTCNumber | - | - | Yes | Yes | - | | reportDTCSnapshotRecordByRecordNumber | - | - | - | Yes | - | | reportDTCExtendedDataRecordByDTCNumber | - | - | Yes | - | Yes | | reportNumberOfDTCBySeverityMaskRecord | Yes | Yes | - | - | - | | reportDTCBySeverityMaskRecord | Yes | Yes | - | - | - | | reportSeverityInformationOfDTC | - | - | Yes | Yes | - | | reportMirrorMemoryDTCByStatusMask | Yes | - | - | - | - | | reportMirrorMemoryDTCExtendedDataRecordByDTCNumber | - | - | Yes | - | Yes | | reportNumberOfMirrorMemoryDTCByStatusMask | Yes | - | - | - | - | | reportNumberOfEmissionsRelatedOBDDTCByStatusMask | Yes | - | - | - | - | | reportEmissionsRelatedOBDDTCByStatusMask | Yes | - | - | - | - | ``` -------------------------------- ### AccessTimingParameter (0x83) Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/services.md Service for accessing timing parameters. ```APIDOC ## AccessTimingParameter (0x83) ### Description Service for accessing timing parameters. ### Method N/A (This is a service identifier, not an endpoint with specific methods to call directly in this context). ### Endpoint N/A ``` -------------------------------- ### Input/Output Data Identifiers Configuration Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/client.md Configuration for mapping IO data identifiers to DidCodec for the InputOutputControlByIdentifier service, supporting composite codecs. ```APIDOC ## input_output (dict) ### Description This configuration is a dictionary that is mapping an integer (the IO data identifier) with a [DidCodec](helper_classes.md#didcodec) specifically for the [InputOutputControlByIdentifier](services.md#inputoutputcontrolbyidentifier) service. Just like config[data_identifers], these codecs will be used to convert values to byte payload and vice-versa when sending/receiving data. Since [InputOutputControlByIdentifier](services.md#inputoutputcontrolbyidentifier) supports composite codecs, it is possible to provide a sub-dictionary as a codec specifying the bitmasks. ### Possible Configuration Values > - `string` : The string will be used as a pack/unpack string when processing the data > - `DidCodec` (class or instance) : The encode/decode method will be used to process the data > - `dict` : The dictionary entry indicates a composite DID. Three subkeys must be defined as: > > - `codec` : The codec, a string or a DidCodec class/instance > > - `mask` : A dictionary mapping the mask name with a bit > > - `mask_size` : An integer indicating on how many bytes must the mask be encoded > The special dictionnary key ‘default’ can be used to specify a fallback codec if an operation is done on a codec not part of the configuration. Useful for scanning a range of DID See [this example](examples.md#iocontrol-composite-did) to see how IO codecs are defined. ``` -------------------------------- ### WriteDataByIdentifier (0x2E) Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/services.md This service is used for writing data by identifier and does not have subfunctions. ```APIDOC ## WriteDataByIdentifier (0x2E) ### Description Used for writing data by identifier. ### Method POST ### Endpoint /pylessard/python-udsoncan/api/writedatabyidentifier ### Parameters This service does not have subfunctions or parameters. ``` -------------------------------- ### TransferData (0x36) Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/services.md This service is used for transferring data and does not have subfunctions. ```APIDOC ## TransferData (0x36) ### Description Used for transferring data. ### Method POST ### Endpoint /pylessard/python-udsoncan/api/transferdata ### Parameters This service does not have subfunctions or parameters. ``` -------------------------------- ### Define Dynamic DIDs Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/examples.md Configures dynamic DIDs using either source identifiers or memory addresses. Supports both single and composite definitions. ```python # Example 1) defineByIdentifier - single value my_def = DynamicDidDefinition(source_did = 0x1111, position=1, memorysize=2) client.dynamically_define_did(0x1234, my_def) # Example 2) defineByIdentifier - composite value my_def = DynamicDidDefinition(source_did = 0x1111, position=1, memorysize=2) my_def.add(source_did = 0x2222, position=5, memorysize=4) client.dynamically_define_did(0x1234, my_def) # Example 3) defineByMemoryAddress - single value my_memloc = MemoryLocation(address=0x1111, memorysize=2, address_format=16, memorysize_format=8) client.dynamically_define_did(0x1234, my_memloc) # Example 4) defineByMemoryAddress - composite value my_def = DynamicDidDefinition(MemoryLocation(address=0x1111, memorysize=2, address_format=16, memorysize_format=8)) my_def.add(MemoryLocation(address=0x2222, memorysize=4, address_format=16, memorysize_format=8)) my_def.add(MemoryLocation(address=0x3333, memorysize=1, address_format=16, memorysize_format=8)) client.dynamically_define_did(0x1234, my_def) # Example 5) defineByMemoryAddress - composite value and client default format client.set_config('server_address_format', 16) client.set_config('server_memorysize_format', 8) my_def = DynamicDidDefinition(MemoryLocation(address=0x1111, memorysize=2)) my_def.add(MemoryLocation(address=0x2222, memorysize=4)) my_def.add(MemoryLocation(address=0x3333, memorysize=1)) client.dynamically_define_did(0x1234, my_def) ``` -------------------------------- ### Send UDS Request using Services Abstraction Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/examples.md Utilizes the `services` abstraction to create a RoutineControl request and send it. Interprets the response using service-specific methods. This approach offers more structured handling of UDS services. ```python req = services.RoutineControl.make_request(control_type=services.RoutineControl.ControlType.startRoutine, routine_id=0x1234) my_connection.send(req.get_payload()) payload = my_connection.wait_frame(timeout=1) response = Response.from_payload(payload) services.ECUReset.interpret_response(response) if ( response.service == service.RoutineControl and response.code == Response.Code.PositiveResponse and response.service_data.control_type_echo == 1 and response.service_data.routine_id_echo == 0x1234): print('Success!') else: print('Start of routine 0x1234 failed') ``` -------------------------------- ### SecurityAccess (0x27) Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/services.md Details on the SecurityAccess service and its subfunction level logic. ```APIDOC ## SecurityAccess (0x27) ### Description Handles security access requests. The level acts as the subfunction (1 to 0x7E). The LSB indicates the request type: 1 for RequestSeed, 0 for SendKey. ### Parameters - **level** (int) - Required - Security level (1-0x7E). LSB 1 = RequestSeed, LSB 0 = SendKey. ``` -------------------------------- ### DiagnosticSessionControl (0x10) Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/services.md Service for controlling diagnostic sessions. ```APIDOC ## DiagnosticSessionControl (0x10) ### Description Manages the diagnostic session with the ECU, allowing transitions between different session types (e.g., default session, programming session). ### Method N/A (This is a service identifier, not an endpoint with specific methods to call directly in this context). ### Endpoint N/A ``` -------------------------------- ### DynamicallyDefineDataIdentifier (0x2C) Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/services.md This service is used for dynamically defining data identifiers. ```APIDOC ## DynamicallyDefineDataIdentifier (0x2C) ### Description Used for dynamically defining data identifiers. ### Method POST ### Endpoint /pylessard/python-udsoncan/api/dynamicallydefinedataidentifier ### Parameters This service does not have subfunctions or parameters. ``` -------------------------------- ### ReadDataByPeriodicIdentifier (0x2A) Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/services.md This service is for reading data by periodic identifier but is not implemented. ```APIDOC ## ReadDataByPeriodicIdentifier (0x2A) ### Description Service for reading data by periodic identifier. ### WARNING Not implemented. ``` -------------------------------- ### LinkControl (0x87) Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/services.md Service for controlling communication links. ```APIDOC ## LinkControl (0x87) ### Description Manages the communication link between the diagnostic tester and the ECU, potentially controlling power modes or other link-related functions. ### Method N/A (This is a service identifier, not an endpoint with specific methods to call directly in this context). ### Endpoint N/A ``` -------------------------------- ### CommunicationControl (0x28) Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/services.md Service for controlling communication behavior. ```APIDOC ## CommunicationControl (0x28) ### Description Controls the communication behavior of the ECU, such as enabling or disabling normal communication or network management. ### Method N/A (This is a service identifier, not an endpoint with specific methods to call directly in this context). ### Endpoint N/A ``` -------------------------------- ### Data Identifiers Configuration Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/client.md Configuration for mapping data identifiers to DidCodec for services like ReadDataByIdentifier, WriteDataByIdentifier, and ReadDTCInformation. ```APIDOC ## data_identifiers (dict) ### Description This configuration is a dictionary that is mapping an integer (the data identifier) with a [DidCodec](helper_classes.md#didcodec). These codecs will be used to convert values to byte payload and vice-versa when sending/receiving data for a service that needs a DID, i.e.: > - [ReadDataByIdentifier](services.md#readdatabyidentifier) > - [WriteDataByIdentifier](services.md#writedatabyidentifier) > - [ReadDTCInformation](services.md#readdtcinformation) with subfunction `reportDTCSnapshotRecordByDTCNumber` and `reportDTCSnapshotRecordByRecordNumber` ### Possible Configuration Values > - `string` : The string will be used as a pack/unpack string when processing the data > - `DidCodec` (class or instance) : The encode/decode method will be used to process the data > The special dictionnary key ‘default’ can be used to specify a fallback codec if an operation is done on a codec not part of the configuration. Useful for scanning a range of DID ``` -------------------------------- ### Send UDS Request using Request Object Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/examples.md Constructs a UDS request using the `Request` object for RoutineControl and sends its payload. Parses the response to verify success. Requires `Request` and `Response` classes. ```python req = Request(services.RoutineControl, control_type=1, routine_id=0x1234) # control_type=1 --> StartRoutine my_connection.send(req.get_payload()) payload = my_connection.wait_frame(timeout=1) response = Response.from_payload(payload) if response.service == service.RoutineControl and response.code == Response.Code.PositiveResponse and response.data == b'\x01\x12\x34': print('Success!') else: print('Start of routine 0x1234 failed') ``` -------------------------------- ### ReadDataByIdentifier (0x22) Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/services.md Service to read data identified by DID. ```APIDOC ## ReadDataByIdentifier (0x22) ### Description Reads data from the ECU identified by Data Identifiers (DIDs). ### Method N/A (This is a service identifier, not an endpoint with specific methods to call directly in this context). ### Endpoint N/A ### Notes - This service does not have subfunctions. ### DidConfig Example ```python didconfig = { 0x1111 : ' 1. `1234567800` (invalid) > 2. `123456780000` (invalid) > 3. `12345678000000` (invalid) > 4. `1234567800000000` (valid) > 5. `123456780000000000` (invalid) In this situation, all cases except case 4 would raise a [InvalidResponseException](exceptions.md#invalidresponseexception) because of their incorrect lengths (unless `config['tolerate_zero_padding']` is set to True). Case 4 would return 2 DTCs, the second DTC with an ID of 0x000000 and a status of 0x00. Setting `config['ignore_all_zero_dtc']` to True will make the functions return only the first valid DTC. ``` -------------------------------- ### Send Raw UDS Request Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/examples.md Sends a raw byte payload for a RoutineControl request and waits for a response. Useful for low-level control or when the library's abstractions are not yet in use. ```python my_connection.send(b'\x31\x01\x12\x34') # Sends RoutineControl, with ControlType=1, Routine ID=0x1234 payload = my_connection.wait_frame(timeout=1) if payload == b'\x71\x01\x12\x34': print('Success!') else: print('Start of routine 0x1234 failed') ``` -------------------------------- ### Suppress positive response Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/client.md Use the suppress_positive_response context manager to signal that no positive response is required. The wait_nrc parameter determines whether the client waits for potential negative responses. ```python with client.suppress_positive_response(wait_nrc=False): client.tester_present() # Will not wait for a response and always return None with client.suppress_positive_response(wait_nrc=True): client.tester_present() # Will wait in case an NRC is returned. ``` -------------------------------- ### Parse a UDS response Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/services.md Retrieve a response payload from a connection, instantiate a Response object, and interpret it using the service class. ```python payload = my_connection.wait_frame(timeout=1) response = Response.from_payload(payload) print('Raw data : %s' % response.data) SomeService.interpret_response(response, param1, param2) print('Interpreted data : field1 : %s, field2 : %s' % (response.service_data.field1, response.service_data.field2)) ``` -------------------------------- ### ClearDiagnosticInformation (0x14) Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/services.md Service to clear diagnostic trouble codes (DTCs). ```APIDOC ## ClearDiagnosticInformation (0x14) ### Description Clears diagnostic trouble codes (DTCs) from the ECU. ### Method N/A (This is a service identifier, not an endpoint with specific methods to call directly in this context). ### Endpoint N/A ### Notes - This service has an empty response data. - This service does not have subfunctions. ``` -------------------------------- ### Configure DTC Extended Data Sizes Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/client.md Specify the byte length of extended data for specific DTCs. This is used to correctly decode server responses when requesting DTC extended data. ```python config['extended_data_size'] = { 0x123456 : 45, # Extended data for DTC 0x123456 is 45 bytes long 0x123457 : 23 # Extended data for DTC 0x123457 is 23 bytes long } ``` -------------------------------- ### Update IsoTPSocketConnection Signature Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/questions_answers.md After updating to isotp v2 socket module, the signature of IsoTPSocketConnection changed. It is no longer possible to pass rxid and txid parameters directly. A full isotp.Address must be provided. ```python IsoTPSocketConnection('vcan0', rxid=123, txid=456) ``` ```python IsoTPSocketConnection('vcan0', isotp.Address(isotp.AddressingMode.Normal_11bits, rxid=123, txid=456)) ``` -------------------------------- ### interpret_response() subfunctions Source: https://github.com/pylessard/python-udsoncan/blob/master/doc/source/udsoncan/services.md Parameters for the interpret_response method categorized by DTC subfunction. ```APIDOC ## interpret_response() Parameters ### Description Defines the configuration parameters for interpreting responses based on the specific DTC subfunction used. ### Parameters - **subfunction** (string) - Required - The specific DTC subfunction being executed. - **extended_data_size** (bool) - Optional - Indicates if extended data size is applicable. - **tolerate_zero_padding** (bool) - Optional - Indicates if zero padding is tolerated. - **ignore_all_zero_dtc** (bool) - Optional - Indicates if all-zero DTCs should be ignored. - **dtc_snapshot_did_size** (bool) - Optional - Indicates if DTC snapshot DID size is applicable. - **didconfig** (bool) - Optional - Indicates if DID configuration is required. ```