Using python-can library here. Here's a simple code to print out can messages:
from can.interface import Bus
bus = Bus(bustype='pcan', channel='PCAN_USBBUS1', bitrate=500000)
for msg in bus:
print(msg)
It runs just fine until I stop the program (running this in Pycharm IDE) and try to run it again. It will show this error:
can.interfaces.pcan.pcan.PcanError: A PCAN Channel has not been initialized yet or the initialization process has failed
I can't figure out why that is. It's fixed by 'restarting' the program, either by reinserting the CAN Dongle or by restarting Pycharm. Is it because the previous instance was cached somewhere? Would appreciate advice on this.