Problems with python-can and PCAN connection

248 Views Asked by At

I cant understand why I get this error. Please help.

MY CODE:

import can
with can.interface.Bus(bustype='pcan', channel='PCAN_USBBUS5', bitrate=500000) as bus1:
    msg = can.Message(arbitration_id=0x370, data=[0x01, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00])
    bus1.send(msg)

ERROR:

Traceback (most recent call last):
  File "/home/lvlukanin/PycharmProjects/HIL/main.py", line 4, in <module>
    with can.interface.Bus(bustype='pcan', channel='PCAN_USBBUS5', bitrate=500000) as bus1:
  File "/home/lvlukanin/PycharmProjects/HIL/venv/lib/python3.10/site-packages/can/util.py", line 369, in wrapper
    return f(*args, **kwargs)
  File "/home/lvlukanin/PycharmProjects/HIL/venv/lib/python3.10/site-packages/can/interface.py", line 138, in __new__
    bus = cls(channel, **kwargs)
  File "/home/lvlukanin/PycharmProjects/HIL/venv/lib/python3.10/site-packages/can/interfaces/pcan/pcan.py", line 301, in __init__
    raise PcanCanInitializationError(self._get_formatted_error(result))
can.interfaces.pcan.pcan.PcanCanInitializationError: The value of a PCAN-Hardware handle is invalid
PcanBus was not properly shut down

I`ve already tryied to reinstall python-can (now I have it v4.2.2), reinstall PCAN drivers.

0

There are 0 best solutions below