问题标签 [socketcan]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
832 浏览

sockets - C - 在 socketCAN 的广播管理器上发送循环消息

我正在使用 socketcan 的广播管理器在 CAN 总线上写一些消息:

此代码工作正常,只需以 100 毫秒的间隔发送 5 条消息,但这不是我想要的。我想发送五个消息(从帧 [0] 到帧 [4])一次,然后以 100 毫秒的间隔继续仅发送最后一帧(帧 [4])。所以 bcm 应该发送:

如果我将 iva2.tv_usec 设置为 100000,它将继续发送所有帧,而我只想发送最后一个帧。我怎么能这样做?我读过添加 TX_COUNTEVT 标志,当计数达到零时,bcm 将生成 TX_EXPIRED 消息。也许我可以处理这个 TX_EXPIRED 消息并根据需要手动修改 bcm 传输?如果以防万一,我可以如何以及在哪里处理这个 TX_EXPIRED 消息?还有其他更简单的方法可以达到我的目标吗?

0 投票
2 回答
4715 浏览

c - SocketCAN:过滤具有某些 CAN ID 的帧不起作用

我正在尝试过滤具有某些 ID 的 CAN 帧,如下所述:https ://landlock.io/linux-doc/landlock-v8/networking/can.html#raw-protocol-sockets-with-can-filters-sock -生的

我的部分代码:

如果我只使用我的四个过滤器中的一个并注释掉其他三个,它会按预期工作。如果我使用所有四个过滤器,它根本不起作用。在那种情况下,我仍然可以在 CANbus 接口上接收所有内容。

所以,我的猜测是我的过滤器以某种方式相互抵消?!我需要更改什么来过滤 CAN ID 0x0D6、0x0D8、0x0E4 和 0x77F?

0 投票
2 回答
498 浏览

c - 确认消息已使用 socketCAN 发送到 CAN 总线

我想确认我的消息已通过 socketCAN 库保存在 CAN 总线上。socketCAN 文档描述了使用 recvmsg() 函数时的这种可能性,我在实现时遇到了问题。

我要实现的功能是确认我的消息赢得了仲裁过程。

0 投票
1 回答
641 浏览

can-bus - Is it possible to imitate arbitration on CAN bus?

Setup

I have two nodes connected to one CAN bus. The first node is a black-box, controlled by some real-time hardware. The second node is a Linux machine with attached PEAK-USB CAN controller:

In order to investigate some problem related to occasional frame loss I want to mimic the CAN arbitration process. To do that I am setting the CAN bit-rate to 125Kb/s and flooding it with random CAN frames with 1ms delay, controlling the bus load with canbusload from can-utils. I also monitor CAN error frames running candump can0,0~0,#ffffffff and the overall can statistics with ip -s -d link show can:

Problem

Now the problem is that the given setup works for hours with zero collisions (arbitration) or any other kind of error frames when the load is at 99%. When I reduce the delay to increase the bus load write(2) fails with either "ENOBUFS 105 No buffer space available" or "EAGAIN 11 Resource temporarily unavailable" - the actual error depends on whether I modify the qlen parameter or set to to defaults.

As I understand it, the load I put is either not enough or too much. What would be the right way to make two nodes enter the arbitration? A successful result would be a received CAN error frame corresponding to the CAN_ERR_LOSTARB constant from can/error.h and a value of collsns other than 0.

Source code

HW Node (Arduino Due with CAN board)

Linux node

0 投票
1 回答
1418 浏览

linux-kernel - 使用 IXXAT SocketCAN 驱动程序构建 Raspberry Pi 内核

我想将IXXAT USB-to-CAN v2设备与 RPI3B+ 一起使用。问题出在驱动程序和内核中。我无法让设备在 RPI 上工作。由于这篇文章,这个设置应该可以工作。

在文章中,他们提到我需要安装SocketCAN 驱动程序。在其自述文件中,注释说:

树莓派部分说:

这将我与内核构建联系起来。

问题:

  • 在构建内核时,我需要在哪个步骤中包含 IXXAT SocketCAN 驱动程序?
  • 我需要将SocketCAN 驱动程序中的文件复制/粘贴到哪个位置?
  • 我还需要更改内核配置吗?

我还安装了 can-utils,但如果没有正确的 SocketCAN 驱动程序,我的目标 USB-to-CAN 设备将无法工作。

命令dmesg

命令lsusb

0 投票
1 回答
247 浏览

linux - 可以在 Linux 中使用 dotnet core Socket 访问 SocketCan 吗?

我在 Linux 平台上使用 dotnet core,并希望与 CAN 设备建立通信。Linux平台上可以使用SocketCan,但是有没有办法使用dotnet core中的UnixDomainSocketEndPoint和Socket类直接访问SocketCan呢?

在 Linux (Debian9) 环境中尝试使用此测试程序创建 Socket 实例时:

输出是:

枚举 AdressFamily、SocketType 和 ProtocolType 的哪些值将匹配 SocketCan 套接字?

0 投票
0 回答
509 浏览

c - 如何从 CAN_RAW 套接字中删除 CAN 消息过滤器?

SocketCAN 的描述说关于向套接字添加一些过滤器:

但是,如果我在同一个套接字上有多个过滤器,它并没有说明如何删除特定过滤器。有人可以为我猜测/解释吗?

(这件事是写在某处还是我应该在接触 SocketCAN 之前先获得很多关于 linux 套接字的一般经验?)

0 投票
1 回答
773 浏览

linux - RAW CAN 套接字和广播管理器 CAN 套接字有什么区别以及如何使用它们?

我是 CAN 协议的新手,我正在尝试通过 Linux 的 SocketCAN 来使用它。但是,我对可用的 2 个不同的 CAN 套接字感到困惑,即 RAW 和广播管理器 (BCM)。

文档指出 BCM 套接字不适用于发送单个 CAN 帧。直觉上我猜 BCM 更适合单主多从配置,但这似乎有些错误。

BCM 的用途是什么?或者更确切地说,它们之间在功能方面有什么区别?在什么样的情况下我选择使用广播管理器而不是原始套接字?

0 投票
1 回答
443 浏览

c - linux c socket可以等待传输缓冲区为空

有没有办法用原始socketcan检查一个空的传输缓冲区?

编辑:或者有没有办法让socketcan阻塞,直到当前帧被发送,这将起到同样的作用......

(动机:我正在编写一个 mcu flash 工具。引导加载程序规范要求在发送一定数量的数据后等待一段时间,以便它写入闪存。根据总线负载发送数据可能更快或更慢。)

0 投票
0 回答
271 浏览

c - SocketCAN长延时收包

我正在尝试使用 SocketCAN 在嵌入式 linux 平台(基于 yocto)上实现 CAN 接口。

阅读文档后,我编写了一个快速测试应用程序代码,以便在非阻塞模式下从 CAN 总线接收/读取一些包:

CAN 链路工作并且正在接收数据,但问题是更新数据需要很长时间(几秒钟),例如,如果 byte0 从 0x00 更改为 0xff,则需要约 5 秒才能看到该更改反映在应用程序。

我使用命令检查了控制台:candump can0我可以看到数据没有延迟就可以正常更改。

有谁知道为什么应用程序会出现这种延迟?我在这里想念什么?

提前致谢。