DS-MPE-CAN2L User Manual Rev A.1
www.diamondsystems.com
Page 16
9. CONFIGURE AND MANAGE THE PORTS IN LINUX
The CANLib library provides the set of APIs to configure and manage the CAN ports. The CANLib library can be
used to build the CAN user application. It is a shared library built on top of Linux platform and using the driver
provided functionality. To compile the CANLib shared library, use the below command
cd CANLib
make
All the CAN APIs prototypes are defined in the can.h file. This file is located in the CANLib directory. Include the
can.h file in the user application to use all these APIs.
9.1
API to Configure and Manage CAN Ports
init_can0()
&
init_can1()
: These function will initialize the CAN#0 & CAN#1 ports respectively.
Both these functions return the CAN file descriptor (fd). The return value of these functions should be retained
for all subsequent APIs. Its prototypes are defined in the can.h file. Declare two CAN file descriptors and
retains its return values.
#include “can.h”
…
int can0_fd;
int can1_fd;
…
can0_fd
= init_can0() ;
if ( can0_fd < 0 )
{
printf("Error while initializing the CAN#0\n") ;
exit(0) ;
}
…
can1_fd
= init_can1() ;
if ( can1_fd < 0 )
{
printf("Error while initializing the CAN#1\n") ;
exit(0) ;
}
Содержание Diamond Systems DS-MPE-CAN2L
Страница 1: ......