### start_tester_present Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/user_guide/quickstart.rst Starts periodically sending TesterPresent messages to maintain the diagnostic session. This method is used to keep the session active. ```APIDOC ## start_tester_present ### Description Starts periodically sending TesterPresent messages to maintain the diagnostic session. This method is used to keep the session active. ### Method start_tester_present ### Request Example ```python import uds # let's assume Client object is created client: uds.client.Client # start sending TesterPresent messages periodically client.start_tester_present() ``` ``` -------------------------------- ### Configure UDS Client Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/user_guide/quickstart.rst Create a Client instance to simulate a diagnostic tester. Requires an existing Transport Interface object. ```python import uds # let's assume Transport Interface object is created transport_interface: uds.transport_interface.AbstractTransportInterface # define a client client = uds.client.Client(transport_interface=transport_interface) ``` -------------------------------- ### start_receiving Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/user_guide/quickstart.rst Starts a background task to collect all response messages sent to the client when no request message was sent. This is useful for services like ResponseOnEvent or ReadDataByPeriodicIdentifier. ```APIDOC ## start_receiving ### Description Starts a background task to collect all response messages sent to the client when no request message was sent. This is useful for services like ResponseOnEvent or ReadDataByPeriodicIdentifier. ### Method start_receiving ### Request Example ```python import uds # let's assume Client object is created client: uds.client.Client # start collecting all response messages sent to client client.start_receiving() ``` ``` -------------------------------- ### Start and stop background receiving of responses Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/examples/client.rst Clears the response queue, starts background receiving, then attempts to get a response immediately with get_response_no_wait() and waits up to 1000 ms with get_response(timeout=1000). Prints whether a response was received or not in each case. ```python """Start and stop receiving response messages in the background.""" from uds.client import Client from uds.transport_interface import AbstractTransportInterface def main(): # configure your own Transport Interface # https://uds.readthedocs.io/en/stable/pages/user_guide/quickstart.html#create-transport-interface transport_interface: AbstractTransportInterface = ... # TODO: provide your implementation here # configure the client # https://uds.readthedocs.io/en/stable/pages/user_guide/client.html#configuration client = Client(transport_interface=transport_interface) # clear queue with response messages client.clear_response_queue() # start collecting all response messages sent to the client client.start_background_receiving() # try to get a response immediately response_message_record = client.get_response_no_wait() if response_message_record is None: print("No response received so far.") else: print("Received response:", response_message_record) # wait for a response message response_message_record = client.get_response(timeout=1000) # wait up to 1000 ms for a response if response_message_record is None: print("No response received within timeout.") else: print("Received response:", response_message_record) ``` -------------------------------- ### Install build tools for PyPI upload Source: https://github.com/mdabrowski1990/uds/wiki/Deployment Run these commands to install setuptools, wheel, and build before creating the package wheel. ```bash python -m pip install -U setuptools ``` ```bash python -m pip install -U wheel ``` ```bash python -m pip install -U build ``` -------------------------------- ### Periodic Tester Present Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/user_guide/quickstart.rst Starts and stops periodic sending of TesterPresent messages to maintain the diagnostic session. ```python import uds # let's assume Client object is created client: uds.client.Client # start sending TesterPresent messages periodically client.start_tester_present() # stop sending TesterPresent messages periodically client.stop_tester_present() ``` -------------------------------- ### Install development version from GitHub Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/installation.rst Installs the latest code from the main branch of the GitHub repository. The development version may be unstable; use at your own risk. ```shell pip install git+https://github.com/mdabrowski1990/uds.git@main ``` -------------------------------- ### Client.start_background_receiving Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/user_guide/client.rst Turns Background Receiving on and starts collecting response. ```APIDOC ## Client.start_background_receiving ### Description Turns Background Receiving on and starts collecting response. ``` -------------------------------- ### Setup logger to Transport Interface instance Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/examples/transport.rst Configure and activate TransportLogger for a Transport Interface instance. Requires a pre-configured transport_interface and a Python logger named 'UDS'. The logger decorates the instance, enabling message and packet logging for sending and receiving. ```python """Configure logger for instance of Transport Interface.""" import logging from uds.transport_interface import AbstractTransportInterface, TransportLogger # configure your own Transport Interface # https://uds.readthedocs.io/en/stable/pages/user_guide/quickstart.html#create-transport-interface transport_interface: AbstractTransportInterface = ... # TODO: provide your implementation here # configure your logging # https://docs.python.org/3/library/logging.html logger = logging.getLogger("UDS") # example logger name logger.setLevel(logging.DEBUG) # example logging level # optionally configure logging to file file_handler = logging.FileHandler(filename="uds.log", encoding="utf-8") file_handler.setLevel(logging.DEBUG) logger.addHandler(file_handler) # optionally configure logging to python console stream_handler = logging.StreamHandler() stream_handler.setLevel(logging.INFO) logger.addHandler(stream_handler) # configure your logger # https://uds.readthedocs.io/en/stable/pages/user_guide/logging.html#configuration transport_logger = TransportLogger( logger_name="UDS", # the same name as previously configured logger message_logging_level=logging.INFO, packet_logging_level=logging.DEBUG, log_sending=True, log_receiving=True, ) # activate your logger # https://uds.readthedocs.io/en/stable/pages/user_guide/logging.html#decorating-transport-interface-instance transport_interface_with_logger = transport_logger(transport_interface) # TODO: use `transport_interface_with_logger` the same way as `transport_interface` ``` -------------------------------- ### Client.start_tester_present Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/user_guide/client.rst Starts sending Tester Present messages periodically. ```APIDOC ## Client.start_tester_present ### Description Starts sending Tester Present messages periodically. ``` -------------------------------- ### Build wheel and install twine Source: https://github.com/mdabrowski1990/uds/wiki/Deployment Build the wheel distribution and upgrade twine for uploading to PyPI. ```bash python -m build --wheel ``` ```bash python -m pip install --upgrade twine ``` -------------------------------- ### Full UDS over CAN FD example with two interfaces Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/examples/CAN/python-can.rst Complete example showing how to set up two CAN interfaces, configure addressing information, create transport interfaces, send and receive a UDS message, and clean up. Uses CAN FD with a data bitrate of 4,000,000 and a 10 ms timer delay. The receive timeout is 1000 ms. ```python def main(): # configure CAN interface - https://python-can.readthedocs.io/en/stable/interfaces.html can_interface_1 = Bus( # provide configuration for your CAN interface interface="kvaser", channel=0, receive_own_messages=True, # recommended # configure your CAN bus bitrate=500_000, fd=True, data_bitrate=4_000_000, ) # configure CAN interface - https://python-can.readthedocs.io/en/stable/interfaces.html can_interface_2 = Bus( # provide configuration for your CAN interface interface="kvaser", channel=1, receive_own_messages=True, # recommended # configure your CAN bus bitrate=500_000, fd=True, data_bitrate=4_000_000, ) # configure addresses for Diagnostics on CAN communication # CAN Addressing Formats explanation: # https://uds.readthedocs.io/en/stable/pages/knowledge_base/packet.html#can-packet-addressing-formats ai_send = CanAddressingInformation( addressing_format=CanAddressingFormat.NORMAL_ADDRESSING, tx_physical_params={"can_id": 0x611}, rx_physical_params={"can_id": 0x612}, tx_functional_params={"can_id": 0x6FF}, rx_functional_params={"can_id": 0x6FE}, ) ai_receive = ai_send.get_other_end() # create Transport Interface object for Diagnostics on CAN communication can_ti_1 = PythonCanTransportInterface( network_manager=can_interface_1, addressing_information=ai_send, can_version=CanVersion.CAN_FD ) # send all diagnostic packets as CAN FD frames can_ti_2 = PythonCanTransportInterface(network_manager=can_interface_2, addressing_information=ai_receive) # define UDS Message to send message = UdsMessage(addressing_type=AddressingType.PHYSICAL, payload=[0x62, 0x10, 0x00, *range(100)]) # prepare code for scheduling transmission sent_message_record = None def _send_message(): nonlocal sent_message_record sent_message_record = can_ti_1.send_message(message) timer = Timer( interval=0.01, # delay after which message will be sent, now 0.01 [s] function=_send_message, ) # send and receive message timer.start() received_message_record = can_ti_2.receive_message(start_timeout=1000) # timeout=1000 [ms] # wait till message is received while not timer.finished.is_set(): sleep(0.01) # show results print(sent_message_record) print(received_message_record) # close connections with CAN interfaces can_ti_1.teardown_sync(suppress_warning=True) can_ti_2.teardown_sync(suppress_warning=True) can_interface_1.shutdown() can_interface_2.shutdown() if __name__ == "__main__": main() ``` -------------------------------- ### Install py-uds from PyPI Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/installation.rst Installs the latest released version of the UDS package from PyPI. Recommended for stable, fully tested versions. ```shell pip install py-uds ``` -------------------------------- ### Create PythonCanTransportInterface with python-can Bus Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/user_guide/quickstart.rst Set up a python-can Bus and create a PythonCanTransportInterface for CAN communication. Requires an existing Addressing Information object. ```python from can import Bus import uds # let's assume Addressing Information object is created can_ai: uds.can.addressing.NormalCanAddressingInformation # configure Bus object (python-can) for CAN communication can_bus = Bus( interface="kvaser", channel=0, receive_own_messages=True, bitrate=500_000, fd=True, data_bitrate=4_000_000) # create Transport Interface object transport_interface = uds.can.PythonCanTransportInterface( network_manager=can_bus, addressing_information=can_ai) ``` -------------------------------- ### Send request and collect all responses Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/examples/client.rst Configures a Client with a custom transport interface, sends a single UdsMessage with payload [0x14, 0xFF, 0xFF, 0xFF] and PHYSICAL addressing, then prints the sent request and all collected responses. The transport interface must be provided by the user; see the linked quickstart guide. ```python """Send a request and collect all responses.""" from uds.addressing import AddressingType from uds.client import Client from uds.message import UdsMessage from uds.transport_interface import AbstractTransportInterface def main(): # configure your own Transport Interface # https://uds.readthedocs.io/en/stable/pages/user_guide/quickstart.html#create-transport-interface transport_interface: AbstractTransportInterface = ... # TODO: provide your implementation here # configure client # https://uds.readthedocs.io/en/stable/pages/user_guide/client.html#configuration client = Client(transport_interface=transport_interface) # define an example request message request = UdsMessage(payload=[0x14, 0xFF, 0xFF, 0xFF], addressing_type=AddressingType.PHYSICAL) # send the request and collect all responses request_record, responses_records = client.send_request_receive_responses(request) # present sent message print(f"Sent request: {request_record}") # present received messages if responses_records: for i, response_record in enumerate(responses_records, start=1): print(f"Response #{i}: {response_record}") else: print("No response message received.") if __name__ == "__main__": main() ``` -------------------------------- ### Send and Receive UDS Messages Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/user_guide/quickstart.rst Exchange complete diagnostic messages using the Transport Interface. The example sends a physical addressing message and receives with a 1000 ms timeout. ```python # let's assume Transport Interface object is created transport_interface: uds.transport_interface.AbstractTransportInterface # define example message to send uds_message = uds.message.UdsMessage(payload=[0x10, 0x03], addressing_type=uds.addressing.AddressingType.PHYSICAL) # send a message sent_message_record = transport_interface.send_message(uds_message) # receive a message received_message_record = transport_interface.receive_message(timeout=1000) # ms ``` -------------------------------- ### Start and stop periodic Tester Present sending Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/examples/client.rst Configures a Client with s3_client=1000 to set a 1000ms period for Tester Present messages, adjusts tester_present_storage_size to 10, then starts periodic sending with PHYSICAL addressing and sprmib=False (disabling Suppress Positive Response Message Indication Bit). After performing actions, stops sending and prints the stored request records via last_sent_tester_present_requests. ```python """Start and stop periodic Tester Present sending.""" from uds.addressing import AddressingType from uds.client import Client from uds.transport_interface import AbstractTransportInterface def main(): # configure your own Transport Interface # https://uds.readthedocs.io/en/stable/pages/user_guide/quickstart.html#create-transport-interface transport_interface: AbstractTransportInterface = ... # TODO: provide your implementation here # configure the client # https://uds.readthedocs.io/en/stable/pages/user_guide/client.html#configuration client = Client( transport_interface=transport_interface, s3_client=1000 ) # set 1000ms as period for Tester Present sending client.tester_present_storage_size = 10 # adjust number of records stored if needed # start periodic Tester Present sending client.start_tester_present( addressing_type=AddressingType.PHYSICAL, # addressing type to use sprmib=False, ) # disable Suppress Positive Response Message Indication Bit # TODO: perform some action with tester present cyclically sent # stop periodic Tester Present sending client.stop_tester_present() # access records of Tester Present request messages print(client.last_sent_tester_present_requests) if __name__ == "__main__": main() ``` -------------------------------- ### Full UDS CAN FD communication example Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/examples/CAN/python-can.rst Complete example for sending and receiving UDS messages over CAN FD using two Vector interfaces. Configures two CAN buses, sets up addressing information, creates transport interfaces, schedules a message transmission with a timer, and prints the sent and received message records. Requires python-can and the uds library. ```python def main(): # configure CAN interface - https://python-can.readthedocs.io/en/stable/interfaces.html can_interface_1 = Bus( # provide configuration for your CAN interface interface="vector", app_name="python-can", # name of the Application in Vector Hardware Config channel=0, receive_own_messages=True, # recommended # configure your CAN bus bitrate=500_000, fd=True, data_bitrate=4_000_000, ) # configure CAN interface - https://python-can.readthedocs.io/en/stable/interfaces.html can_interface_2 = Bus( # provide configuration for your CAN interface interface="vector", app_name="python-can", # name of the Application in Vector Hardware Config channel=1, receive_own_messages=True, # recommended # configure your CAN bus bitrate=500_000, fd=True, data_bitrate=4_000_000, ) # configure addresses for Diagnostics on CAN communication # CAN Addressing Formats explanation: # https://uds.readthedocs.io/en/stable/pages/knowledge_base/packet.html#can-packet-addressing-formats ai_send = CanAddressingInformation( addressing_format=CanAddressingFormat.NORMAL_ADDRESSING, tx_physical_params={"can_id": 0x611}, rx_physical_params={"can_id": 0x612}, tx_functional_params={"can_id": 0x6FF}, rx_functional_params={"can_id": 0x6FE}, ) ai_receive = ai_send.get_other_end() # create Transport Interface object for Diagnostics on CAN communication can_ti_1 = PythonCanTransportInterface( network_manager=can_interface_1, addressing_information=ai_send, can_version=CanVersion.CAN_FD ) # send all diagnostic packets as CAN FD frames can_ti_2 = PythonCanTransportInterface(network_manager=can_interface_2, addressing_information=ai_receive) # define UDS Message to send message = UdsMessage(addressing_type=AddressingType.PHYSICAL, payload=[0x62, 0x10, 0x00, *range(100)]) # prepare code for scheduling transmission sent_message_record = None def _send_message(): nonlocal sent_message_record sent_message_record = can_ti_1.send_message(message) timer = Timer( interval=0.01, # delay after which message will be sent, now 0.01 [s] function=_send_message, ) # send and receive message timer.start() received_message_record = can_ti_2.receive_message(start_timeout=1000) # timeout=1000 [ms] # wait till message is received while not timer.finished.is_set(): sleep(0.01) # show results print(sent_message_record) print(received_message_record) # close connections with CAN interfaces can_ti_1.teardown_sync(suppress_warning=True) can_ti_2.teardown_sync(suppress_warning=True) can_interface_1.shutdown() can_interface_2.shutdown() if __name__ == "__main__": main() ``` -------------------------------- ### Create CAN Addressing Information examples for different addressing formats Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/user_guide/can.rst Creates three CanAddressingInformation instances for NORMAL_ADDRESSING, EXTENDED_ADDRESSING, and MIXED_29BIT_ADDRESSING. Each instance specifies rx/tx physical and functional parameters with can_id and optional target_address or address_extension. ```python # create examples storages for CAN Addressing Information ecu_ai = uds.can.addressing.CanAddressingInformation( addressing_format=uds.can.CanAddressingFormat.NORMAL_ADDRESSING, rx_physical_params={"can_id": 0x7E8}, tx_physical_params={"can_id": 0x7E0}, rx_functional_params={"can_id": 0x7E8}, tx_functional_params={"can_id": 0x7DF}) ecu_ai_2 = uds.can.CanAddressingInformation( addressing_format=uds.can.CanAddressingFormat.EXTENDED_ADDRESSING, rx_physical_params={"can_id": 0x701, "target_address": 0x01}, tx_physical_params={"can_id": 0x702, "target_address": 0xF1}, rx_functional_params={"can_id": 0x701, "target_address": 0xFF}, tx_functional_params={"can_id": 0x702, "target_address": 0xF1}) ecu_ai_3 = uds.can.CanAddressingInformation( addressing_format=uds.can.CanAddressingFormat.MIXED_29BIT_ADDRESSING, rx_physical_params={"can_id": 0x18CEF101, "address_extension": 0x2D}, tx_physical_params={"can_id": 0x18CE01F1, "address_extension": 0x2D}, rx_functional_params={"can_id": 0x18CDF101, "address_extension": 0x8C}, tx_functional_params={"can_id": 0x18CD33F1, "address_extension": 0x8C}) ``` -------------------------------- ### Setup logger to Transport Interface class Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/examples/transport.rst Configure and activate TransportLogger as a class decorator for a Transport Interface class. Requires a Python logger named 'UDS'. The decorated class must implement AbstractTransportInterface. ```python """Configure logger for class of Transport Interface.""" import logging from uds.transport_interface import AbstractTransportInterface, TransportLogger # configure your logging # https://docs.python.org/3/library/logging.html logger = logging.getLogger("UDS") # example logger name logger.setLevel(logging.DEBUG) # example logging level # optionally configure logging to file file_handler = logging.FileHandler(filename="uds.log", encoding="utf-8") file_handler.setLevel(logging.DEBUG) logger.addHandler(file_handler) # optionally configure logging to python console stream_handler = logging.StreamHandler() stream_handler.setLevel(logging.INFO) logger.addHandler(stream_handler) # configure your logger # https://uds.readthedocs.io/en/stable/pages/user_guide/logging.html#configuration transport_logger = TransportLogger( logger_name="UDS", # the same name as previously configured logger message_logging_level=logging.INFO, packet_logging_level=logging.DEBUG, log_sending=True, log_receiving=True, ) # activate your logger # https://uds.readthedocs.io/en/stable/pages/user_guide/logging.html#decorating-transport-interface-class @transport_logger class CustomTransportInterface(AbstractTransportInterface): ... # TODO: implement your interface class ``` -------------------------------- ### start_tester_present Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/user_guide/client.rst Starts the periodic sending of Tester Present messages. This method initiates a background task that sends Tester Present requests at the configured interval. ```APIDOC ## start_tester_present ### Description Starts the periodic sending of Tester Present messages. ### Method start_tester_present ### Parameters - **addressing_type** (uds.addressing.AddressingType) - Required - Addressing Type to use - **sprmib** (bool) - Required - Whether to set Suppress Positive Response Message Indication Bit ### Example ```python client.start_tester_present(addressing_type=uds.addressing.AddressingType.PHYSICAL, # Addressing Type to use sprmib=False) # whether to set Suppress Positive Response Message Indication Bit ``` ``` -------------------------------- ### start_background_receiving Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/user_guide/client.rst Starts collecting response messages sent to the Client, such as asynchronous responses not directly tied to a single request. This enables background receiving of responses. ```APIDOC ## start_background_receiving ### Description Starts collecting response messages sent to the Client. ### Method start_background_receiving ### Example ```python client.start_background_receiving() ``` ``` -------------------------------- ### Receive a CAN packet asynchronously with PythonCanTransportInterface Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/examples/CAN/python-can.rst Configures a python-can Bus and CanAddressingInformation, then creates a PythonCanTransportInterface to receive a single CAN packet asynchronously. Uses NORMAL_ADDRESSING with physical and functional CAN IDs. The example sets receive_own_messages=True and CAN FD parameters, and calls teardown_async and shutdown to close connections. ```python """Receive asynchronously a packet defined by Diagnostic on CAN protocol (ISO 15765).""" import asyncio from can import Bus from uds.can import CanAddressingFormat, CanAddressingInformation, PythonCanTransportInterface async def main(): # configure CAN interface - https://python-can.readthedocs.io/en/stable/interfaces.html can_interface = Bus( # provide configuration for your CAN interface interface="kvaser", channel=0, receive_own_messages=True, # recommended # configure your CAN bus bitrate=500_000, fd=True, data_bitrate=4_000_000, ) # configure addresses for Diagnostics on CAN communication # CAN Addressing Formats explanation: # https://uds.readthedocs.io/en/stable/pages/knowledge_base/packet.html#can-packet-addressing-formats addressing_information = CanAddressingInformation( addressing_format=CanAddressingFormat.NORMAL_ADDRESSING, rx_physical_params={"can_id": 0x611}, tx_physical_params={"can_id": 0x612}, rx_functional_params={"can_id": 0x6FF}, tx_functional_params={"can_id": 0x6FE}, ) # create Transport Interface object for Diagnostics on CAN communication can_ti = PythonCanTransportInterface(network_manager=can_interface, addressing_information=addressing_information) # receive CAN packet received_packet_record = await can_ti.async_receive_packet(timeout=1000) # timeout=1000 [ms] # show received packet print(received_packet_record) # close connections with CAN interface can_ti.teardown_async(suppress_warning=True) can_interface.shutdown() if __name__ == "__main__": asyncio.run(main()) ``` -------------------------------- ### Service configuration example Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/user_guide/message_translation.rst Configures a Service object for DiagnosticSessionControl with request and response structures and supported NRC codes. Requires pre-defined sub_function_data_record and session_parameter_data_record. ```python from uds.translator import Service, AbstractDataRecord from uds.message import NRC, RequestSID # let's assume that we have `sub_function_data_record` and `session_parameter_data_record` Data Records defined sub_function_data_record: AbstractDataRecord session_parameter_data_record: AbstractDataRecord # configure example diagnostic service diagnostic_session_control = Service(request_sid=RequestSID.DiagnosticSessionControl, request_structure=[sub_function_data_record], response_structure=[sub_function_data_record, session_parameter_data_record], supported_nrc={NRC.SubFunctionNotSupported, NRC.IncorrectMessageLengthOrInvalidFormat, NRC.BusyRepeatRequest, NRC.ConditionsNotCorrect}) ``` -------------------------------- ### Generate flow control parameters with DefaultFlowControlParametersGenerator Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/user_guide/can.rst Creates a generator for flow control parameters (Flow Status, Block Size, STmin) for CAN. The first example uses wait_count=2 and repeat_wait=False, producing two Wait frames then ContinueToSend frames. The second example uses wait_count=1 and repeat_wait=True, alternating Wait and ContinueToSend frames. ```python # create example flow control parameters generators fc_gen_1 = uds.can.DefaultFlowControlParametersGenerator(block_size=2, st_min=5, wait_count=2, repeat_wait=False) # create iterators for flow control parameters fc_iter_1 = iter(fc_gen_1) # generate following flow control parameters (Flow Status, Block Size, STmin) next(fc_iter_1) # (, None, None) next(fc_iter_1) # (, None, None) next(fc_iter_1) # (, 2, 5) next(fc_iter_1) # (, 2, 5) # example 2 fc_gen_2 = uds.can.DefaultFlowControlParametersGenerator(block_size=13, st_min=241, wait_count=1, repeat_wait=True) fc_iter_2 = iter(fc_gen_2) next(fc_iter_2) # (, None, None) next(fc_iter_2) # (, 13, 241) next(fc_iter_2) # (, None, None) next(fc_iter_2) # (, 13, 241) ``` -------------------------------- ### Client.get_response_no_wait Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/user_guide/client.rst Gets the next response collected by Background Receiving without waiting. ```APIDOC ## Client.get_response_no_wait ### Description Gets the next response collected by Background Receiving without waiting. ``` -------------------------------- ### Receive CAN Packet with PythonCanTransportInterface Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/examples/CAN/python-can.rst Receives a CAN packet asynchronously using PythonCanTransportInterface. Configures a CAN bus with python-can, sets up addressing information, and receives with a timeout. Includes teardown. ```python """Receive asynchronously a packet defined by Diagnostic on CAN protocol (ISO 15765).""" import asyncio from can import Bus from uds.can import CanAddressingFormat, CanAddressingInformation, PythonCanTransportInterface async def main(): # configure CAN interface - https://python-can.readthedocs.io/en/stable/interfaces.html can_interface = Bus( # provide configuration for your CAN interface interface="vector", app_name="python-can", # name of the Application in Vector Hardware Config channel=0, receive_own_messages=True, # recommended # configure your CAN bus bitrate=500_000, fd=True, data_bitrate=4_000_000, ) # configure addresses for Diagnostics on CAN communication # CAN Addressing Formats explanation: # https://uds.readthedocs.io/en/stable/pages/knowledge_base/packet.html#can-packet-addressing-formats addressing_information = CanAddressingInformation( addressing_format=CanAddressingFormat.NORMAL_ADDRESSING, rx_physical_params={"can_id": 0x611}, tx_physical_params={"can_id": 0x612}, rx_functional_params={"can_id": 0x6FF}, tx_functional_params={"can_id": 0x6FE}, ) # create Transport Interface object for Diagnostics on CAN communication can_ti = PythonCanTransportInterface(network_manager=can_interface, addressing_information=addressing_information) # receive CAN packet received_packet_record = await can_ti.async_receive_packet(timeout=1000) # timeout=1000 [ms] # show received packet print(received_packet_record) # close connections with CAN interface can_ti.teardown_async(suppress_warning=True) can_interface.shutdown() if __name__ == "__main__": asyncio.run(main()) ``` -------------------------------- ### Client.__init__ Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/user_guide/client.rst Creates and configures the Client object. Accepts transport interface and timeout parameters. ```APIDOC ## Client.__init__ ### Description Creates and configures the Client object. Accepts transport interface and timeout parameters. ### Parameters - `transport_interface` (AbstractTransportInterface) - Required - Transport Interface used - `p2_client_timeout` (int) - Optional - Custom value of P2Client timeout - `p2_ext_client_timeout` (int) - Optional - Custom value of P2*Client timeout - `p3_client_physical` (int) - Optional - Custom value of P3Client_Phys - `p3_client_functional` (int) - Optional - Custom value of P3Client_Func - `p6_client_timeout` (int) - Optional - Custom value of P6Client timeout - `p6_ext_client_timeout` (int) - Optional - Custom value of P6*Client timeout - `s3_client` (int) - Optional - Custom value of S3Client ### Request Example ```python import uds # assume Transport Interface object exists transport_interface: uds.transport_interface.AbstractTransportInterface # configure Client object client = uds.client.Client(transport_interface=transport_interface, # Transport Interface used p2_client_timeout=50, # custom value of P2Client timeout p2_ext_client_timeout=5000, # custom value of P2*Client timeout p3_client_physical=250, # custom value of P3Client_Phys p3_client_functional=500, # custom value of P3Client_Func p6_client_timeout=1000, # custom value of P6Client timeout p6_ext_client_timeout=10000, # custom value of P6*Client timeout s3_client=1000) # custom value of S3Client ``` ``` -------------------------------- ### Send and Receive CAN Packets Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/user_guide/quickstart.rst Send and receive CAN packets using the Transport Interface. This is for packet-level (layers 3 and 4) operations. The example uses a single frame with functional addressing. ```python import uds # let's assume Transport Interface and Addressing Information objects are created can_ai: uds.can.addressing.NormalCanAddressingInformation transport_interface: uds.can.PythonCanTransportInterface # define example packet to send (depends on network type - example for CAN bus) sf = uds.can.CanPacket(packet_type=uds.can.CanPacketType.SINGLE_FRAME, payload=[0x3E, 0x00], **can_ai.tx_functional_params) # send a packet sent_packet_record = transport_interface.send_packet(sf) # receive a packet received_packet_record = transport_interface.receive_packet(timeout=None) # no timeout ``` -------------------------------- ### Upload to TestPyPI and PyPI with twine Source: https://github.com/mdabrowski1990/uds/wiki/Deployment Upload the built distribution to the test server first, then to PyPI. When prompted, use `__token__` as username and the token value (including `pypi-` prefix) as password. ```bash python -m twine upload --repository testpypi dist/* # to upload to test server first ``` ```bash python -m twine upload --repository pypi dist/* ``` -------------------------------- ### get_response_no_wait Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/user_guide/quickstart.rst Returns a response message immediately if available, without waiting. This method is non-blocking. ```APIDOC ## get_response_no_wait ### Description Returns a response message immediately if available, without waiting. This method is non-blocking. ### Method get_response_no_wait ### Response #### Success Response - **response_message_record** - The received response message record, or None if no response is available. ### Request Example ```python import uds # let's assume Client object is created client: uds.client.Client # get a response message immediately response_message_record = client.get_response_no_wait() ``` ``` -------------------------------- ### get_response Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/user_guide/quickstart.rst Waits for and returns a response message from the collected responses. This method blocks until a response is available. ```APIDOC ## get_response ### Description Waits for and returns a response message from the collected responses. This method blocks until a response is available. ### Method get_response ### Response #### Success Response - **response_message_record** - The received response message record. ### Request Example ```python import uds # let's assume Client object is created client: uds.client.Client # wait for a response message response_message_record = client.get_response() ``` ``` -------------------------------- ### stop_receiving Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/user_guide/quickstart.rst Stops the background task that collects response messages. This method is used to stop the collection of responses. ```APIDOC ## stop_receiving ### Description Stops the background task that collects response messages. This method is used to stop the collection of responses. ### Method stop_receiving ### Request Example ```python import uds # let's assume Client object is created client: uds.client.Client # stop collecting response messages client.stop_receiving() ``` ``` -------------------------------- ### stop_tester_present Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/user_guide/quickstart.rst Stops periodically sending TesterPresent messages. This method is used to stop the periodic TesterPresent transmission. ```APIDOC ## stop_tester_present ### Description Stops periodically sending TesterPresent messages. This method is used to stop the periodic TesterPresent transmission. ### Method stop_tester_present ### Request Example ```python import uds # let's assume Client object is created client: uds.client.Client # stop sending TesterPresent messages periodically client.stop_tester_present() ``` ``` -------------------------------- ### Define CAN Addressing Information Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/user_guide/quickstart.rst Configure NormalCanAddressingInformation for CAN with physical and functional CAN IDs. This is required before creating a transport interface. ```python import uds # configure Addressing Information can_ai = uds.can.addressing.NormalCanAddressingInformation( rx_physical_params={"can_id": 0x7E8}, tx_physical_params={"can_id": 0x7E0}, rx_functional_params={"can_id": 0x7E8}, tx_functional_params={"can_id": 0x7DF}) ``` -------------------------------- ### Configure UDS Client with custom timeouts Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/user_guide/client.rst Shows how to create a uds.client.Client with custom timeout values for P2Client, P2*Client, P3Client_Phys, P3Client_Func, P6Client, P6*Client, and S3Client. Requires an existing transport_interface object. ```python import uds # assume Transport Interface object exists transport_interface: uds.transport_interface.AbstractTransportInterface # configure Client object client = uds.client.Client(transport_interface=transport_interface, # Transport Interface used p2_client_timeout=50, # custom value of P2Client timeout p2_ext_client_timeout=5000, # custom value of P2*Client timeout p3_client_physical=250, # custom value of P3Client_Phys p3_client_functional=500, # custom value of P3Client_Func p6_client_timeout=1000, # custom value of P6Client timeout p6_ext_client_timeout=10000, # custom value of P6*Client timeout s3_client=1000) # custom value of S3Client ``` -------------------------------- ### send_request_receive_responses Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/user_guide/quickstart.rst Sends a diagnostic request message and receives all response messages. This method is used to perform a request-response exchange with the vehicle's ECU. ```APIDOC ## send_request_receive_responses ### Description Sends a diagnostic request message and receives all response messages. This method is used to perform a request-response exchange with the vehicle's ECU. ### Method send_request_receive_responses ### Parameters #### Request Body - **request** (UdsMessage) - Required - The diagnostic request message to send. ### Response #### Success Response - **request_record** - The record of the sent request. - **responses_records** - The records of all received responses. ### Request Example ```python import uds # let's assume Client object is created client: uds.client.Client # define an example request message request = uds.message.UdsMessage(payload=[0x14, 0xFF, 0xFF, 0xFF], addressing_type=uds.addressing.AddressingType.PHYSICAL) # send request and receive all responses request_record, responses_records = client.send_request_receive_responses(request) ``` ``` -------------------------------- ### requestChallengeForAuthentication (0x05) Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/knowledge_base/service.rst This sub-function initiates the client authentication process by requesting a challenge from the server. It is part of the Authentication service (SID 0x29) and is used to obtain a challenge for proof of ownership. ```APIDOC ## [REQUEST] requestChallengeForAuthentication (0x05) ### Description This sub-function can be used by the client to initiate own authentication process by requesting Challenge from the server. ### Method REQUEST ### Endpoint Service 0x29, Sub-function 0x05 ### Parameters #### Request Body - **SID** (8 bits) - Always - Authentication (0x29) - **SubFunction** (8 bits) - Always - Contains suppressPosRspMsgIndicationBit (bit 7) and authenticationTask (bits 6-0). For this sub-function, authenticationTask = 0x05. - suppressPosRspMsgIndicationBit (1 bit) - Always - 0: response required, 1: suppress positive response - authenticationTask (7 bits) - Always - 0x05 (requestChallengeForAuthentication) - **communicationConfiguration** (8 bits) - Always - Information about how to proceed with security in further diagnostic communication after the Authentication. Values meanings are vehicle manufacturer specific. - **algorithmIndicator** (128 bits) - Always - Indicates the algorithm used in the generating and verifying Proof of Ownership. This field is a 16 byte value containing the BER encoded OID value of the algorithm used. The value is left aligned and right padded with zero up to 16 bytes. ### Response #### Positive Response Format - **SID** (8 bits) - Always - Positive response SID (0x69) - **SubFunction** (8 bits) - Always - Echo of the request sub-function (0x05) - **challenge** (variable) - Always - The challenge data generated by the server for the client to prove ownership. ``` -------------------------------- ### Send request and receive responses Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/user_guide/quickstart.rst Creates a UDS message with a physical addressing type and sends it using the client, returning the request record and response records. ```python import uds # let's assume Client object is created client: uds.client.Client # define an example request message request = uds.message.UdsMessage(payload=[0x14, 0xFF, 0xFF, 0xFF], addressing_type=uds.addressing.AddressingType.PHYSICAL) # send request and receive all responses request_record, responses_records = client.send_request_receive_responses(request) ``` -------------------------------- ### Collecting Response Messages Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/user_guide/quickstart.rst Uses a background task to collect all response messages sent to the client when no request was sent. Useful for ResponseOnEvent, ReadDataByPeriodicIdentifier, or periodic TesterPresent responses. ```python import uds # let's assume Client object is created client: uds.client.Client # start collecting all response messages sent to client client.start_receiving() # wait for a response message response_message_record = client.get_response() # get a response message immediately response_message_record = client.get_response_no_wait() # stop collecting response messages client.stop_receiving() ``` -------------------------------- ### proofOfOwnership (0x03) Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/knowledge_base/service.rst This sub-function can be used by the client to verify Proof of Ownership on the client side. It is part of the Authentication service (SID 0x29). ```APIDOC ## [SID] 0x29 - proofOfOwnership (0x03) ### Description This sub-function can be used by the client to verify Proof of Ownership on the client side. ### Method Not specified (likely a request/response over UDS) ### Endpoint Not applicable (UDS service) ### Parameters #### Request Body - **SID** (8 bits) - Required - Authentication (0x29) - **SubFunction** (8 bits) - Required - proofOfOwnership (0x03) - **challengeServer** (8 * lengthOfChallengeServer) - Required - Challenge generated by the server for the client - **lengthOfCertificateServer** (16 bits) - Required - Number of bytes to use for certificateServer (0x0001-0xFFFF) - **certificateServer** (8 * lengthOfCertificateServer) - Required - Certificate to verify - **lengthOfProofOfOwnershipServer** (16 bits) - Required - Number of bytes to use for proofOfOwnershipServer (0x0001-0xFFFF) - **proofOfOwnershipServer** (8 * lengthOfProofOfOwnershipServer) - Required - Proof of Ownership to be verified by the client - **lengthOfEphemeralPublicKeyServer** (16 bits) - Required - Number of bytes to use for ephemeralPublicKeyServer (0x0000-0xFFFF) - **ephemeralPublicKeyServer** (8 * lengthOfEphemeralPublicKeyServer) - Optional - Ephemeral public key generated by the server for Diffie-Hellman key agreement (present if lengthOfEphemeralPublicKeyServer != 0) ### Response Not specified in the source. ``` -------------------------------- ### TextDataRecord import example Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/user_guide/message_translation.rst Imports TextDataRecord and TextEncoding classes from uds.translator. This is the starting point for defining text data records that translate to text using supported encoding formats (e.g., ASCII, BCD). ```python from uds.translator import TextDataRecord, TextEncoding ``` -------------------------------- ### Authentication (0x29) Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/knowledge_base/service.rst This service provides a mechanism for the client to prove its identity, allowing access to restricted data or diagnostic services. It supports multiple sub-functions for authentication tasks. ```APIDOC ## [POST] Authentication (0x29) ### Description This service provides a mechanism for the client to prove its identity, allowing access to restricted data or diagnostic services. It supports multiple sub-functions for authentication tasks. ### Method POST ### Endpoint Authentication (0x29) ### Parameters #### Request Body - **authenticationTask** (uint8) - Required - The sub-function value (0x00-0x08). ### Response #### Success Response (200) - **RSID** (uint8) - Always 0x69. - **SubFunction** (uint8) - Echo of the authenticationTask value from the request. ``` -------------------------------- ### Upgrade py-uds to latest release Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/installation.rst Upgrades the installed UDS package to the latest release version from PyPI. ```shell pip install -U py-uds ``` -------------------------------- ### Client.get_response Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/user_guide/client.rst Waits for the next response collected by Background Receiving. ```APIDOC ## Client.get_response ### Description Waits for the next response collected by Background Receiving. ``` -------------------------------- ### Client.wait_till_ready_for_transmission Source: https://github.com/mdabrowski1990/uds/blob/main/docs/source/pages/user_guide/client.rst Waits till Client is ready for transmitting given request message. ```APIDOC ## Client.wait_till_ready_for_transmission ### Description Waits till Client is ready for transmitting given request message. ```