Understanding SocketCAN Linux Unified Interface for CAN Networks

1. Introduction

 

In the past, CAN on Linux was treated as a character device, similar to a serial port. The CAN driver could only communicate with the CAN controller in a point-to-point (P2P) manner, meaning that multiple processes were not allowed to access the same CAN device, and a single application could not control multiple CAN channels simultaneously.
 
   SocketCAN release
 
In 2006, Volkswagen released the open-source SocketCAN software, it is a network device interface based on the Berkeley Socket API. Just as each network interface card (NIC) on a host is treated as one or more network devices, each CAN channel is also regarded as a network device. It is defined under a new protocol family (PF): PF_CAN.

 
 

  The SocketCAN patches were introduced in Linux Kernel 2.6.25, and various CAN controller drivers have been added progressively since then.
 
SocketCAN advantages:
 
Using Kernel 2.6.25 as a milestone, we have summarized the information in a table, making the advantages of SocketCAN immediately clear.

 
 
 

2. SUNCAN SocektCAN Driver

 
Currently, SUNIX SDC series: SUNCAN, also has its own SocketCAN driver. After installing the driver, the module is placed under the directory:


 
 

 
  Network device list
After installing the driver, you will see the newly created SUNCAN devices (can0, can1) appear in the system, They are recognized as network devices, just like Ethernet adapter(eno1) and wireless adapter(wlp0s20f3), as shown in the table and figure below.



 
 

3. SocketCAN Utility: can-utils

 

  can-utils is a collection of Linux command-line utilities designed for working with SocketCAN. Maintained under the Linux-CAN project and hosted on GitHub:
 
https://github.com/linux-can/can-utils
 
This toolset is widely used in automotive and industrial communication testing.
 
With can-utils, developers and engineers can:
 
1).        Monitor and log: CAN frames using tools such as candump.
2).        Data Transmission: CAN frames with cansend or generate traffic using cangen, canfdtest, and cansequence.
3).        Replay: previously recorded traffic with canplayer or convert log files using log2asc and asc2log.
4).        Analyze: bus performance with canbusload and simulate bus errors using canerrsim.
 
SUNIX provides a user guide for performing simple data transmission tests between CAN channels using can-utils. This document is included in the SUNIX SUNCAN integrated installation package, allowing customers to quickly conduct initial testing of the SUNCAN solution.

 
 
 
 

4. Socket Programming

 

Since SocketCAN is based on the Socket API, its coding approach is the same as TCP/IP socket programming. This is a great advantage for most application developers, as socket programming is a widely used technique in network communications and a skill that most developers are already familiar with. Therefore, it is very easy to get started without spending additional time learning third-party APIs.
 
 Official SocketCAN application development guide:
 
Kernel.org:
 
https://docs.kernel.org/networking/can.html
 
https://docs.kernel.org/networking/j1939.html
 
python-can doc:
 
https://python-can.readthedocs.io/en/stable/
 
  SUNCAN SocketCAN sample code
 
The SUNIX SUNCAN integrated installation package includes not only the SUNCAN driver but also SocketCAN and J1939 sample code, providing both C and Python examples to help developers quickly adopt the SUNCAN solution.
For instructions on operating the sample programs, please refer to the tutorial document included in the SUNIX SUNCAN integrated installation package.

 
 

 
C sample project directory:

 

 
Python sample code directory:

 
 

5. Summary

 

SocketCAN offers excellent portability and universality. In general, unless the user’s environment runs a kernel version older than 2.6.25 or a very lightweight Linux distribution without built-in SocketCAN support, it is almost impossible not to use SocketCAN.
 
First, SocketCAN allows multiple processes to access a single CAN channel simultaneously. Second, when users wish to switch CAN hardware, they can do so seamlessly without modifying any software. Third, almost all verification and testing tasks can be performed using can-utils, eliminating the need for additional development.
 
For users, this brings nothing but advantages — there is virtually no incentive to choose the hard-to-maintain character device driver approach.

News & Event

Understanding SocketCAN Linux Unified Interface for CAN Networks

