pythontypeerrorabstract-classcan-busuds

TypeError: Can't instantiate abstract class


I try to run code to send a UDS extended diagnostics request on CAN

from uds import Uds

PCM = Uds(resId=0x200, reqId=0x250, transportProtocol="CAN", interface="vector", channel="0", appName="CANoe")
response = PCM.send([0x10, 0x03])

But I get following Type error:

Traceback (most recent call last):
  File "C:\__work__\Karol_projects\main.py", line 26, in <module>
    PCM = Uds(resId=0x200, reqId=0x250, transportProtocol="CAN", interface="vector", channel="0", appName="CANoe")
  File "C:\__work__\Karol_projects\venv\lib\site-packages\uds\uds_communications\Uds\Uds.py", line 43, in __init__
    self.tp = tpFactory(self.__transportProtocol, configPath=configPath, **kwargs)
  File "C:\__work__\Karol_projects\venv\lib\site-packages\uds\uds_communications\TransportProtocols\TpFactory.py", line 37, in __call__
    return CanTp(configPath=configPath, **kwargs)
  File "C:\__work__\Karol_projects\venv\lib\site-packages\uds\uds_communications\TransportProtocols\Can\CanTp.py", line 96, in __init__
    self.__connection = canConnectionFactory(self.callback_onReceive,
  File "C:\__work__\Karol_projects\venv\lib\site-packages\uds\uds_communications\TransportProtocols\Can\CanConnectionFactory.py", line 52, in __call__
    CanConnectionFactory.connections[connectionKey] = CanConnection(callback, filter,
  File "C:\__work__\Karol_projects\venv\lib\site-packages\uds\uds_communications\TransportProtocols\Can\CanConnection.py", line 21, in __init__
    listener = can.Listener()
TypeError: Can't instantiate abstract class Listener with abstract method on_message_received

I have seen similar posts but anyway I can't get a proper solution. I only imported python-can and python-uds modules and had tried to send a can message. I don't have much experience with OOP especially with abstract classes.


Solution

  • python-uds is an older library, and hasn't seen new releases in 3 and half years now (version 1.0.2 was released in March 2019). python-can on the other hand, has made major strides in that time, and released a major update, version 4.0.0 in February 2022. That release is fundamentally incompatible with python-uds, causing the traceback you see.

    You have two options: