Diamond Systems DS-MPE-CAN2L Podręcznik - Strona 17

Przeglądaj online lub pobierz pdf Podręcznik dla Karta PCI Diamond Systems DS-MPE-CAN2L. Diamond Systems DS-MPE-CAN2L 19 stron.

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};
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.
DS-MPE-CAN2L User Manual Rev A.
www.diamondsystems.com
Page 17