A PCAN Channel has not been initialized

This forum covers PCAN-Linux and Linux development issues concerning our products
Post Reply
ntesla
Posts: 10
Joined: Wed 8. Jul 2020, 13:42

A PCAN Channel has not been initialized

Post by ntesla » Thu 11. Mar 2021, 13:55

Hi,

I installed PCAN linux driver and PCAN basic. I don't understand why I am facing this issue.
Here is the error:

Code: Select all

  File "send_one.py", line 33, in <module>
    send_one()
  File "send_one.py", line 18, in send_one
    bus = can.interface.Bus(bustype='pcan', channel='PCAN_USBBUS1', bitrate=250000)
  File "/home/jetson/.local/lib/python3.6/site-packages/can/interface.py", line 127, in __new__
    return cls(channel, *args, **kwargs)
  File "/home/jetson/.local/lib/python3.6/site-packages/can/interfaces/pcan/pcan.py", line 198, in __init__
    raise PcanError(self._get_formatted_error(result))
can.interfaces.pcan.pcan.PcanError: A PCAN Channel has not been initialized yet or the initialization process has failed
Regards,

M.Heidemann
Sales & Support
Sales & Support
Posts: 503
Joined: Fri 20. Sep 2019, 13:31

Re: A PCAN Channel has not been initialized

Post by M.Heidemann » Thu 11. Mar 2021, 14:05

Hello,

Can you provide us with some information to analyze the issue?

1. Which version of the PCAN-Linux driver package do use?

2.Which driver variant did you install ? (CharDev/NetDev)

3. CAn you provide us with more information about your system (Kernel-version, current OS, etc)

4. It seems like you use python-can, which we are not at all addiliated with.
Have you tried our PcanBasic examples for python?

5. Whats you output for: "cat /proc/pcan"

Please report back to us regarding this.

Best Regards

Marvin

ntesla
Posts: 10
Joined: Wed 8. Jul 2020, 13:42

Re: A PCAN Channel has not been initialized

Post by ntesla » Thu 11. Mar 2021, 14:28

I can send message using pcanview
1. peak-linux-driver-8.11.0
2. I am not sure about which variant I installed. I did following steps while installing the driver:
make clean
make
sudo make install
3. 4.9.201
4. No I haven't try Pcanbasic examples yet. How can I run a PcanBasic example? I am just trying to send one message with this code:https://python-can.readthedocs.io/en/master/


5.

Code: Select all

cat /proc/pcan

*------------- PEAK-System CAN interfaces (www.peak-system.com) -------------
*------------- Release_20210119_n (8.11.0) Mar  2 2021 08:18:41 --------------
*------------------- [mod] [isa] [pci] [pec] [dng] [usb] --------------------
*--------------------- 1 interfaces @ major 505 found -----------------------
*n -type- -ndev- --base-- irq --btr- --read-- --write- --irqs-- -errors- status
32    usb   -NA- ffffffff 000 0x011c 00000001 00000000 00000001 00000000 0x0000

Thanks for reply

M.Heidemann
Sales & Support
Sales & Support
Posts: 503
Joined: Fri 20. Sep 2019, 13:31

Re: A PCAN Channel has not been initialized

Post by M.Heidemann » Thu 11. Mar 2021, 15:46

Hello,

In the PCAN-Linux driver package you will find the python example
in the path:

Code: Select all

peak-linux-driver-8.11.0\libpcanbasic\examples\python
These are GUI-Examples, if you work in terminal or prefer to work in console
you could also use the following code:

Code: Select all

from PCANBasic import *
channel = PCAN_USBBUS1
baud = PCAN_BAUD_500K

## The Plug & Play Channel (PCAN-USB) is initialized
##
#PCANBasicAPI =# The Plug & Play Channel (PCAN-USB) is initialized
#
PCANBasicAPI = PCANBasic()
result = PCANBasicAPI.Initialize(channel, baud)
if result != PCAN_ERROR_OK:
	# An error occured, get a text describing the error and show it
	#
	result = PCANBasicAPI.GetErrorText(result)
	print(result[1])
	channel = PCAN_USBBUS1
	PCANBasicAPI = PCANBasic()
	result = PCANBasicAPI.Initialize(channel, baud)
	if result != PCAN_ERROR_OK:
		# An error occured, get a text describing the error and show it
		#
		result = PCANBasicAPI.GetErrorText(result)
		print(result[1])
	else:
		print("PCAN-USB was initialized")
else:
	print("PCAN-USB was initialized")

	# Check the status of the USB Channel
	#
	result = PCANBasicAPI.GetStatus(channel)
if result == PCAN_ERROR_BUSLIGHT:
	print("PCAN-USB (Ch-x): Handling a BUS-LIGHT status...")
elif result == PCAN_ERROR_BUSHEAVY:
	print("PCAN-USB (Ch-x): Handling a BUS-HEAVY status...")
elif result == PCAN_ERROR_BUSOFF:
	print("PCAN-USB (Ch-x): Handling a BUS-OFF status...")
elif result == PCAN_ERROR_OK:
	print("PCAN_USB (Ch-x): Status is OK")
else:
	# An error occured, get a text describing the error and show it
	#
	result = PCANBasicAPI.GetErrorText(result)
	print(result[1])

msg = TPCANMsg()
msg.ID = 0x123
msg.MSGTYPE = PCAN_MESSAGE_STANDARD
msg.LEN = 8
msg.DATA[0] = 0x01
msg.DATA[1] = 0x02
msg.DATA[2] = 0x03
msg.DATA[3] = 0x04
msg.DATA[4] = 0x05
msg.DATA[5] = 0x06
msg.DATA[6] = 0x07
msg.DATA[7] = 0x08
#
result = PCANBasicAPI.Write(channel, msg)
if result != PCAN_ERROR_OK:
	# An error occured, get a text describing the error and show it
	#
	result = PCANBasicAPI.GetErrorText(result)
	print(result)
else:
	print("Message sent successfully")
	
	# All initialized channgels are released
	#
	result = PCANBasicAPI.Uninitialize(PCAN_NONEBUS)
if result != PCAN_ERROR_OK:
	# An error occured, get a text describing the error and show it
	#
	result = PCANBasicAPI.GetErrorText(result)
	print(result)
else:
	print("PCAN-USB was UN-initialized")
Just create a python file in

Code: Select all

peak-linux-driver-8.11.0\libpcanbasic\examples\python
and paste the code, save it and run the .py file.

If you receive the following output everything works as expected:

Code: Select all

PCAN-USB was initialized
PCAN_USB (Ch-x): Status is OK
Message sent successfully
PCAN-USB was UN-initialized
Please report back to us with your findings.

Best Regards

Marvin

ntesla
Posts: 10
Joined: Wed 8. Jul 2020, 13:42

Re: A PCAN Channel has not been initialized

Post by ntesla » Fri 12. Mar 2021, 07:10

Hi,

I am able to run code successfully here is my output:

Code: Select all

PCAN-USB was initialized
PCAN_USB (Ch-x): Status is OK
Message sent successfully
PCAN-USB was UN-initialized

M.Heidemann
Sales & Support
Sales & Support
Posts: 503
Joined: Fri 20. Sep 2019, 13:31

Re: A PCAN Channel has not been initialized

Post by M.Heidemann » Fri 12. Mar 2021, 08:15

Hello,

Then the issue seems the code used with pythoncan,
our API and driver do work as they should.
You should contact the pythoncan community regarding this,
we are not familiar with pythoncan and how its used and
therefore cannot really help you.
Is suspect you are missing one instruction to initialize the device
before your transmission somewhere.

Best Regards

MArvin

Post Reply