ISO-TP_FORMAT_EXTENDED is not working

A free API for the transfer of data packages according to ISO-TP (ISO 15765-2)
Kevin1
Posts: 14
Joined: Sun 2. Jun 2024, 10:40

ISO-TP_FORMAT_EXTENDED is not working

Post by Kevin1 » Sun 2. Jun 2024, 10:48

Hello

I am working on BMW TP protocol which is extended addressing mode.
test id is 0x6f1 and ECU is is 0x612
I have created TX module as below but I see always flow control error from a simulator since this source does not send '30' for TP response message. should I create my own command to send '30' message? or is there any bug for extended addressing mode? it looks like mapping.can_id_flow_ctrl is not working....

Code: Select all

mapping = cantp_mapping()
	mapping.can_id = 0x6f1  # Extended CAN ID
	mapping.can_id_flow_ctrl = 0x612  # Extended CAN ID for Flow Control
	mapping.can_msgtype = PCANTP_CAN_MSGTYPE_STANDARD  

Code: Select all

mapping.netaddrinfo.format = PCANTP_ISOTP_FORMAT_EXTENDED  # extended adressing format from ISO 15765-2
	mapping.netaddrinfo.msgtype = PCANTP_ISOTP_MSGTYPE_DIAGNOSTIC  
	mapping.netaddrinfo.target_type = PCANTP_ISOTP_ADDRESSING_PHYSICAL  

Code: Select all

mapping.netaddrinfo.source_addr = 0xF1  
	mapping.netaddrinfo.target_addr = 0x12  
	mapping.netaddrinfo.extension_addr = 0x00  

Code: Select all

# Add ISOTP mappings on channels
	status = objPCANIsotp.AddMapping_2016(client_handle, mapping)
	print("[ISOTP] Add a simple isotp mapping: %s" %(ISOTP_STATUS_OK_KO(status)))

Code: Select all

# Initialize ISOTP Tx message containing 
	tx_msg = cantp_msg()
	status = objPCANIsotp.MsgDataAlloc_2016(tx_msg, PCANTP_MSGTYPE_ISOTP)
	print("[ISOTP] Allocate ISOTP tx message: %s" %(ISOTP_STATUS_OK_KO(status)))
	status = objPCANIsotp.MsgDataInit_2016(tx_msg, mapping.can_id, mapping.can_msgtype, MSG_SIZE, ISOTP_REQUEST_MSG, mapping.netaddrinfo)
	print("[ISOTP] Initialize ISOTP tx message: %s" %(ISOTP_STATUS_OK_KO(status)))
	##########################


	while not parameters.stop_task:
		
	
		status = PCANTP_STATUS_OK
		while not objPCANIsotp.StatusIsOk_2016(status, PCANTP_STATUS_NO_MESSAGE, False):
			
				
			status = objPCANIsotp.Write_2016(client_handle, tx_msg) 
			
			sleep(TX_SLEEP)
            ##########################

M.Heidemann
Sales & Support
Sales & Support
Posts: 1083
Joined: Fri 20. Sep 2019, 13:31

Re: ISO-TP_FORMAT_EXTENDED is not working

Post by M.Heidemann » Mon 3. Jun 2024, 16:47

Hello,

As far as we can tell you have no reverse mapping for incoming responses,
it should look like this:

Code: Select all

        mapping = cantp_mapping()
        mapping.can_id = 0x612  # Extended CAN ID
        mapping.can_id_flow_ctrl = 0x6f1  # Extended CAN ID for Flow Control
        mapping.can_msgtype = PCANTP_CAN_MSGTYPE_STANDARD  
        mapping.netaddrinfo.format = PCANTP_ISOTP_FORMAT_EXTENDED  # extended adressing format from ISO 15765-2
        mapping.netaddrinfo.msgtype = PCANTP_ISOTP_MSGTYPE_DIAGNOSTIC  
        mapping.netaddrinfo.target_type = PCANTP_ISOTP_ADDRESSING_PHYSICAL  
        mapping.netaddrinfo.source_addr = 0x12  
        mapping.netaddrinfo.target_addr = 0xF1  
        mapping.netaddrinfo.extension_addr = 0x00  

        # Add ISOTP mappings on channels
        status = objPCANIsotp.AddMapping_2016(client_handle, mapping)
        print("[ISOTP] Add a simple isotp mapping: %s" %(ISOTP_STATUS_OK_KO(status)))
