4

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.

2 Answers 2

6

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.

1
-2

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

2
  • 1
    Can you elaborate on that? set_filters() is a function of the bus class so wouldn't you need to call that on the bus you try to filter? Asking cause I have the same problem as OP and I can't get my filters to work.
    – Swedgin
    Oct 10, 2019 at 7:51
  • This is wrong. You shouldn't be calling set_filters in your receive callback, plus you have syntax errors.
    – insys
    Aug 27, 2020 at 7:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.