automate ProcessMessageCan string

The free CAN Software API (Application Programming Interface) for Windows®
Post Reply
ross.bledsoe@emerson.com
Posts: 1
Joined: Mon 30. Oct 2023, 18:01

automate ProcessMessageCan string

Post by ross.bledsoe@emerson.com » Sat 11. Nov 2023, 03:59

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;
    }
}
Last edited by K.Wagner on Mon 13. Nov 2023, 14:06, edited 1 time in total.
Reason: Code formatting for better reading

K.Wagner
Software Development
Software Development
Posts: 1080
Joined: Wed 22. Sep 2010, 13:36

Re: automate ProcessMessageCan string

Post by K.Wagner » Mon 13. Nov 2023, 15:52

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.
Best regards,
Keneth

Post Reply