Client
This section describes the Client implementation,
provided in the uds.client module.
The main entry point is the Client class.
Attributes:
DEFAULT_P2_CLIENT_TIMEOUT- default P2Client timeoutDEFAULT_P2_EXT_CLIENT_TIMEOUT- default P2*Client timeoutDEFAULT_P3_CLIENT- default P3Client valueDEFAULT_P6_CLIENT_TIMEOUT- default P6Client timeoutDEFAULT_P6_EXT_CLIENT_TIMEOUT- default P6*Client timeoutDEFAULT_S3_CLIENT- default S3Client valueDEFAULT_RECEIVING_TASK_CYCLE- default cycle used by Background Receivingtester_present_storage_size- number of Tester Present request records storedtransport_interface- transport interface in usep2_client_timeout- configured P2Client timeoutp2_client_measured- last measured P2Client valuep2_ext_client_timeout- configured P2*Client timeoutp2_ext_client_measured- last measured P2*Client valuep3_client_physical- configured P2Client_Phys valuep3_client_functional- configured P2Client_Func valuep6_client_timeout- configured P6Client timeoutp6_client_measured- last measured P6Client valuep6_ext_client_timeout- configured P6*Client timeoutp6_ext_client_measured- last measured P6*Client valuelast_sent_tester_present_requests- the last sent few (number equal totester_present_storage_size) Tester Present request recordslast_sent_request- the last transmitted request messagelast_received_response- the final response tolast_sent_requestis_background_receiving- whether Background Receiving is onis_tester_present_sent- whether Tester Present is sent periodicallyis_ready_for_physical_transmission- whether Client is ready for transmitting physically addressed request messageis_ready_for_functional_transmission- whether Client is ready for transmitting functionally addressed request message
Methods:
__init__()- create and configure the Client__del__()- clean up and stop background tasks safelyis_response_pending_message()- check if a message is a negative response with Response Pending (0x78) NRCis_response_to_request()- check if a message is a response to provided request messagewait_till_ready_for_physical_transmission()- wait till Client is ready for transmitting physically addressed requestwait_till_ready_for_functional_transmission()- wait till Client is ready for transmitting functionally addressed requestwait_till_ready_for_transmission()- wait till Client is ready for transmitting given request messageget_response()- wait for the next response collected by Background Receivingget_response_no_wait()- get the next response collected by Background Receiving without waitingclear_response_queue()- clear messages collected so far by Background Receivingstart_tester_present()- start sending Tester Present messages periodicallystop_tester_present()- stop sending Tester Present messages periodicallystart_background_receiving()- turn Background Receiving on and start collecting responsestop_background_receiving()- turn Background Receiving off and stop collecting responsesend_request_receive_responses()- send request message and collect all responses till the final one
Configuration
The Client is configured during Client object creation.
The following arguments can be provided:
P2Client timeout value
P2*Client timeout value
P3Client_Phys value
P3Client_Func value
P6Client timeout value
P6*Client timeout value
S3Client value
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:
start_tester_present()- start sending Tester Present messages periodicallystop_tester_present()- stop sending Tester Present messages periodically
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:
start_background_receiving()- start collecting responsesstop_background_receiving()- stop collecting responsesget_response()- get the next response (waits if none are available)get_response_no_wait()- get the next response immediately (returns None if none are available)clear_response_queue()- clear queue with response messages
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()