Page 1 of 1

automate ProcessMessageCan string

Posted: Sat 11. Nov 2023, 03:59
by ross.bledsoe@emerson.com
I have modified the manualread and manualwrite functions to read and write text strings sent and received from a product I am testing.
I need help reading in the PCAN string dynamically so I can look for data and determine pass/fail criteria. you can see where I hard coded
if(msg.DATA[2]== 77 && msg.DATA[3] == 67 && msg.DATA[4] == 66) //if return string = MCB then enter test mode to determine if the string contained MCB. I want to be able to pass this function variables so I dont have to hard code my msg.DATA

Thanks, Ross

Code: Select all

void ManualRead::ProcessMessageCan(TPCANMsg msg, TPCANTimestamp itsTimeStamp)
{

    UINT64 microsTimestamp = itsTimeStamp.micros + (1000ULL * itsTimeStamp.millis) + (0x100'000'000ULL * 1000ULL * itsTimeStamp.millis_overflow);
    char result[MAX_PATH] = { 0 };
    sprintf_s(result, sizeof(result), "%i", msg.LEN);
    std::cout << "Data: " << GetDataString(msg.DATA, msg.MSGTYPE, msg.LEN) << "\n";

    if(msg.DATA[2]== 77 && msg.DATA[3] == 67 && msg.DATA[4] == 66) //if return string = MCB then enter test mode

}


std::string ManualRead::GetDataString(BYTE data[], TPCANMessageType msgType, int dataLength)
{
    if ((msgType & PCAN_MESSAGE_RTR) == PCAN_MESSAGE_RTR)
        return "Remote Request";
    else
    {
        char strTemp[MAX_PATH] = { 0 };
        std::string result = "";
        for (int i = 0; i < dataLength; i++)
        {
            sprintf_s(strTemp, sizeof(strTemp), "%02X ", data[i]);
            result.append(strTemp);
        }

        return result;
    }
}

Re: automate ProcessMessageCan string

Posted: Mon 13. Nov 2023, 15:52
by K.Wagner
Hello,

If understood well, then this question is outside the scope of support for the API. The PCAN-Basic API helps you communicating over CAN, this is, reading from and writing to a CAN network, and this is working well as we can infer from your post. How the data being received is to be interpreted is up to the API user.

Checking some data bytes to have a special character sequence for taking some processing decision (for example a string like "MCB") is a general programming question that doesn't have anything to do with CAN. We recommend to visit a programming forum and just ask for searching a pattern in a byte array.

Thanks for your understanding.