You need to define a mapping for all frames in your application, regardless of direction.

Please let us know if this solved your problem.

Best Regards

Marvin
---
Marvin Heidemann
PEAK-Support Team

Kevin1
Posts: 14
Joined: Sun 2. Jun 2024, 10:40

Re: ISO-TP_FORMAT_EXTENDED is not working

Post by Kevin1 » Thu 6. Jun 2024, 10:18

I had tried already as below. but sill I got flow control error and can't get data more than 8 byte since PACN does not send 30 for example when it receives F1 10 07 62 58 12 00 33, PCAN need to send 12 30 00 00 00 00 00 00 to get next frame. this is reason why I get flow control error and can't get all frames...

for your reference, in rx, I have tried mapping.can_id = 0x612 / 0x6f1 ...... as your instruction

Code: Select all

def isotp_tx(parameters):
		##########################  TX 메시지 설정

	'''
	ISOTP_REQUEST_MSG = create_string_buffer(6)
	ISOTP_REQUEST_MSG[0]=0x22
	ISOTP_REQUEST_MSG[1]=0x01
	ISOTP_REQUEST_MSG[2]=0x01
	ISOTP_REQUEST_MSG[3]=0x00
	ISOTP_REQUEST_MSG[4]=0x00
	ISOTP_REQUEST_MSG[5]=0x00
	MSG_SIZE = 3
	'''
	# ISO-TP 매핑 설정
	mapping = cantp_mapping()
	mapping.can_id = 0x6f1  # Extended CAN ID
	mapping.can_id_flow_ctrl = 0x612  # Extended CAN ID for Flow Control
	mapping.can_msgtype = PCANTP_CAN_MSGTYPE_STANDARD  # CAN 메시지 타입을 Extended로 설정

	# 네트워크 주소 정보 설정
	
	mapping.netaddrinfo.format = PCANTP_ISOTP_FORMAT_EXTENDED  # extended adressing format from ISO 15765-2
	mapping.netaddrinfo.msgtype = PCANTP_ISOTP_MSGTYPE_DIAGNOSTIC  # 메시지 타입을 진단으로 설정
	mapping.netaddrinfo.target_type = PCANTP_ISOTP_ADDRESSING_PHYSICAL  # 주소 지정 방식을 Physical로 설정

	mapping.netaddrinfo.source_addr = 0xF1  #Extension 방식을 사용할때만 지정할것
	mapping.netaddrinfo.target_addr = 0x12  #Extension 방식을 사용할때만 지정할것
	mapping.netaddrinfo.extension_addr = 0x00  # 필요에 따라 확장 주소 설정

		# Add ISOTP mappings on channels
	status = objPCANIsotp.AddMapping_2016(client_handle, mapping)
	print("[ISOTP] Add a simple isotp mapping: %s" %(ISOTP_STATUS_OK_KO(status)))

		# Initialize ISOTP Tx message containing 
	tx_msg = cantp_msg()
	status = objPCANIsotp.MsgDataAlloc_2016(tx_msg, PCANTP_MSGTYPE_ISOTP)
	print("[ISOTP] Allocate ISOTP tx message: %s" %(ISOTP_STATUS_OK_KO(status)))
	status = objPCANIsotp.MsgDataInit_2016(tx_msg, mapping.can_id, mapping.can_msgtype, MSG_SIZE, ISOTP_REQUEST_MSG, mapping.netaddrinfo)
	print("[ISOTP] Initialize ISOTP tx message: %s" %(ISOTP_STATUS_OK_KO(status)))
	##########################


	while not parameters.stop_task:
		
	
		status = PCANTP_STATUS_OK
		while not objPCANIsotp.StatusIsOk_2016(status, PCANTP_STATUS_NO_MESSAGE, False):
			
		#while 1:	
		
			########################## ISO-TP 메시지 전송
			status = objPCANIsotp.Write_2016(client_handle, tx_msg) # tx_msg Request를 보내는 명령어
			
			sleep(TX_SLEEP)
            ##########################
	
	



