PCAN-UDS API Version-2.3.0.256
When I used UDSApi.AddMapping_2013 function to mapping CANID(request 0X784,Response 0x 78C) and used the sample (UDS specification page 166 with C# )
and then send the uds diagnostic session control message with function UDSApi.SvcDiagnosticSessionControl_2013(sample from page260)
and after running the code ,initialization and mapping seems successful ,but arose error(PUDS_STATUS_SERVICE_TX_ERROR) when sent the diagnostic session message
Below is my code
Code: Select all
private void Init_Click(object sender, EventArgs e)
{
StringBuilder buffer = new StringBuilder(BUFFER_SIZE);
stsResult = UDSApi.GetValue_2013(cantp_handle.PCANTP_HANDLE_NONEBUS, uds_parameter.PUDS_PARAMETER_API_VERSION, buffer, BUFFER_SIZE);
MessageBox.Show("PCAN-UDS API Version - " + buffer.ToString());
stsResult = UDSApi.Initialize_2013(m_clientHandle, m_baudrate, (cantp_hwtype)0, 0, 0);
if(!UDSApi.StatusIsOk_2013(stsResult))
{
MessageBox.Show(UDS_STATUS_OK_KO(stsResult));
}
PUDS_SetRequestResponse_CANID();
}
private void ReadMsg_Click(object sender, EventArgs e)
{
//Thread uds_client = new Thread(() => uds_client_task());
//uds_client.Start();
UDS_BOOT_Process1();
}
public void PUDS_SetRequestResponse_CANID()
{
UInt16 mapping_count;
uds_mapping[] mapping_buffer = new uds_mapping[BUFFER_SIZE];
uds_mapping request_mapping = new uds_mapping();
request_mapping.can_id = 0x784;
request_mapping.can_id_flow_ctrl = 0x78C;
request_mapping.can_msgtype = cantp_can_msgtype.PCANTP_CAN_MSGTYPE_STANDARD;
request_mapping.nai.extension_addr = 0;
request_mapping.nai.protocol = uds_msgprotocol.PUDS_MSGPROTOCOL_ISO_15765_2_11B_NORMAL;
request_mapping.can_tx_dlc = 8;
request_mapping.nai.source_addr =(UInt16)uds_address.PUDS_ADDRESS_ISO_15765_4_ADDR_TEST_EQUIPMENT;
request_mapping.nai.target_addr = (UInt16)uds_address.PUDS_ADDRESS_ISO_15765_4_ADDR_ECU_1;
request_mapping.nai.target_type = cantp_isotp_addressing.PCANTP_ISOTP_ADDRESSING_PHYSICAL;
uds_mapping response_mapping;
response_mapping = request_mapping;
response_mapping.can_id = request_mapping.can_id_flow_ctrl;
response_mapping.can_id_flow_ctrl = request_mapping.can_id;
response_mapping.nai.source_addr = request_mapping.nai.target_addr;
response_mapping.nai.target_addr = request_mapping.nai.source_addr;
mapping_count = 0;
uds_status status;
status = UDSApi.AddMapping_2013(m_clientHandle, ref request_mapping);
if (UDSApi.StatusIsOk_2013(status))
{
MessageBox.Show("Add request mapping", "Success");
}
else
{
MessageBox.Show("Failed to add request mapping", "Error");
}
status = UDSApi.AddMapping_2013(cantp_handle.PCANTP_HANDLE_USBBUS1, ref response_mapping);
if (UDSApi.StatusIsOk_2013(status))
{
MessageBox.Show("Add response mapping", "Success");
}
else
{
MessageBox.Show("Failed to add response mapping", "Error");
}
status = UDSApi.GetMappings_2013(m_clientHandle, mapping_buffer, (UInt16)BUFFER_SIZE, ref mapping_count);
bool mapp_sur= mapping_list_contains(ref mapping_buffer, mapping_count, ref request_mapping);
bool mapp_res= mapping_list_contains(ref mapping_buffer, mapping_count, ref response_mapping);
}
private void UDS_BOOT_Process1()
{
uds_status result;
uds_msg request = new uds_msg();
uds_msg request_confirmation = new uds_msg();
uds_msg response = new uds_msg();
uds_msgconfig config = new uds_msgconfig();
// Set request message configuration
config.can_msgtype = cantp_can_msgtype.PCANTP_CAN_MSGTYPE_STANDARD;
config.nai.extension_addr = 0x0;
config.nai.protocol = uds_msgprotocol.PUDS_MSGPROTOCOL_ISO_15765_2_11B_NORMAL;
config.nai.source_addr = (UInt16)uds_address.PUDS_ADDRESS_ISO_15765_4_ADDR_TEST_EQUIPMENT;
config.nai.target_addr = (UInt16)uds_address.PUDS_ADDRESS_ISO_15765_4_ADDR_ECU_1;
config.nai.target_type = cantp_isotp_addressing.PCANTP_ISOTP_ADDRESSING_PHYSICAL;
//config.type = uds_msgtype.PUDS_MSGTYPE_USDT;
// Sends a physical DiagnosticSessionControl message
result = UDSApi.SvcDiagnosticSessionControl_2013(m_clientHandle, config,
out request, UDSApi.uds_svc_param_dsc.PUDS_SVC_PARAM_DSC_ECUPS);
if (UDSApi.StatusIsOk_2013(result))
result = UDSApi.WaitForService_2013(cantp_handle.PCANTP_HANDLE_USBBUS1, ref request, out
response, out request_confirmation);
if (UDSApi.StatusIsOk_2013(result))
MessageBox.Show("Response was received", "Success");
else
// An error occurred
MessageBox.Show("An error occurred", "Error");
// Free structures
UDSApi.MsgFree_2013(ref request);
UDSApi.MsgFree_2013(ref response);
UDSApi.MsgFree_2013(ref request_confirmation);
}
static bool mapping_list_contains(ref uds_mapping[] mapping_list, UInt16 mapping_list_size, ref uds_mapping searched_mapping)
{
bool res = false;
for (int i = 0; i < mapping_list_size; i++)
{
// If unique identifier are the same, the mapping is in the list
if (mapping_list[i].uid == searched_mapping.uid)
{
res = true;
break;
}
}
return res;
}
thanks !