1. Introduction

 

In the past, CAN on Linux was treated as a character device, similar to a serial port. The CAN driver could only communicate with the CAN controller in a point-to-point (P2P) manner, meaning that multiple processes were not allowed to access the same CAN device, and a single application could not control multiple CAN channels simultaneously.
 
   SocketCAN release
 
In 2006, Volkswagen released the open-source SocketCAN software, it is a network device interface based on the Berkeley Socket API. Just as each network interface card (NIC) on a host is treated as one or more network devices, each CAN channel is also regarded as a network device. It is defined under a new protocol family (PF): PF_CAN.

 
 

  The SocketCAN patches were introduced in Linux Kernel 2.6.25, and various CAN controller drivers have been added progressively since then.
 
SocketCAN advantages:
 
Using Kernel 2.6.25 as a milestone, we have summarized the information in a table, making the advantages of SocketCAN immediately clear.

 
 
 

2. SUNCAN SocektCAN Driver

 
Currently, SUNIX SDC series: SUNCAN, also has its own SocketCAN driver. After installing the driver, the module is placed under the directory:


 
 

 
  Network device list
After installing the driver, you will see the newly created SUNCAN devices (can0, can1) appear in the system, They are recognized as network devices, just like Ethernet adapter(eno1) and wireless adapter(wlp0s20f3), as shown in the table and figure below.



 
 

3. SocketCAN Utility: can-utils

 

  can-utils is a collection of Linux command-line utilities designed for working with SocketCAN. Maintained under the Linux-CAN project and hosted on GitHub:
 
https://github.com/linux-can/can-utils
 
This toolset is widely used in automotive and industrial communication testing.
 
With can-utils, developers and engineers can:
 
1).        Monitor and log: CAN frames using tools such as candump.
2).        Data Transmission: CAN frames with cansend or generate traffic using cangen, canfdtest, and cansequence.
3).        Replay: previously recorded traffic with canplayer or convert log files using log2asc and asc2log.
4).        Analyze: bus performance with canbusload and simulate bus errors using canerrsim.
 
SUNIX provides a user guide for performing simple data transmission tests between CAN channels using can-utils. This document is included in the SUNIX SUNCAN integrated installation package, allowing customers to quickly conduct initial testing of the SUNCAN solution.

 
 
 
 

4. Socket Programming

 

Since SocketCAN is based on the Socket API, its coding approach is the same as TCP/IP socket programming. This is a great advantage for most application developers, as socket programming is a widely used technique in network communications and a skill that most developers are already familiar with. Therefore, it is very easy to get started without spending additional time learning third-party APIs.
 
 Official SocketCAN application development guide:
 
Kernel.org:
 
https://docs.kernel.org/networking/can.html
 
https://docs.kernel.org/networking/j1939.html
 
python-can doc:
 
https://python-can.readthedocs.io/en/stable/
 
  SUNCAN SocketCAN sample code
 
The SUNIX SUNCAN integrated installation package includes not only the SUNCAN driver but also SocketCAN and J1939 sample code, providing both C and Python examples to help developers quickly adopt the SUNCAN solution.
For instructions on operating the sample programs, please refer to the tutorial document included in the SUNIX SUNCAN integrated installation package.

 
 

 
C sample project directory:

 

 
Python sample code directory:

 
 

5. Summary

 

SocketCAN offers excellent portability and universality. In general, unless the user’s environment runs a kernel version older than 2.6.25 or a very lightweight Linux distribution without built-in SocketCAN support, it is almost impossible not to use SocketCAN.
 
First, SocketCAN allows multiple processes to access a single CAN channel simultaneously. Second, when users wish to switch CAN hardware, they can do so seamlessly without modifying any software. Third, almost all verification and testing tasks can be performed using can-utils, eliminating the need for additional development.
 
For users, this brings nothing but advantages — there is virtually no incentive to choose the hard-to-maintain character device driver approach.

News & Event

Understanding SocketCAN Linux Unified Interface for CAN Networks

1. Introduction

 