def isotp_rx(parameters):


	# Configure isotp to get any messages (disable can identifier filtering)
	isotp_param = c_ubyte(0)
	status = objPCANIsotp.SetValue_2016(parameters.client_handle, PCANTP_PARAMETER_FILTER_CAN_ID, isotp_param, sizeof(isotp_param))
	print("[ISOTP] Disable can identifier filtering in isotp: %s" %(ISOTP_STATUS_OK_KO(status)))

	# Configure isotp to get a copy of UDS messages
	isotp_param = c_ubyte(1)
	status = objPCANIsotp.SetValue_2016(parameters.client_handle, PCANTP_PARAMETER_KEEP_HIGHER_LAYER_MESSAGES, isotp_param, sizeof(isotp_param))
	print("[ISOTP] Activate higher layer messages in isotp: %s" %(ISOTP_STATUS_OK_KO(status)))

	# Create a isotp receive event
	if IS_WINDOWS:
		receive_event = c_void_p(windll.kernel32.CreateEventA(None, 0,0,None))
		#status = objPCANIsotp.SetValue_2016(parameters.client_handle, PCANTP_PARAMETER_RECEIVE_EVENT, receive_event, sizeof(receive_event))
		#status = objPCANIsotp.SetValue_2016(parameters.client_handle, PCANTP_PARAMETER_RECEIVE_EVENT, receive_event, sizeof(receive_event))
		
		
		print("[ISOTP] Set isotp receive event parameter: %s" %(ISOTP_STATUS_OK_KO(status)))
	else:
		receive_event = NULL_HANDLE()
		status = objPCANIsotp.GetValue_2016(parameters.client_handle, PCANTP_PARAMETER_RECEIVE_EVENT, receive_event, sizeof(receive_event))
		print("[ISOTP] Get isotp receive event parameter: %s" %(ISOTP_STATUS_OK_KO(status)))

	# Read and print ISOTP messages
	rx_msg = cantp_msg()
	message_data = bytearray() # 초기화

		
	
	# ISO-TP 매핑 설정
	mapping = cantp_mapping()
	mapping.can_id = 0x612  # Extended CAN ID
	mapping.can_id_flow_ctrl = 0x6f1  # Extended CAN ID for Flow Control
	mapping.can_msgtype = PCANTP_CAN_MSGTYPE_STANDARD  # CAN 메시지 타입을 Extended로 설정

	# 네트워크 주소 정보 설정
	
	mapping.netaddrinfo.format = PCANTP_ISOTP_FORMAT_EXTENDED  # extended adressing format from ISO 15765-2
	mapping.netaddrinfo.msgtype = PCANTP_ISOTP_MSGTYPE_DIAGNOSTIC  # 메시지 타입을 진단으로 설정
	mapping.netaddrinfo.target_type = PCANTP_ISOTP_ADDRESSING_PHYSICAL  # 주소 지정 방식을 Physical로 설정
	mapping.netaddrinfo.source_addr = 0x12  #Extension 방식을 사용할때만 지정할것
	mapping.netaddrinfo.target_addr = 0xf1  #Extension 방식을 사용할때만 지정할것
	mapping.netaddrinfo.extension_addr = 0x00  # 필요에 따라 확장 주소 설정
		# Add ISOTP mappings on channels
	#status = objPCANIsotp.AddMapping_2016(client_handle, mapping)
	#print("[ISOTP] Add a simple isotp mapping: %s" %(ISOTP_STATUS_OK_KO(status)))
