Python3 python CAN notifier - TypeError: 'NoneType' object is not callables

Python3 python CAN notifier - TypeError: 'NoneType' object is not callables

我正在尝试按照与 here 中完全相同的方法为 python-can (4.0.0) 实施通知程序,但我收到以下错误:

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

我的代码:

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')

我不太明白我做错了什么,python-can 通知程序的文档也不是很有帮助。

就像@TimRoberts 所说的那样,我以错误的方式传递了函数。

这是一个可以工作的代码,即使没有 CAN 硬件也可以测试。

from time import sleep
import can

bus1 = can.interface.Bus(channel = 'test', bustype = 'virtual')
bus2 = can.interface.Bus('test', bustype='virtual')

msg = can.Message(arbitration_id=0x123, data=[0, 1, 2, 3, 4, 5, 6, 7])

def parseData(can):
        print( can.arbitration_id )

notifier = can.Notifier(bus2,[parseData])

while (1):
    bus1.send(msg)
    sleep(1)