In the past, CAN on Linux was treated as a character device, similar to a serial port. The CAN driver could only communicate with the CAN controller in a point-to-point (P2P) manner, meaning that multiple processes were not allowed to access the same CAN device, and a single application could not control multiple CAN channels simultaneously.
 
   SocketCAN release
 
In 2006, Volkswagen released the open-source SocketCAN software, it is a network device interface based on the Berkeley Socket API. Just as each network interface card (NIC) on a host is treated as one or more network devices, each CAN channel is also regarded as a network device. It is defined under a new protocol family (PF): PF_CAN.

 
 

  The SocketCAN patches were introduced in Linux Kernel 2.6.25, and various CAN controller drivers have been added progressively since then.
 
SocketCAN advantages:
 
Using Kernel 2.6.25 as a milestone, we have summarized the information in a table, making the advantages of SocketCAN immediately clear.

 
 
 

2. SUNCAN SocektCAN Driver

 
Currently, SUNIX SDC series: SUNCAN, also has its own SocketCAN driver. After installing the driver, the module is placed under the directory:


 
 

 
  Network device list
After installing the driver, you will see the newly created SUNCAN devices (can0, can1) appear in the system, They are recognized as network devices, just like Ethernet adapter(eno1) and wireless adapter(wlp0s20f3), as shown in the table and figure below.



 
 

3. SocketCAN Utility: can-utils

 

  can-utils is a collection of Linux command-line utilities designed for working with SocketCAN. Maintained under the Linux-CAN project and hosted on GitHub:
 
https://github.com/linux-can/can-utils
 
This toolset is widely used in automotive and industrial communication testing.
 
With can-utils, developers and engineers can:
 
1).        Monitor and log: CAN frames using tools such as candump.
2).        Data Transmission: CAN frames with cansend or generate traffic using cangen, canfdtest, and cansequence.
3).        Replay: previously recorded traffic with canplayer or convert log files using log2asc and asc2log.
4).        Analyze: bus performance with canbusload and simulate bus errors using canerrsim.
 
SUNIX provides a user guide for performing simple data transmission tests between CAN channels using can-utils. This document is included in the SUNIX SUNCAN integrated installation package, allowing customers to quickly conduct initial testing of the SUNCAN solution.

 
 
 
 

4. Socket Programming

 

Since SocketCAN is based on the Socket API, its coding approach is the same as TCP/IP socket programming. This is a great advantage for most application developers, as socket programming is a widely used technique in network communications and a skill that most developers are already familiar with. Therefore, it is very easy to get started without spending additional time learning third-party APIs.
 
 Official SocketCAN application development guide:
 
Kernel.org:
 
https://docs.kernel.org/networking/can.html
 
https://docs.kernel.org/networking/j1939.html
 
python-can doc:
 
https://python-can.readthedocs.io/en/stable/
 
  SUNCAN SocketCAN sample code
 
The SUNIX SUNCAN integrated installation package includes not only the SUNCAN driver but also SocketCAN and J1939 sample code, providing both C and Python examples to help developers quickly adopt the SUNCAN solution.
For instructions on operating the sample programs, please refer to the tutorial document included in the SUNIX SUNCAN integrated installation package.

 
 

 
C sample project directory:

 

 
Python sample code directory:

 
 

5. Summary

 

SocketCAN offers excellent portability and universality. In general, unless the user’s environment runs a kernel version older than 2.6.25 or a very lightweight Linux distribution without built-in SocketCAN support, it is almost impossible not to use SocketCAN.
 
First, SocketCAN allows multiple processes to access a single CAN channel simultaneously. Second, when users wish to switch CAN hardware, they can do so seamlessly without modifying any software. Third, almost all verification and testing tasks can be performed using can-utils, eliminating the need for additional development.
 
For users, this brings nothing but advantages — there is virtually no incentive to choose the hard-to-maintain character device driver approach.

News & Event

Understanding SocketCAN Linux Unified Interface for CAN Networks

1. Introduction

 

