Python3:can.Notifier、can.Logger 不写入文件
在 python 3.9.2 上使用 can.Logger 我无法编写一个日志文件,其中包含所有可以总线的
python 脚本:
#! /usr/bin/python3
import can
import time
bus = can.Bus(interface='socketcan',
channel='can2')
fileName = "test.asc"
notifier = can.Notifier(bus, [can.Printer(), can.Logger(fileName, 'a')])
tm1 = time.perf_counter()
while True:
tm2 = time.perf_counter()
if tm2 >= tm1 + 5:
notifier.stop()
tm1=time.perf_counter()
notifier = can.Notifier(bus, [can.Printer(), can.Logger(fileName, 'a')])
当我运行我的脚本时,“test.asc”文件已正确创建,但里面没有任何内容。
该脚本给了我这样的输出:
2
Timestamp: 1647881138.770576 ID: 0302b0a0 X DLC: 8 00 00 55 00 8d 00 00 aa Channel: can2
Timestamp: 1647881139.770898 ID: 0302b0a0 X DLC: 8 00 00 55 00 8d 00 00 aa Channel: can2
Timestamp: 1647881140.770732 ID: 0302b0a0 X DLC: 8 00 00 55 00 8d 00 00 aa Channel: can2
Timestamp: 1647881141.770435 ID: 0302b0a0 X DLC: 8 00 00 55 00 8d 00 00 aa Channel: can2
T
我想要获得的结果是记录can总线上到达我的所有内容,直到脚本被中断
编辑
i'我发现问题可能出在我第二次声明通知者的地方。 但我有必要每 5 秒阻止一次通知程序。我怎样才能重新启动它?
using can.Logger on python 3.9.2 i'm not able to write a log file with everything that comes on can bus
my python script:
#! /usr/bin/python3
import can
import time
bus = can.Bus(interface='socketcan',
channel='can2')
fileName = "test.asc"
notifier = can.Notifier(bus, [can.Printer(), can.Logger(fileName, 'a')])
tm1 = time.perf_counter()
while True:
tm2 = time.perf_counter()
if tm2 >= tm1 + 5:
notifier.stop()
tm1=time.perf_counter()
notifier = can.Notifier(bus, [can.Printer(), can.Logger(fileName, 'a')])
when I run my script, the "test.asc" file is correctly created but there's nothing inside.
the script give me an output like this:
2
Timestamp: 1647881138.770576 ID: 0302b0a0 X DLC: 8 00 00 55 00 8d 00 00 aa Channel: can2
Timestamp: 1647881139.770898 ID: 0302b0a0 X DLC: 8 00 00 55 00 8d 00 00 aa Channel: can2
Timestamp: 1647881140.770732 ID: 0302b0a0 X DLC: 8 00 00 55 00 8d 00 00 aa Channel: can2
Timestamp: 1647881141.770435 ID: 0302b0a0 X DLC: 8 00 00 55 00 8d 00 00 aa Channel: can2
T
the result I would like to obtain is to log everything that comes to me on the can bus until the script is interrupted
EDIT
i've seen that the problem probaly is where i declare notifier for the second time.
but it is necessary for me to block the notifier every 5 seconds. how can I restart it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无法重新启动 can.Notifier。
但要写入包含 CAN 总线上所有内容的日志文件,您可以使用 Bus.recv()
it's not possible to restart can.Notifier.
but to write a log file with everything that comes on can bus you can use bus.recv()