0

I'm trying to filter out CAN bus messages except 0x257 as below

It seems like the filter is working because in the beginning I can only see message with ID 0x257 like


0000257 00 A1 00 FF ...

but several ten seconds later I start to get other messages with different ID like


0000257 00 A1 00 FF ... 00003E2 14 01 00 00 ... 00003E3 04 00 ...

I think my ID filter 0x257 and Mask 0x7FF(11bit ID) are correct but I dont understand why messages with different IDs are coming through the mask

def read_bus(bus_device):   
    message = bus.recv(0.2)
    filters = [
{"can_id": 0x257, "can_mask": 0x7FF, "extended": False}
]
    bus = can.interface.Bus(channel="can0", bustype="socketcan", can_filters=filters)
    while True:
        if message:
            break
        message = bus.recv(0.2)

    try:
        string = "{}:ID={}:LEN={}".format("RX", message.arbitration_id, message.dlc)
        for x in range(message.dlc):
            string += ":{:02x}".format(message.data[x])

    except Exception as e:
        print(e)
    return string
deepsdog
  • 25
  • 5
  • Typo: `break` needs to be indented one more level. – Dennis Williamson Nov 15 '22 at 14:19
  • Is it possible your interface doesn't support filtering or that it's functioning correctly? From the [docs](https://python-can.readthedocs.io/en/master/bus.html#filtering): "Message filtering can be set up for each bus. Where the interface supports it, this is carried out in the hardware or kernel layer - not in Python." – Dennis Williamson Nov 16 '22 at 14:03

0 Answers0