我想使用device
使用socketCAN定期发送消息我创建了一个小脚本来实现此目的,如下所示:
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。
答案 0 :(得分:1)
ifconfig-parameters,但是在设置参数之前,请先启动链接。因此,我不确定运行脚本时实际上是否有1000的txqueuelen。您的ifconfig can0
的输出可能显示此内容。
尝试切换ifconfig命令的顺序。
代替:
os.system("sudo ifconfig can0 up")
os.system("sudo ifconfig can0 txqueuelen 1000")`
要做:
os.system("sudo ifconfig can0 txqueuelen 1000")
os.system("sudo ifconfig can0 up")
我个人还会添加一个命令,以在脚本结束时关闭can0。