Client

This section describes the Client implementation, provided in the uds.client module. The main entry point is the Client class.

Attributes:

Methods:

Configuration

The Client is configured during Client object creation. The following arguments can be provided:

Example code:

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

Sending Requests and Receiving Responses

send_request_receive_responses() can be used to send a request message and collect all responses, including Negative Responses with NRC Response Pending (0x78) and the final response.

Example code:

import uds

# assume Client object exists
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)

Tester Present

Manage periodic TesterPresent messages with:

Period used for transmission is controlled by s3_client.

is_tester_present_sent indicates whether Tester Present cyclic sending is currently active.

last_sent_tester_present_requests contains Tester Present request messages records that were sent by periodic Tester Present task.

Example code:

# assume Client object exists
client: uds.client.Client

# set period for Tester Present messages
client.s3_client = 1000  # ms

# start sending Tester Present Messages periodically
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

# stop sending Tester Present Messages periodically
client.stop_tester_present()

Background Receiving

Use this feature to receive response messages sent to Client such as asynchronous responses not directly tied to a single request (e.g. ResponseOnEvent, ReadDataByPeriodicIdentifier).

Methods:

is_background_receiving indicates whether responses are currently being collected.

Example code:

# assume Client object exists
client: uds.client.Client
# assume some request message object exists
some_request: uds.message.UdsMessage

# clear messages queue before receiving any messages
client.clear_response_queue()

# start collecting responses
client.start_background_receiving()

# you might send requests while collecting responses is active
client.send_request_receive_responses(some_request)

# get the next collected response with a timeout
client.get_response(timeout=1000)  # ms

# get next response immediately
client.get_response_no_wait()

# stop collecting responses
client.stop_background_receiving()