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_P6_CLIENT_TIMEOUT- default P6Client timeoutDEFAULT_P2_EXT_CLIENT_TIMEOUT- default P2*Client timeoutDEFAULT_P6_EXT_CLIENT_TIMEOUT- default P6*Client timeoutDEFAULT_S3_CLIENT- default S3Client valueDEFAULT_RECEIVING_TASK_CYCLE- default cycle used by Background Receivingtransport_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 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 valueis_receiving- whether Background Receiving is onis_tester_present_sent- whether Tester Present is sent periodically
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) NRCget_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_receiving()- start collecting responsesstop_receiving()- stop collecting responsesstart_tester_present()- start sending Tester Present messages periodicallystop_tester_present()- stop sending Tester Present messages periodicallysend_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
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, 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.
Whether Tester Present is currently active is indicated by is_tester_present_sent.
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_receiving()- start collecting responsesstop_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)
Whether responses are currently being collected is indicated by is_receiving.
Example code:
# assume Client object exists client: uds.client.Client # assume some request message object exists some_request: uds.message.UdsMessage # start collecting responses client.start_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_receiving()