C++ how to assign a received frame in a variable

This forum covers PCAN-Linux and Linux development issues concerning our products
Post Reply
elpimous12
Posts: 59
Joined: Tue 3. Aug 2021, 23:34

C++ how to assign a received frame in a variable

Post by elpimous12 » Fri 27. Aug 2021, 09:13

Hello,
Testing my c++ code, offline...
Without calls to pcanbasic methods, I need to test my other methods, and I'd like to test with this default received frame.
can_frame = [1002404000a005000000170ff230d181400];

But doesn t work!!
Brackets doesn't seems to be the right method?!!

Just need one ex of this variable alimentation.

Thanks all

Vincent

M.Heidemann
Sales & Support
Sales & Support
Posts: 977
Joined: Fri 20. Sep 2019, 13:31

Re: C++ how to assign a received frame in a variable

Post by M.Heidemann » Fri 27. Aug 2021, 09:30

Hello,

Please use the structure as defined by PCANBasic:
example.png
example.png (5.22 KiB) Viewed 3036 times
example_2.png
example_2.png (17.66 KiB) Viewed 3033 times
Also you should test with an hardware active,
PCANBasic works closely with the driver, which will require
an active hardware to function as intended.

Best Regards

Marvin
---
Marvin Heidemann
PEAK-Support Team

elpimous12
Posts: 59
Joined: Tue 3. Aug 2021, 23:34

Re: C++ how to assign a received frame in a variable

Post by elpimous12 » Fri 27. Aug 2021, 10:26

Hey, Marvin,
I have this process in my code.
My question is :
What is c++ type of requested msg variable?
Is it data[64]?
Can I request 3rd byte as :
Int byte3 = msg.DATA[2]
from a RECEIVED CANFD message

M.Heidemann
Sales & Support
Sales & Support
Posts: 977
Joined: Fri 20. Sep 2019, 13:31

Re: C++ how to assign a received frame in a variable

Post by M.Heidemann » Fri 27. Aug 2021, 10:45

Hello,

The struct for messages is the same regardless of their direction,
see the PCANbasic.h file:

Code: Select all

////////////////////////////////////////////////////////////
// Structure definitions
////////////////////////////////////////////////////////////

// Represents a PCAN message
//
typedef struct tagTPCANMsg
{
    DWORD             ID;      // 11/29-bit message identifier
    TPCANMessageType  MSGTYPE; // Type of the message
    BYTE              LEN;     // Data Length Code of the message (0..8)
    BYTE              DATA[8]; // Data of the message (DATA[0]..DATA[7])
} TPCANMsg;

// Represents a timestamp of a received PCAN message
// Total Microseconds = micros + 1000 * millis + 0x100000000 * 1000 * millis_overflow
//
typedef struct tagTPCANTimestamp
{
    DWORD  millis;             // Base-value: milliseconds: 0.. 2^32-1
    WORD   millis_overflow;    // Roll-arounds of millis
    WORD   micros;             // Microseconds: 0..999
} TPCANTimestamp;

// Represents a PCAN message from a FD capable hardware
//
typedef struct tagTPCANMsgFD
{
    DWORD             ID;       // 11/29-bit message identifier
    TPCANMessageType  MSGTYPE;  // Type of the message
    BYTE              DLC;      // Data Length Code of the message (0..15)
    BYTE              DATA[64]; // Data of the message (DATA[0]..DATA[63])
} TPCANMsgFD;
You can assign the returned byte from the array to an Int, but you'll
have to cast the byte to int.
---
Marvin Heidemann
PEAK-Support Team

elpimous12
Posts: 59
Joined: Tue 3. Aug 2021, 23:34

Re: C++ how to assign a received frame in a variable

Post by elpimous12 » Fri 27. Aug 2021, 20:08

Perfect. Thanks Marvin.
You can close.

Post Reply