Reputation: 214
Hello I have a Raspberry with an MCP2515 CAN bus device, for read entire values of broadcasting it's only this source in Python with use of python-can:
import can
bus = can.interface.Bus(channel='can0', bustype='socketcan_native')
notifier = can.Notifier(bus, [can.Printer()])
I need to filter that result for id, how it work? Can anybody make an example of it's possible make a filter? I watched on website of library and this is the web page of filtering: https://python-can.readthedocs.io/en/stable/bus.html#filtering
How it work? Thanks a lot for reply.
Upvotes: 4
Views: 9587
Reputation: 1288
You should set the filter using the set_filters()
method of your instance of the Bus
class. The argument is an iterable of dictionaries each containing a can_id
, a can_mask
, and an optional extended
key.
bus.set_filters([{"can_id": 0x11, "can_mask": 0x21, "extended": False}])
Check out the internal api docs for more detailed information.
Upvotes: 6
Reputation: 1
I think what this means is that
def on_message_received:
set_filters(can_filters{"can_id": 0x11, "can_mask": 0x21})
Another reference [Json] https://github.com/normaldotcom/CANard/blob/master/examples/example_db.json
Upvotes: -2