A PCAN Channel has not been initialized yet

The free CAN Software API (Application Programming Interface) for Windows®
Locked
Abdelrahman SAEED
Posts: 2
Joined: Wed 25. Oct 2023, 01:59

A PCAN Channel has not been initialized yet

Post by Abdelrahman SAEED » Wed 25. Oct 2023, 02:17

Hello,

we have a .net framework project (DLL) acting as an CANEngine built using UDSApi and PCANBasic APIs, and since we use Diagnostics we initialize using UDSApi and pass its handle to the PCANBasic APIs whenever we want to use them.

Recently we are trying to integrate this DLL project into another solution based on python (for deadline issues we can't rebuild it using the python package), now we are facing a weird behavior whenever we call any functions that uses the PCANBasic saying "A PCAN Channel has not been initialized yet or the initialization process has failed"

apparently any PCANBasic gets PCAN_ERROR_INITIALIZE status whenever it's called, even tho we already know that it's been initialized using the UDSApi already and the Diag services are working fine

Note:
  • Everything works normally when initializing with PCANBasic however we can't use UDS services
  • any .net framework project using the CANEngine DLL works also fine, it only shows when calling from python

Please let mw know if anyone faced such issue and how to fix it

K.Wagner
Software Development
Software Development
Posts: 1080
Joined: Wed 22. Sep 2010, 13:36

Re: A PCAN Channel has not been initialized yet

Post by K.Wagner » Wed 25. Oct 2023, 09:10

Hello,

three things come to my mind:
  1. When porting the code to Python, the initialization sequence of the channel has to be somehow changed.
  2. There is a Python feature, that is a blessing and a curse at the same time: if a variable doesn't exists within a class or a project, it will just created when first referenced.
  3. The Python apporach is splitting the calls to the APIs between different processes.
Regarding 1: Have you tried to call an UDS function with that (variable) handle, right before calling the PCAN-Basic function returning the PCAN_ERROR_INITIALIZE? It should not work neather.
Regarding 2: Typos happen often. If you do a Typo on a variable name and this is created, it will not contain the right PCAN-Basic handle and would lead to errors like this. Check that the handle is valid, i.e. that the handle variable contains the right handle value.
Regarding 3: PCAN-Basic can initialize and use a channel only one time per process. If a process already is using a channel, this is not available for any other process.

Hope this helps you finding the problem.
Best regards,
Keneth

Abdelrahman SAEED
Posts: 2
Joined: Wed 25. Oct 2023, 01:59

Re: A PCAN Channel has not been initialized yet

Post by Abdelrahman SAEED » Wed 25. Oct 2023, 11:27

Hello,

Thanks for your the suggestions unfortunately they weren't the case, however, I was able to fix it this morning by simply updating all the DLLs (Basic, ISO and UDS) to the latest version from Peak-System website and HOLAAA it works, perhaps it was a bug and was fixed it in the recent versions.

K.Wagner
Software Development
Software Development
Posts: 1080
Joined: Wed 22. Sep 2010, 13:36

Re: A PCAN Channel has not been initialized yet

Post by K.Wagner » Wed 25. Oct 2023, 11:38

Hello,
Abdelrahman SAEED wrote:
Wed 25. Oct 2023, 11:27
I was able to fix it this morning by simply updating all the DLLs
If you were using different API versions for the .NET and Python projects, then I would understand this. It is always recommended to use the latest version of the APIs.

Glad to see that you have found and fixed your problem.

Closed.
Best regards,
Keneth

Locked