I want to create a program that will emulate the CAN port for testing another large application. The program should send previously recorded data via the virtual CAN port. Does anyone have experience with such things?

I think to install a virtual COM and send data packed into a CAN frame through it. Can this option be a success ?? I found a discussion of the Virtual Serial Port for Linux, but unfortunately I don’t understand how it can be implemented in the program (I’m a novice Linux user, and I’m also a novice Linux pogromist)

I would like to read your experience and suggestions.


the question is a translation

    1 answer 1

    You just need a SocketCAN driver, business sausage: 3 it is available in modern distributions such as Ubuntu and Debian, etc. SocketCAN provides the driver virtual CAN port:

    sudo modprobe vcan sudo ip link add dev vcan0 type vcan sudo ip link set up vcan0 

    Now you can send and receive CAN frames through the vcan0 device. The Wikipedia article provides a simple example of code and explains how to use SocketCAN.

    You will also need can-utils to test the program.

    You will also find more information about SocketCAN and its use at eLinux.org .

    An example of working with a physical CAN port (device):

     // поднять интерфейс CAN1 sudo modprobe can sudo ip link set can0 type can bitrate 125000 sudo ip link set can0 up // отправка сообщения с устройства sudo cansend can0 '111#11aa' // приём данных sudo candump can0 

    Translator's note, SocketCAN is built into the Linux kernel and uses the Linux networking subsystem.