In the past, CAN on Linux was treated as a character device, similar to a serial port. The CAN driver could only communicate with the CAN controller in a point-to-point (P2P) manner, meaning that multiple processes were not allowed to access the same CAN device, and a single application could not control multiple CAN channels simultaneously.
 
   SocketCAN release
 
In 2006, Volkswagen released the open-source SocketCAN software, it is a network device interface based on the Berkeley Socket API. Just as each network interface card (NIC) on a host is treated as one or more network devices, each CAN channel is also regarded as a network device. It is defined under a new protocol family (PF): PF_CAN.

 
 

  The SocketCAN patches were introduced in Linux Kernel 2.6.25, and various CAN controller drivers have been added progressively since then.
 
SocketCAN advantages:
 
Using Kernel 2.6.25 as a milestone, we have summarized the information in a table, making the advantages of SocketCAN immediately clear.

 
 
 

2. SUNCAN SocektCAN Driver

 
Currently, SUNIX SDC series: SUNCAN, also has its own SocketCAN driver. After installing the driver, the module is placed under the directory:


 
 

 
  Network device list
After installing the driver, you will see the newly created SUNCAN devices (can0, can1) appear in the system, They are recognized as network devices, just like Ethernet adapter(eno1) and wireless adapter(wlp0s20f3), as shown in the table and figure below.



 
 

3. SocketCAN Utility: can-utils

 

  can-utils is a collection of Linux command-line utilities designed for working with SocketCAN. Maintained under the Linux-CAN project and hosted on GitHub:
 
https://github.com/linux-can/can-utils
 
This toolset is widely used in automotive and industrial communication testing.
 
With can-utils, developers and engineers can:
 
1).        Monitor and log: CAN frames using tools such as candump.
2).        Data Transmission: CAN frames with cansend or generate traffic using cangen, canfdtest, and cansequence.
3).        Replay: previously recorded traffic with canplayer or convert log files using log2asc and asc2log.
4).        Analyze: bus performance with canbusload and simulate bus errors using canerrsim.
 
SUNIX provides a user guide for performing simple data transmission tests between CAN channels using can-utils. This document is included in the SUNIX SUNCAN integrated installation package, allowing customers to quickly conduct initial testing of the SUNCAN solution.

 
 
 
 

4. Socket Programming

 

Since SocketCAN is based on the Socket API, its coding approach is the same as TCP/IP socket programming. This is a great advantage for most application developers, as socket programming is a widely used technique in network communications and a skill that most developers are already familiar with. Therefore, it is very easy to get started without spending additional time learning third-party APIs.
 
 Official SocketCAN application development guide:
 
Kernel.org:
 
https://docs.kernel.org/networking/can.html
 
https://docs.kernel.org/networking/j1939.html
 
python-can doc:
 
https://python-can.readthedocs.io/en/stable/
 
  SUNCAN SocketCAN sample code
 
The SUNIX SUNCAN integrated installation package includes not only the SUNCAN driver but also SocketCAN and J1939 sample code, providing both C and Python examples to help developers quickly adopt the SUNCAN solution.
For instructions on operating the sample programs, please refer to the tutorial document included in the SUNIX SUNCAN integrated installation package.

 
 

 
C sample project directory:

 

 
Python sample code directory:

 
 

5. Summary

 

SocketCAN offers excellent portability and universality. In general, unless the user’s environment runs a kernel version older than 2.6.25 or a very lightweight Linux distribution without built-in SocketCAN support, it is almost impossible not to use SocketCAN.
 
First, SocketCAN allows multiple processes to access a single CAN channel simultaneously. Second, when users wish to switch CAN hardware, they can do so seamlessly without modifying any software. Third, almost all verification and testing tasks can be performed using can-utils, eliminating the need for additional development.
 
For users, this brings nothing but advantages — there is virtually no incentive to choose the hard-to-maintain character device driver approach.

News & Event

Subscribe SUNIX eDM

Subscribe SUNIX eDM

Subscribe SUNIX eDM

Subscribe SUNIX eDM

Back to top
返回頂部
返回頂部