Click here to Skip to main content
15,887,944 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to print TPCANMsg.ID and DATA of following struct


C++
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;

Any idea?
Posted
Updated 3-Nov-15 22:19pm
v2
Comments
CPallini 4-Nov-15 3:21am    
What is your doubt?
Ramiien 4-Nov-15 3:29am    
M idea was that structname.element is the way to print value. e.g cout << TPCANMsg.ID to print the ID of the CAN. but it is not working. i dont know why?
Richard MacCutchan 4-Nov-15 4:19am    
What does "not working" mean? Please edit your question, show the code and explain exactly what is happening.
Jochen Arndt 4-Nov-15 4:19am    
TPCANMsg is the type. You must use a variable of that type and can then access the elements. Example:

TPCANMsg msg;
CAN_Read(handle, &msg, &timeStamp);
cout << msg.ID;
[no name] 4-Nov-15 4:44am    
No it won't work because it won't compile. We need your actual code snippet to understand your question but Jochen Arndt has told you exactly how to do it.

1 solution

To print it you must understand what the values oft data types are representing. It is best to write converter function for that.

Blueprint-Example:
C++
const char*  TPCANMessageTypeToText( const TPCANMessageType* typ ) {
  if( * typ = 0x00 ) { //PCAN_MESSAGE_STANDARD
    return "The PCAN message is a CAN Standard Frame (11-bit identifier)";
  }
//all the rest
}

The value I have found here.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900