DS-MPE-CAN2L User Manual Rev A.1
www.diamondsystems.com
Page 18
CAN Transmit Prototype
int can_tx( int can_fd, unsigned char msgType, unsigned int can_id, int
len,unsigned char *data) ;
Assign the appropriate values, before calling the can_tx function.
can0_fd: CAN descriptor, return value from init_can0() function
msgType = MSG_STANDARD ; // or MSG_EXTENDED.
can_id = 0x12;
//if the msgType is MSG_STANDARD then can_id value should be in the range of
0x0 to
0x7FF (11 bit value)
//Else if the msgType is MSG_EXTENDED then can_id value should be in the range
0x0
to 0x1FFFFFFF (29 bit value)
len = 4 //This field can be of 0 to 8 ; // CAN Transmit Data Length (DLC)
data: This field depends on the above CAN Data length len field.
In this case, len is 4 then the CAN message data will be of 4 bytes long and each
byte can have values from 0x0 to 0xFF (8-bits )
data[0] = 0x1A ;
data[1] = 0xAB ;
data[2] = 0x22 ;
data[3] = 0x4D ;
ret_val = can_tx(can0_fd, msgType, can_id, dlc, data) ;
if ( ret_val < 0 )
{
printf("Error while transmitting the CAN message.\n") ;
close(can1_fd) ;
exit(0) ;
}
The above sample code will transmit the CAN standard message with CAN ID=0x12 of data length=4 and
message data = {0x1A, 0xAB, 0x22, 0x4D};
Summary of Contents for Diamond Systems DS-MPE-CAN2L
Page 1: ......