DS-MPE-CAN2L User Manual Rev A.1
www.diamondsystems.com
Page 19
CAN Receive Prototype
int can_rx(int can_fd, unsigned char *msgType, unsigned char *rx_data, unsigned int
*can_id, unsigned char *can_msg_len) ;
Pass the appropriate pointers for calling the can_rx function:
if ( can_rx(can0_fd, &msgType, data, &can_id, &dlc) )
{
If (msgType == MSG_STANDARD )
{
// Received message is CAN Standard Message.
}
else if (msgType == MSG_EXTENDED)
{
// Received message is CAN Extended Message.
}
// dlc : Received CAN Data Length
// can_id : Will contain the CAN Message ID
// Data of dlc length
printf("ID=%x DLC=%d Data : ", can_id, dlc) ;
for (i=0; i< dlc; i++ )
printf("%x ", data[i] ) ;
printf("\n") ;
}
The sample example programs for both transmit and receive can be found in the CANLib directory for the
reference.
9.2
Compiling User Application using CANLib Library
Export the library path using the following command:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path-to-CANLib
To compile the user application, use the following command:
g++ can_app.c
-lCAN
–
L/path-to-CANLib
-o can_app
Summary of Contents for Diamond Systems DS-MPE-CAN2L
Page 1: ......