I'd like to have a function to receive incoming CANbus frames asynchronously. I wrote the following, but the following issue:
can.rxcallback(0, callback)
AttributeError: module 'can' has no attribute 'rxcallback'
My code is as follow:
def reception():
global count
data = [0, 0, 0, memoryview(bytearray(8))]
def callback(bus, reason):
global count
count += 1
bus.recv(0, list=data)
if reason == 0:
pass
elif reason == 1:
pass # fifo full
elif reason == 2:
# fifo overflow
raise Exception("fifo overflow")
can.rxcallback(0, callback)