Python-can filtering mask

348 Views Asked by At

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
0

There are 0 best solutions below