Hello,
I am using SvcReadDataByIdentifier_2013to request 0x22 service to ECU like 22 01 01.
however I am not sure how can I send 0x21 service to ECU? like 21 01 01?
it looks like SvcReadDataByIdentifier_2013send always 0x22 service only..
question for SvcReadDataByIdentifier_2013
-
- Software Development
- Posts: 305
- Joined: Mon 9. Sep 2013, 12:21
Re: question for SvcReadDataByLocalIdentifier_2013
Hello,
The first data byte you are trying to change is the Service ID. Changing this byte means you want to use another service...
- The standardized UDS service is ReadDataByIdentifier (0x22).
- Service 0x21 is not a standardized UDS service.
- Check ISO 14229-1:2020 for the complete list of standardized UDS services.
To request a custom service, you will have to use function UDS_Write_2013 instead of UDS_SvcReadDataByIdentifier_2013.
You can check sample "07_read_write_uds" to see how to allocate and initialize a uds_msg.
You can still use UDS_WaitForXXX function to retrieve the Tx confirmation and the ECU's response.
The first data byte you are trying to change is the Service ID. Changing this byte means you want to use another service...
- The standardized UDS service is ReadDataByIdentifier (0x22).
- Service 0x21 is not a standardized UDS service.
- Check ISO 14229-1:2020 for the complete list of standardized UDS services.
To request a custom service, you will have to use function UDS_Write_2013 instead of UDS_SvcReadDataByIdentifier_2013.
You can check sample "07_read_write_uds" to see how to allocate and initialize a uds_msg.
You can still use UDS_WaitForXXX function to retrieve the Tx confirmation and the ECU's response.
Best regards,
Fabrice
Fabrice
Re: question for SvcReadDataByIdentifier_2013
hello
thanks for your feed back. please see my code below, I can do communication with ECU as functional address mode, but I can get ECU response with WaitForService_2013... do I need to use other function to get ECU response?
** changed by ADMIN - see Forum Rules - ALWAYS format if you post source code **
thanks for your feed back. please see my code below, I can do communication with ECU as functional address mode, but I can get ECU response with WaitForService_2013... do I need to use other function to get ECU response?
Code: Select all
import os
import sys
import copy
from time import sleep
from PCAN_UDS_2013 import *
import threading
# Help functions
def OK_KO(test):
return "OK" if test else "KO"
def STATUS_OK_KO(test):
return OK_KO(objPCANUds.StatusIsOk_2013(test, PUDS_STATUS_OK, False))
def UDS_STATUS_OK_KO(test):
return OK_KO(objPCANUds.StatusIsOk_2013(test, PUDS_STATUS_OK, False))
def ThreadWork():
# Execute ReadDataByIdentifier on 0x5812 and wait response
TESTER_ID=0x7DF
ECU_ID=0x7E8
# Initialize source mapping
source_mapping = uds_mapping()
source_mapping.can_id = TESTER_ID
source_mapping.can_id_flow_ctrl = ECU_ID
source_mapping.can_msgtype = PCANTP_CAN_MSGTYPE_STANDARD
source_mapping.can_tx_dlc = 0
source_mapping.nai.extension_addr = 0
source_mapping.nai.target_type = PCANTP_ISOTP_ADDRESSING_FUNCTIONAL
source_mapping.nai.protocol = PUDS_MSGPROTOCOL_ISO_15765_2_11B_NORMAL
#source_mapping.nai.source_addr = PUDS_ISO_15765_4_ADDR_TEST_EQUIPMENT #0xF1
#source_mapping.nai.target_addr = 0x01
# Initialize response mapping
response_mapping = uds_mapping()
response_mapping.can_id = source_mapping.can_id_flow_ctrl
response_mapping.can_id_flow_ctrl = source_mapping.can_id
response_mapping.can_msgtype = source_mapping.can_msgtype
response_mapping.can_tx_dlc = source_mapping.can_tx_dlc
response_mapping.nai.extension_addr = source_mapping.nai.extension_addr
response_mapping.nai.target_type = source_mapping.nai.target_type
response_mapping.nai.protocol = source_mapping.nai.protocol
#response_mapping.nai.source_addr = source_mapping.nai.target_addr
#response_mapping.nai.target_addr = source_mapping.nai.source_addr
# Add mapping: 0xF1 -> 0x12
status = objPCANUds.AddMapping_2013(client_handle, source_mapping)
#print("Add source mapping on transmitter: %s" %(UDS_STATUS_OK_KO(status)))
# Add mapping: 0x12 -> 0xF1
status = objPCANUds.AddMapping_2013(client_handle, response_mapping)
#print("Add response mapping on transmitter: %s" %(UDS_STATUS_OK_KO(status)))
# Initialize a physical configuration
config_physical = uds_msgconfig()
config_physical.can_id = 0x7df # required for functional
config_physical.can_msgtype = source_mapping.can_msgtype
config_physical.nai.protocol = source_mapping.nai.protocol
config_physical.nai.target_type = source_mapping.nai.target_type
config_physical.type = PUDS_MSGTYPE_USDT
config_physical.nai.source_addr = source_mapping.nai.source_addr
config_physical.nai.target_addr = source_mapping.nai.target_addr
config_physical.nai.extension_addr = 0
'''
ISOTP_REQUEST_MSG = create_string_buffer(6)
ISOTP_REQUEST_MSG[0]=0x22
ISOTP_REQUEST_MSG[1]=0x02
ISOTP_REQUEST_MSG[2]=0x01
'''
MSG_SIZE = 2
while 1:
sleep(0.01)
msg_request = uds_msg()
response = uds_msg()
request_confirmation = uds_msg()
data_identifier_count = 1
#data_identifiers = (c_uint16 * data_identifier_count) (0x0101) #22 01 01
# Allocate TX message with previous configuration
tx_msg = uds_msg()
status = objPCANUds.MsgAlloc_2013(tx_msg, config_physical, MSG_SIZE)
tx_msg.msg.msgdata.any.contents.data[0]=0x21
tx_msg.msg.msgdata.any.contents.data[1]=0x01
#tx_msg.msg.msgdata.any.contents.data[2]=0x01
print("Allocate TX message: %s" %(STATUS_OK_KO(status)))
status = objPCANUds.Write_2013(client_handle, tx_msg)
if objPCANUds.StatusIsOk_2013(status, PUDS_STATUS_OK, False):
status = objPCANUds.WaitForService_2013(client_handle, msg_request, response, request_confirmation)
print("WaitForService_2013: %s" %(STATUS_OK_KO(status)))
#print(response.msg.msgdata.any.contents.data[0])
'''
message_data = bytes(response.msg.msgdata.any.contents.data[:response.msg.msgdata.any.contents.length])
byte_list = [f'{byte:02x}' for byte in message_data]
print(byte_list)
print(f"0x{response.msg.can_info.can_id:x}")
'''
os.add_dll_directory(os.getcwd());
# UDS library
objPCANUds = PCAN_UDS_2013()
# Definitions
BUFFER_SIZE = 256
##########################################################################################################################
# Main entry point of the program, start a UDS channel, ask in the same time UDS TesterPresent and isotp request
#
# Initialize variables
client_handle = PCANTP_HANDLE_USBBUS1 # TODO: modify the value according to your available PCAN devices.
#t_params = task_params()
#t_params.client_handle = client_handle
#t_params.stop_task = False
# Print version informations
buffer = create_string_buffer(BUFFER_SIZE)
status = objPCANUds.GetValue_2013(PCANTP_HANDLE_NONEBUS, PUDS_PARAMETER_API_VERSION, buffer, BUFFER_SIZE)
print("PCAN-UDS API Version - %s: %s" %(buffer.value, UDS_STATUS_OK_KO(status)))
# Initialize client channel
status = objPCANUds.Initialize_2013(client_handle, PCANTP_BAUDRATE_500K, 0, 0, 0)
print("Initialize channel: %s" %(UDS_STATUS_OK_KO(status)))
ThreadWorking=threading.Thread(target=ThreadWork)
ThreadWorking.start()
ThreadWorking.join()
objPCANUds.Uninitialize_2013(client_handle)
Re: question for SvcReadDataByIdentifier_2013
Dear,
Please understand that neither the companion development of software nor teaching protocols and standards is part of the scope of support that we offer for the libraries. My colleague has already helped you beyond the scope of our support. If you can use the services of our APIs and send messages, then the problem is more likely with the configuration of your ECU. Please check its documentation and also the UDS documentation regarding the services you are using. Note that the standards (ISO-TP and UDS protocol descriptions) are not part of our documentation. in case you do not have these, they can be purchased via the ISO online shop.
Thank you for your understanding.
Please understand that neither the companion development of software nor teaching protocols and standards is part of the scope of support that we offer for the libraries. My colleague has already helped you beyond the scope of our support. If you can use the services of our APIs and send messages, then the problem is more likely with the configuration of your ECU. Please check its documentation and also the UDS documentation regarding the services you are using. Note that the standards (ISO-TP and UDS protocol descriptions) are not part of our documentation. in case you do not have these, they can be purchased via the ISO online shop.
Thank you for your understanding.
Best regards,
Keneth
Keneth