如何用PythonCan和Raspberry过滤CAN总线的入侵检测结果

2024-04-29 10:36:53 发布

您现在位置:Python中文网/ 问答频道 /正文

您好,我有一个带有MCP2515 CAN总线设备的树莓,用于读取广播的全部值,这是Python中使用Python CAN的唯一来源:

import can 
bus = can.interface.Bus(channel='can0', bustype='socketcan_native') 
notifier = can.Notifier(bus, [can.Printer()])

我需要过滤id的结果,它是如何工作的?有人能举个例子说明制造过滤器的可能性吗?我在图书馆的网站上看了,这是过滤的网页: https://python-can.readthedocs.io/en/stable/bus.html#filtering

它是如何工作的?谢谢你的回复


Tags: import来源channelcaninterface树莓native总线
2条回答

应该使用Bus类实例的set_filters()方法设置过滤器。参数是一个包含can_id、一个can_mask和一个可选的extended键的字典的iterable

bus.set_filters([{"can_id": 0x11, "can_mask": 0x21, "extended": False}])

查看internal api docs了解更多详细信息

我想这意味着

def on_message_received:
    set_filters(can_filters{"can_id": 0x11, "can_mask": 0x21})

另一个引用[Json]https://github.com/normaldotcom/CANard/blob/master/examples/example_db.json

相关问题 更多 >