Page 1 of 1

send a frame faster

Posted: Wed 2. Mar 2022, 13:57
by clem69
Hello,

Is there a way to decrease the transmission time of a frame. because I have to send 16 frames with an interval of 10ms. However with API I cannot go below 3 or 4 seconds for all the frames to be sent correctly.

Thank you

Re: send a frame faster

Posted: Wed 2. Mar 2022, 14:37
by F.Vergnaud
Hello,

PCAN-UDS API transmits UDS message (i.e. segmented ISO-TP messages) as quickly as possible (it can be <1ms).
Yet ISO-TP transmission depends on the receiver configuration (when it transmits flow control frames).
But, honestly, an ECU using a minimum separation time of several seconds would be really odd...

The most probable reason is that you reach a timeout because there is something wrong with your UDS configuration or your communication workflow.

Re: send a frame faster

Posted: Wed 2. Mar 2022, 14:46
by clem69
Thank you

I will look. here is my configuration

my configuration :

Code: Select all

mapping2.can_id = 0xE8;
mapping2.can_id_flow_ctrl = 0x725;
mapping2.can_msgtype = PCANTP_CAN_MSGTYPE_STANDARD;
mapping2.can_tx_dlc = 8;
mapping2.nai.extension_addr = 0;
mapping2.nai.protocol = PUDS_MSGPROTOCOL_ISO_15765_2_11B_NORMAL;
mapping2.nai.source_addr = PUDS_ISO_15765_4_ADDR_TEST_EQUIPMENT; 
mapping2.nai.target_addr = PUDS_ISO_15765_4_ADDR_TEST_EQUIPMENT;
mapping2.nai.target_type = PCANTP_ISOTP_ADDRESSING_PHYSICAL;

status = UDS_AddMapping_2013(channel, &mapping2);
if (!UDS_StatusIsOk_2013(status,PUDS_STATUS_OK, false))
{
	MessagePopup( "Add source_mapping1 failed.", "Error");
}	    

config2.can_id =  0xE8;
config2.can_msgtype = PCANTP_CAN_MSGTYPE_STANDARD;
config2.nai.extension_addr = 0x0;
config2.nai.protocol = PUDS_MSGPROTOCOL_ISO_15765_2_11B_NORMAL;
config2.nai.source_addr = PUDS_ISO_15765_4_ADDR_TEST_EQUIPMENT;
config2.nai.target_addr = PUDS_ISO_15765_4_ADDR_TEST_EQUIPMENT;
config2.nai.target_type = PCANTP_ISOTP[/i]_ADDRESSING_PHYSICAL;
config2.type = PUDS_MSGTYPE_USDT;
to send

Code: Select all

status = UDS_MsgAlloc_2013(&FIAT_msg, config2,8);  
	 
for(i=0;i<8;i++)
{
	FIAT_msg.msg.msgdata.isotp->data[i]=Fiatframe[j];
	j=j+1;

	if(j==128)
	{
		j=0;
	}
}

status = UDS_Write_2013(PCANTP_HANDLE_USBBUS1, &FIAT_msg);

UDS_MsgFree_2013(&FIAT_msg);

Re: send a frame faster

Posted: Wed 2. Mar 2022, 14:56
by F.Vergnaud

Code: Select all

mapping2.nai.source_addr = PUDS_ISO_15765_4_ADDR_TEST_EQUIPMENT; 
mapping2.nai.target_addr = PUDS_ISO_15765_4_ADDR_TEST_EQUIPMENT;
You're using the same value for the source and target addresses... this is wrong. If your ECU has no defined address, arbitrarily use one (for instance 0x01) but nor the same as the source address!

Re: send a frame faster

Posted: Wed 2. Mar 2022, 15:59
by clem69
thank you but the problem persists

I want to send a frame every 10ms so I use an asynchronous timer

unsigned char Fiatframe[129]={
0x87,0x99,0x00,0x00,0x08,0x00,0x00,0xD1,
0x87,0x99,0x00,0x00,0x08,0x00,0x01,0xCC,
0x87,0x99,0x00,0x00,0x08,0x00,0x02,0xEB,
0x87,0x99,0x00,0x00,0x08,0x00,0x03,0xF6,
0x87,0x99,0x00,0x00,0x08,0x00,0x04,0xA5,
0x87,0x99,0x00,0x00,0x08,0x00,0x05,0xB8,
0x87,0x99,0x00,0x00,0x08,0x00,0x06,0x9F,
0x87,0x99,0x00,0x00,0x08,0x00,0x07,0x82,
0x87,0x99,0x00,0x00,0x08,0x00,0x08,0x39,
0x87,0x99,0x00,0x00,0x08,0x00,0x09,0x24,
0x87,0x99,0x00,0x00,0x08,0x00,0x0A,0x03,
0x87,0x99,0x00,0x00,0x08,0x00,0x0B,0x1E,
0x87,0x99,0x00,0x00,0x08,0x00,0x0C,0x4D,
0x87,0x99,0x00,0x00,0x08,0x00,0x0D,0x50,
0x87,0x99,0x00,0x00,0x08,0x00,0x0E,0x77,
0x87,0x99,0x00,0x00,0x08,0x00,0x0F,0x6A};

