如何在linux上创建虚拟CAN端口?(c++)

时间:2022-07-02 15:06:05

I want to create program that would emulate CAN port for testing purposes for another big application. Program should send previously recorded data through this virtual CAN. Anyone has any experience with such thing?

我想要创建一个能够模拟CAN端口的程序,用于其他大型应用程序的测试目的。程序应该通过这个虚拟CAN发送先前记录的数据。有人有这样的经历吗?

I'm thinking to establish virtual COM, and send through it data packed in CAN Frames. Could it work? And how could I establish virtual COM on linux? Found this thread Virtual Serial Port for Linux but sadly I don't get how could it be implemented into source code of program (beginner linux user and programmer under linux).

我正在考虑建立虚拟COM,并通过它发送压缩在CAN帧中的数据。会工作吗?我如何在linux上建立虚拟COM ?为Linux找到了这个线程虚拟串口,但遗憾的是我不知道如何将它实现到程序的源代码中(Linux的初学者和程序员)。

Would love to read your experience and suggestions.

我很乐意阅读你的经验和建议。

1 个解决方案

#1


30  

You need SocketCAN driver, that is available on modern Linux distributions like Ubuntu etc. SocketCAN provides a virtual CAN port driver:

你需要SocketCAN驱动,它可以在现代Linux发行版(如Ubuntu等)上使用。

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 over vcan0 device. Wikipedia article provides simple code example on how to use SocketCAN.

现在您可以发送和接收可以帧在vcan0设备上。Wikipedia文章提供了如何使用SocketCAN的简单代码示例。

You'll also need can-utils for testing purposes.

您还需要can-utils用于测试目的。

You'll find more information about SocketCAN and its usage on eLinux.org

您将在eLinux.org上找到关于SocketCAN及其用法的更多信息

#1


30  

You need SocketCAN driver, that is available on modern Linux distributions like Ubuntu etc. SocketCAN provides a virtual CAN port driver:

你需要SocketCAN驱动,它可以在现代Linux发行版(如Ubuntu等)上使用。

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 over vcan0 device. Wikipedia article provides simple code example on how to use SocketCAN.

现在您可以发送和接收可以帧在vcan0设备上。Wikipedia文章提供了如何使用SocketCAN的简单代码示例。

You'll also need can-utils for testing purposes.

您还需要can-utils用于测试目的。

You'll find more information about SocketCAN and its usage on eLinux.org

您将在eLinux.org上找到关于SocketCAN及其用法的更多信息