Page 1 of 1

Wrong PIDs in ReadDataByPeriodicIdentifier

Posted: Wed 28. Aug 2019, 14:50
by ValeV
I call service ReadDataByPeriodicIdentifier at medium rate, wanting to read 0xF200 and 0xF204.

My code:

Code: Select all

string TC_UDS_266()
{
    string s;
    TPUDSStatus r;
    unique_ptr<PUDSClass> pcan(new PUDSClass());

    if (pcan->openDevice(PUDS_USBBUS1, PUDS_BAUD_250K) != PUDS_ERROR_OK)
    {
        cout << "UDS-266: failed to initialize" << endl;
        return "UDS-266: FAILED";
    }

    cout << "initialized" << endl;

    TPUDSMsg requestConfirmation;
    TPUDSMsg response;
    memset(&requestConfirmation, 0, sizeof(TPUDSMsg));
    memset(&response, 0, sizeof(TPUDSMsg));

    WORD bufferLength = 2;
    BYTE buffer[bufferLength] = {};
    buffer[0] = '00';
    buffer[1] = '04';

    r = pcan->SvcReadDataByPeriodicIdentifier(&pcan->request, 0x01, buffer, bufferLength);
    if (r == PUDS_ERROR_OK)
        r = pcan->WaitForService(&response, &requestConfirmation);
    if (r == PUDS_ERROR_OK)
    {
        cout << "Response was received" << endl;
        //cout << "SID: " << response.DATA.POSITIVE.SI << endl;

        s = "UDS-266: PASSED";
    }
    else
    {
        cout << "An error occured" << endl;
        s = "UDS-266: FAILED";
    }

    return s;
}
Problem is, when I'm watching data on other device, i see these 2 messages:
Send: [04 2A 01 30 34]
Received: [03 7F 2A 7F]

The response is ok, since this service is no allowed in default session, but I can't understand why it sends "... 30 34]" and not "...00 04]". Even if I set buffer (PIDs) to ["A0", "B4"], it still sends "30" and "34". :?

Re: Wrong PIDs in ReadDataByPeriodicIdentifier

Posted: Wed 28. Aug 2019, 15:11
by F.Vergnaud
Dear Valev,

The following code is incorrect, as you are confusing an integer hex value with a char value (char '04' is 0x34 in ascii):

Code: Select all

    WORD bufferLength = 2;
    BYTE buffer[bufferLength] = {};
    buffer[0] = '00';
    buffer[1] = '04';
Also your code should not compile without a const value in front of "WORD bufferLength = 2;"

Here is the corrected version:

Code: Select all

    const WORD bufferLength = 2;
    BYTE buffer[bufferLength] = {};
    buffer[0] = 0x00;
    buffer[1] = 0x04;

Re: Wrong PIDs in ReadDataByPeriodicIdentifier

Posted: Wed 28. Aug 2019, 15:48
by ValeV
Thank you, easy fix for more experienced programmers. :)
Also your code should not compile without a const value in front of "WORD bufferLength = 2;"
I have no problems even if I don't have "const" there. In your API user manual, in example, there also is no "const" there. Are you sure it's needed?

Re: Wrong PIDs in ReadDataByPeriodicIdentifier

Posted: Wed 28. Aug 2019, 15:57
by F.Vergnaud
It may depends on your compiler but on VS2019 it doesn't.

Re: Wrong PIDs in ReadDataByPeriodicIdentifier

Posted: Thu 29. Aug 2019, 08:24
by ValeV
I see, I have GCC, no problems here. Will keep in might if anything goes wrong. Thank you again for the help.