如何在Linux上创建虚拟CAN端口? (C ++) [英] How to create virtual CAN port on linux? (C++)

查看:949
本文介绍了如何在Linux上创建虚拟CAN端口? (C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个程序来模拟CAN端口,以用于另一个大型应用程序的测试.程序应通过此虚拟CAN发送以前记录的数据.任何人都对这种东西有经验吗?

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?

我正在考虑建立虚拟COM,并通过它发送打包在CAN框架中的数据.能行吗?以及如何在Linux上建立虚拟COM?找到了该线程 Linux的虚拟串行端口 但可悲的是,我不知道如何将其实现为程序的源代码(初学者linux用户和linux下的程序员).

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.

推荐答案

您需要 SocketCAN 驱动程序,可在现代Linux发行版(如Ubuntu等)上使用.SocketCAN提供了虚拟CAN端口驱动程序:

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

现在,您可以通过vcan0设备发送和接收CAN帧. Wikipedia文章提供了有关如何使用SocketCAN的简单代码示例.

Now you can send and receive CAN frames over vcan0 device. Wikipedia article provides simple code example on how to use SocketCAN.

出于测试目的,您还需要 can-utils .

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

您可以在 eLinux.org

这篇关于如何在Linux上创建虚拟CAN端口? (C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