int enable_ex8=0;
int count = -1;
int enabled = 1;



int CVICALLBACK MyTimerCallback (int reserved, int theTimerId, int event,
void *callbackData, int eventData1,int eventData2)

{


status = UDS_MsgAlloc_2013(&FIAT_msg, config2,8);

for(i=0;i<8;i++)
{
FIAT_msg.msg.msgdata.isotp->data=Fiatframe[j];
j=j+1;

if(j==128)
{
j=0;
}

}

status = UDS_Write_2013(PCANTP_HANDLE_USBBUS1, &FIAT_msg);

UDS_MsgFree_2013(&FIAT_msg);


return 0;
}



frame received
E8 87 99 0 0 8 0 F 6A the seventh byte is a counter which should normally increase by 1 of 0 to f
E8 87 99 0 0 8 0 5 B8
E8 87 99 0 0 8 0 B 1E
E8 87 99 0 0 8 0 1 CC
E8 87 99 0 0 8 0 7 82
E8 87 99 0 0 8 0 D 50
E8 87 99 0 0 8 0 3 F6
E8 87 99 0 0 8 0 9 24
E8 87 99 0 0 8 0 F 6A
E8 87 99 0 0 8 0 5 B8
E8 87 99 0 0 8 0 B 1E
E8 87 99 0 0 8 0 1 CC

Here, this is not the case. at first I thought it came from CVI but I notice that the frames received are all displayed at the same speed in my table
regardless of the speed of the timer. I wonder if 10ms to execute the sending code is not too fast.

Re: send a frame faster

Posted: Wed 2. Mar 2022, 17:42
by F.Vergnaud
I fear that you are not doing UDS communication the right way..
Are you expecting a UDS response to your request ? Based on the logs, I guess you want to make a UDS LinkControl request, isn't it?
If not consider using directly PCAN-ISO-TP functions.

In the standard, there are indeed mechanisms that prevent to write a new UDS request if one is already pending.
A request is marked as "Pending" by the API if a response to a request is not yet received (response's target address must match request's source address and UDS service ID must match).

Your timer CallBack should do quite the same as in the included samples:
1- write the request (UDS_Write_2013 or UDS_SvcLinkControl_2013)
2- assert the result is OK
3- call UDS_WaitForService_2013
4- assert the result is OK
On standard conditions, this workflow should take only a few milliseconds.

If, at some point the result is not OK, you need to figure out the reason based on the status code and fix the issue first.

Re: send a frame faster

Posted: Wed 2. Mar 2022, 17:45
by F.Vergnaud
also this line of code should lead to major memory problems:

Code: Select all

 FIAT_msg.msg.msgdata.isotp->data=Fiatframe[j];
data is memory allocated by our API, and you modify it with a constant. Considering using memcpy to initialize the data.

Re: send a frame faster

Posted: Thu 3. Mar 2022, 09:17
by clem69
Thank you.
What do you say by assert is ok.

for(i=0;i<8;i++)
{
FIAT_msg.msg.msgdata.can->data=Fiatframe[j];
j=j+1;

if(j==128)
{
j=0;
}

}