Edit by Admin - please READ the Forum Rules ! Code MUST be in Code Brackets !

F.Vergnaud
Software Development
Software Development
Posts: 305
Joined: Mon 9. Sep 2013, 12:21

Re: ISO-TP_FORMAT_EXTENDED is not working

Post by F.Vergnaud » Thu 6. Jun 2024, 16:45

Hello,

This code is non-sense, you should check the examples before trying to guess how the API works.
We told you to initialize all the mappings first! Currently your are initializing one mapping in a function isotp_tx and the other one in the function isotp_rx.
We can't provide support if we have to guess how and when you are calling your functions...

Please create a function where you call AddMapping_2016 twice:
* once for mapping 0x6f1/0x612
* and the other for mapping 0x612/0x6f1
Do not forget to check the status of the AddMapping_2016 calls (your application should die/abort if it is not OK).
You must call this function only once. If it succeeds then you can call a function that transmits your message with : MsgDataAlloc_2016, MsgDataInit_2016 and Write_2016.
Finally after Write_2016 you should loop to read the confirmation of the transmission.

Moreover you are incorrectly using parameter PCANTP_PARAMETER_FILTER_CAN_ID, you have to remove this configuration.
Finally you are using parameter PCANTP_PARAMETER_KEEP_HIGHER_LAYER_MESSAGES, are you using PCAN-UDS at the same time?
* If not remove this configuration too, this is useless and confusing.
* If yes, double-check the documentation you are not supposed to do this unless you would like to debug the UDS stack. Directly use PCAN-UDS to make requests.
Best regards,
Fabrice

Kevin1
Posts: 14
Joined: Sun 2. Jun 2024, 10:40

Re: ISO-TP_FORMAT_EXTENDED is not working

Post by Kevin1 » Sun 9. Jun 2024, 08:48

Hello,

I am attaching my full code and problem explain in detail.

Basically, I am using a ECU simulator with other program so I don't think I need to set up reverse mapping.
ISOTP with Normal addressing mode is working perfectly, but I am struggling with ISOTP in Extended address mode.
Please see attached and advise me.


Thanks in advance.

Kevin
acoustickkm@naver.com
Attachments
New folder (2).zip
(273.04 KiB) Downloaded 1278 times

F.Vergnaud
Software Development
Software Development
Posts: 305
Joined: Mon 9. Sep 2013, 12:21

Re: ISO-TP_FORMAT_EXTENDED is not working

Post by F.Vergnaud » Mon 10. Jun 2024, 12:43

Hello,

Your sample "ISOTP with Normal addressing mode" is working because you are using standardized ISO-15765-4 addresses:
- see PUDS_ISO_15765_4_CAN_ID_PHYSICAL_REQUEST_8 (0x7E7)
- see PUDS_ISO_15765_4_CAN_ID_PHYSICAL_RESPONSE_8 (0x7EF)
- see PCAN-UDS API documentation §4.3 "UDS and ISO-TP Network Addressing Information".
Your code points out this fact:

Code: Select all

status = objPCANIsotp.AddMapping_2016(client_handle, mapping)
print("[ISOTP] Add a simple isotp mapping: %s" %(ISOTP_STATUS_OK_KO(status)))
// here your console outputs KO !
// status returned is 15: PCANTP_STATUS_MAPPING_ALREADY_INITIALIZED

Also in your code you commented:
# ISOTP API의 에러로 보이는데, 처음에는 두번째 21번부터 전부 00 00 00 .. 으로 나와서 필터링한다
Translated as
# It appears to be an error in the ISOTP API, but at first, starting from the second number 21, everything comes out as 00 00 00 .., so it is filtered.
This is not a bug: you are receiving an ISOTP indication... the API has received the start of a segmented ISOTP message, this notification is mandatory.
Please note that this is something heavily documented in our API documentations, samples and also in the ISO 15765-2 documents.
You have to check:
1. that the read message corresponds to an ISOTP message (PCANTP_MSGTYPE_ISOTP), see see rx_msg.type ;
2. that its network status is OK (PCANTP_NETSTATUS_OK), see rx_msg.msgdata.any.netstatus ;
3. if the type of ISOTP message has an indication flag (PCANTP_ISOTP_MSGTYPE_FLAG_INDICATION), see rx_msg.msgdata.isotp.netaddrinfo.msgtype.


