我创建了一个小脚本来实现这一点,如下所示:
import os
import time
msg = "1FF#FFFFF00000000000"
os.system("sudo slcand -o -c -f -s6 /dev/serial/by-id/*CANtact* can0")
os.system("sudo ifconfig can0 up")
os.system("sudo ifconfig can0 txqueuelen 1000") # this does not help
start = time.time()
while True:
if round(time.time() - start, 1) % 60 == 0.:
print(str(int((time.time() - start) / 60)) + " minutes")
os.system("cansend can0 " + msg)
time.sleep(0.1)
我已经在做一些研究,发现对于某些人来说,设置txqueuelen
. 但是,这对我没有帮助。此脚本的输出如下所示:
0 minutes
1 minutes
[...]
15 minutes
16 minutes
18 minutes
write: No buffer space available
write: No buffer space available
write: No buffer space available
write: No buffer space available
write: No buffer space available
write: No buffer space available
[and so on]
设备在该错误发生之前停止发送这些消息。输入和输出流量的 LED 指示灯会在错误消息出现前大约 10 秒到几分钟停止闪烁。此外,我无法在接收方阅读任何内容。缓冲区填满所需的时间变化很大,从几分钟到几小时不等。不过通常在 10-20 分钟内。
我曾想过可能有类似接收缓冲区的东西,因为我从未从中读到它只是填满。但我不知道这是否真的如此,也不知道如何测试它或如何刷新缓冲区或重置它或其他什么。我只需要发送我的消息。我不关心其他任何事情。
之后唯一的解决方案是重新启动为设备供电的 Raspberry Pi。