How to create virtual CAN port on linux? (C++)

跟風遠走 提交于 2019-11-28 20:35:11

问题


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?

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).

Would love to read your experience and suggestions.


回答1:


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

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.

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

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



来源:https://stackoverflow.com/questions/21022749/how-to-create-virtual-can-port-on-linux-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!