Finally, for your "Extended addressing client_uds_and_can" script, as said previously you have to configure the mappings for EXTENDED communication as follows:

Code: Select all


# Initialize client channel
status = objPCANUds.Initialize_2013(client_handle, PCANTP_BAUDRATE_500K, 0, 0, 0)
print("Initialize channel: %s" %(UDS_STATUS_OK_KO(status)))

TESTER_ID=0x6f1 
ECU_ID=0x612

# 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.source_addr = PUDS_ISO_15765_4_ADDR_TEST_EQUIPMENT
source_mapping.nai.target_addr = 0x12
source_mapping.nai.target_type = PCANTP_ISOTP_ADDRESSING_PHYSICAL
source_mapping.nai.protocol = PUDS_MSGPROTOCOL_ISO_15765_2_11B_EXTENDED

# 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.source_addr = source_mapping.nai.target_addr
response_mapping.nai.target_addr = source_mapping.nai.source_addr
response_mapping.nai.target_type = source_mapping.nai.target_type
response_mapping.nai.protocol = source_mapping.nai.protocol

# 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)))
Best regards,
Fabrice

Kevin1
Posts: 14
Joined: Sun 2. Jun 2024, 10:40

Re: ISO-TP_FORMAT_EXTENDED is not working

Post by Kevin1 » Sat 15. Jun 2024, 21:14

Hello,

I tried as below as per your advise but no success... can you advise me what's wrong with codes below?

no any CAN signal is going out and nothing happen....

Code: Select all

##########################################################################################################################
# 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)))


# Initialize client channel
status = objPCANUds.Initialize_2013(client_handle, PCANTP_BAUDRATE_500K, 0, 0, 0)
print("Initialize channel: %s" %(UDS_STATUS_OK_KO(status)))

TESTER_ID=0x6f1 
ECU_ID=0x612

# 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.source_addr = PUDS_ISO_15765_4_ADDR_TEST_EQUIPMENT
source_mapping.nai.target_addr = 0x12
source_mapping.nai.target_type = PCANTP_ISOTP_ADDRESSING_PHYSICAL
source_mapping.nai.protocol = PUDS_MSGPROTOCOL_ISO_15765_2_11B_EXTENDED

# 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.source_addr = source_mapping.nai.target_addr
response_mapping.nai.target_addr = source_mapping.nai.source_addr
response_mapping.nai.target_type = source_mapping.nai.target_type
response_mapping.nai.protocol = source_mapping.nai.protocol

# 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)))

# Prepare and send UDS request 22 28 12
request_data = [0x22, 0x58, 0x12]
request = uds_msg()
request.id = source_mapping.can_id
request.dlc = len(request_data)
request.data = bytearray(request_data)

# Send the request
status = objPCANUds.Write_2013(client_handle, request)
print("Send UDS request: %s" % (UDS_STATUS_OK_KO(status)))

# Receive the response
response = uds_msg()
status = objPCANUds.Read_2013(client_handle, response)
print(response)
** Edit by ADMIN **
READ the Forum Rules - post Code only in the needed Format

Kevin1
Posts: 14
Joined: Sun 2. Jun 2024, 10:40

Re: ISO-TP_FORMAT_EXTENDED is not working

Post by Kevin1 » Mon 17. Jun 2024, 16:10

Hello,

I am totally confused with UDS and ISOTP API.... those are completely complex stuff... would it possible to provide me a very very simple code for ISOTP_FORMAT_EXTENDED communication ? even I don't know if I need to use UDS or ISOTP API.... more confusing is that not sure if I need to use mapping or not. some codes uses mapping and but others are not using Mapping.

