O'Reilly logo

GNU/Linux Rapid Embedded Programming by Rodolfo Giometti

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The raw CAN bus

In a Linux-based system, we can use the SocketCAN implementation to manage these devices and then exchange data between them. It uses the Berkeley socket API and the Linux network stack (and raw sockets) to implement CAN device drivers as network interfaces to allow programmers familiar with network programming to easily learn how to use CAN sockets.

Note

See the Documentation/networking/can.txt file in the kernel's repository for more information.

Here is a simplified example in C language regarding how to open a SocketCAN socket:

int s; char *ifname; struct sockaddr_can addr; struct can_frame frame; struct ifreq ifr; int ret; /* Open the PF_CAN socket */ s = socket(PF_CAN, SOCK_RAW, CAN_RAW); if (s < 0) { perror("Error while opening ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required