status = UDS_Write_2013(PCANTP_HANDLE_USBBUS1, &FIAT_msg);
if (UDS_StatusIsOk_2013(status,0,0))
{

UDS_WaitForSingleMessage_2013(PCANTP_HANDLE_USBBUS1, &FIAT_msg, true, 10,
10, &confirmation);

if (UDS_StatusIsOk_2013(status,0,0))
{
//MessageBox(NULL, "Response was received", "Success", MB_OK);
UDS_MsgFree_2013(&response);
UDS_MsgFree_2013(&request_confirmation);

Re: send a frame faster

Posted: Thu 3. Mar 2022, 11:32
by F.Vergnaud
Hello,

You need to check the result all your API calls
Here is a corrected sample based on your input:

Code: Select all

    unsigned char Fiatframe[129] = {
        0x87,0x99,0x00,0x00,0x08,0x00,0x00,0xD1,
        0x87,0x99,0x00,0x00,0x08,0x00,0x01,0xCC,
        0x87,0x99,0x00,0x00,0x08,0x00,0x02,0xEB,
        0x87,0x99,0x00,0x00,0x08,0x00,0x03,0xF6,
        0x87,0x99,0x00,0x00,0x08,0x00,0x04,0xA5,
        0x87,0x99,0x00,0x00,0x08,0x00,0x05,0xB8,
        0x87,0x99,0x00,0x00,0x08,0x00,0x06,0x9F,
        0x87,0x99,0x00,0x00,0x08,0x00,0x07,0x82,
        0x87,0x99,0x00,0x00,0x08,0x00,0x08,0x39,
        0x87,0x99,0x00,0x00,0x08,0x00,0x09,0x24,
        0x87,0x99,0x00,0x00,0x08,0x00,0x0A,0x03,
        0x87,0x99,0x00,0x00,0x08,0x00,0x0B,0x1E,
        0x87,0x99,0x00,0x00,0x08,0x00,0x0C,0x4D,
        0x87,0x99,0x00,0x00,0x08,0x00,0x0D,0x50,
        0x87,0x99,0x00,0x00,0x08,0x00,0x0E,0x77,
        0x87,0x99,0x00,0x00,0x08,0x00,0x0F,0x6A };

    int enable_ex8 = 0;

    uds_status status;
    cantp_handle channel = PCANTP_HANDLE_USBBUS1;
    uds_msgconfig requestconfig;
    uds_mapping mapping_tester_to_ecu, mapping_ecu_to_tester;

    status = UDS_Initialize_2013(channel, PCANTP_BAUDRATE_500K);
    if (!UDS_StatusIsOk_2013(status, PUDS_STATUS_OK, false)) {
        return;
    }
    // add mapping to support communication from Tester to ECU
    memset(&mapping_tester_to_ecu, 0, sizeof(mapping_tester_to_ecu));
    mapping_tester_to_ecu.can_id = 0xE8;
    mapping_tester_to_ecu.can_id_flow_ctrl = 0x725;
    mapping_tester_to_ecu.can_msgtype = PCANTP_CAN_MSGTYPE_STANDARD;
    mapping_tester_to_ecu.can_tx_dlc = 8;
    mapping_tester_to_ecu.nai.extension_addr = 0;
    mapping_tester_to_ecu.nai.protocol = PUDS_MSGPROTOCOL_ISO_15765_2_11B_NORMAL;
    mapping_tester_to_ecu.nai.source_addr = PUDS_ISO_15765_4_ADDR_TEST_EQUIPMENT;
    mapping_tester_to_ecu.nai.target_addr = 0x01;
    mapping_tester_to_ecu.nai.target_type = PCANTP_ISOTP_ADDRESSING_PHYSICAL;
    status = UDS_AddMapping_2013(channel, &mapping_tester_to_ecu);
    if (!UDS_StatusIsOk_2013(status, PUDS_STATUS_OK, false)) {
        return;
    }
    // add mapping to support communication from ECU to Tester
    mapping_ecu_to_tester = mapping_tester_to_ecu;
    mapping_ecu_to_tester.can_id = mapping_tester_to_ecu.can_id_flow_ctrl;
    mapping_ecu_to_tester.can_id_flow_ctrl = mapping_tester_to_ecu.can_id;
    mapping_ecu_to_tester.nai.source_addr = mapping_tester_to_ecu.nai.target_addr;
    mapping_ecu_to_tester.nai.target_addr = mapping_tester_to_ecu.nai.source_addr;
    status = UDS_AddMapping_2013(channel, &mapping_ecu_to_tester);
    if (!UDS_StatusIsOk_2013(status, PUDS_STATUS_OK, false)) {
        return;
    }

    memset(&requestconfig, 0, sizeof(requestconfig));
    requestconfig.can_id = -1;
    requestconfig.can_msgtype = mapping_tester_to_ecu.can_msgtype;
    requestconfig.nai = mapping_tester_to_ecu.nai;
    requestconfig.type = PUDS_MSGTYPE_USDT;

    for (int j = 0; j < 128; j += 8) {
        uds_msg FIAT_msg;
        memset(&FIAT_msg, 0, sizeof(uds_msg));

        // Allocate TX message with previous configuration
        status = UDS_MsgAlloc_2013(&FIAT_msg, requestconfig, 9);
        if (UDS_StatusIsOk_2013(status, PUDS_STATUS_OK, false)) {
            memcpy(FIAT_msg.msg.msgdata.any->data, &Fiatframe[j], 8);
            status = UDS_Write_2013(channel, &FIAT_msg);
            if (UDS_StatusIsOk_2013(status, PUDS_STATUS_OK, 0))
            {
                uds_msg request_confirmation;
                uds_msg response;
                memset(&request_confirmation, 0, sizeof(uds_msg));
                memset(&response, 0, sizeof(uds_msg));


                // either user a WaitForService or a WaitForMessage function 
                // since request has the flag no_response in the data (0x80)! the WaitForService status should return PUDS_STATUS_SERVICE_NO_MESSAGE.
                //status = UDS_WaitForService_2013(channel, &FIAT_msg, &response, &request_confirmation);
                              
                // Wait for Tx confirmation only
                status = UDS_WaitForSingleMessage_2013(channel, &FIAT_msg, true, 10, 10, &request_confirmation);
                if (UDS_StatusIsOk_2013(status, PUDS_STATUS_OK, 0))
                {
                   // handle what to do with a successfull transmission
                }
                UDS_MsgFree_2013(&request_confirmation);
                UDS_MsgFree_2013(&response);
            }
        }
        UDS_MsgFree_2013(&FIAT_msg);
    }
    status = UDS_Uninitialize_2013(channel);
    // ...

Re: send a frame faster

Posted: Thu 3. Mar 2022, 16:00
by clem69
It's good
thank you very much, your help is very valuable to me.