F.Vergnaud
Software Development
Software Development
Posts: 305
Joined: Mon 9. Sep 2013, 12:21

Re: ISO-TP_FORMAT_EXTENDED is not working

Post by F.Vergnaud » Wed 19. Jun 2024, 17:13

Hello,

Please keep in mind that explaining ISO standards is out of the scope of this forum. Check Wikipedia or directly ISO-15765 and ISO-14229-1 for more information.

You want to make UDS communications, so you should stick to using PCAN-UDS API only. If you don't understand how ISOTP works do not use PCAN-ISO-TP and let PCAN-UDS API configure and use it for you.
You can check samples 05_server_simulator and 06_client_all_request for a complete and working example of UDS communication between a client and a simulated ECU (using 11 bit Normal addressing).
The only change for your usecase is to configure mappings with EXTENDED addressing.
Your code extract is OK on that matter.

You'll find below your sample updated with the correct UDS request:

Code: Select all

import os
import sys
import copy
from time import sleep
from PCAN_UDS_2013 import *



# 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))


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_PCIBUS1 # 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)))

TESTER_ID=0x6f1 
ECU_ID=0x612

# 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.source_addr = PUDS_ISO_15765_4_ADDR_TEST_EQUIPMENT
source_mapping.nai.target_addr = 0x12
source_mapping.nai.target_type = PCANTP_ISOTP_ADDRESSING_PHYSICAL
source_mapping.nai.protocol = PUDS_MSGPROTOCOL_ISO_15765_2_11B_EXTENDED

# 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.source_addr = source_mapping.nai.target_addr
response_mapping.nai.target_addr = source_mapping.nai.source_addr
response_mapping.nai.target_type = source_mapping.nai.target_type
response_mapping.nai.protocol = source_mapping.nai.protocol

# 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)))

# Prepare and send UDS request 22 28 12

# Initialize a physical configuration
config_physical = uds_msgconfig()
config_physical.can_id = -1
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

# Execute ReadDataByIdentifier on 0x5812 and wait response
msg_request = uds_msg()
response = uds_msg()
request_confirmation = uds_msg()
data_identifier_count = 1
data_identifiers = (c_uint16 * data_identifier_count) (0x5812)
status = objPCANUds.SvcReadDataByIdentifier_2013(client_handle, config_physical, msg_request, data_identifiers, data_identifier_count)
print("SvcReadDataByIdentifier_2013: %s" %(UDS_STATUS_OK_KO(status)))

if objPCANUds.StatusIsOk_2013(status, PUDS_STATUS_OK, False):
    status = objPCANUds.WaitForService_2013(client_handle, msg_request, response, request_confirmation)
    print(" UDS_SvcReadDataByIdentifier_2013: %i" %(status.value))
    # check response status and handle the response...

objPCANUds.Uninitialize_2013(client_handle)
Best regards,
Fabrice

Kevin1
Posts: 14
Joined: Sun 2. Jun 2024, 10:40

Re: ISO-TP_FORMAT_EXTENDED is not working

Post by Kevin1 » Tue 25. Jun 2024, 18:07

Thanks for your support,
Now it works very well.

Few questions for your modification.
I can't understand why you put source_mapping.can_tx_dlc = 0 and config_physical.can_id = -1
I presume tx_dlc needs to be 8 and config_physical.can_id=0x6f1 ?

and in Normal addressing, why do I need to inactivate source mapping and response mapping as below?
otherwise, I can start communication...

#source_mapping.nai.source_addr = PUDS_ISO_15765_4_ADDR_TEST_EQUIPMENT #0xF1
#source_mapping.nai.target_addr = 0x01

#response_mapping.nai.source_addr = source_mapping.nai.target_addr
#response_mapping.nai.target_addr = source_mapping.nai.source_addr

Post Reply