I'm trying to implement a notifier for for the python-can (4.0.0) following the exact same approach as in here but I'm getting the following error:
Exception in thread can.notifier for bus "socketcan channel 'can0'":
Traceback (most recent call last):
File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/usr/lib/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.7/dist-packages/can/notifier.py", line 121, in _rx_thread
self._on_message_received(msg)
File "/usr/local/lib/python3.7/dist-packages/can/notifier.py", line 143, in _on_message_received
res = cast(Union[None, Optional[Awaitable[Any]]], callback(msg))
TypeError: 'NoneType' object is not callables
My code:
import os
import can
os.system('sudo ip link set can0 up type can bitrate 500000')
bus = can.interface.Bus(channel = 'can0', bustype = 'socketcan')
def parseData(can):
SingleCanFrame = can.Message
notifier = can.Notifier(bus,[parseData(can)])
while(1):
continue
os.system('sudo ifconfig can0 down')
I don't really understand what I'm doing wrong and the python-can documentation on the notifier is not very helpful either.
Like @TimRoberts said I was passing the function in the wrong way.
Here is a code that works and can be tested even without the CAN Hardware.