Ask for information

The free CAN Software API (Application Programming Interface) for Windows®
Post Reply
Bourass
Posts: 13
Joined: Mon 28. Jan 2019, 18:31

Ask for information

Post by Bourass » Thu 16. May 2019, 12:37

I'm using PCAN-Basic to talk to my devices, but sometime i try to start my application , CAN_Initialize is failing with status

Code: Select all

" *** Remote Interpreter Reinitialized  ***
b'A PCAN Channel has not been initialized yet or the initialization process has failed'" 
but sometimes it worked perfectly?
this is my used function in my code

Code: Select all

import sys
import time
from  threading import Thread
import codecs
#sys.path.insert(0, 'C:\Program Files (x86)\Python36-32\Lib\site-packages\PCAN-Basic API\Include')
from PCANBasic import *
bitrate = b"f_clock_mhz=80, nom_brp=10, nom_tseg1=12, nom_tseg2=3, nom_sjw=1, data_brp=4, data_tseg1=7, data_tseg2=2, data_sjw=1"
bus = PCANBasic()
res = bus.InitializeFD(PCAN_USBBUS1, bitrate)

rx_mssg = TPCANMsgFD()
data_rx = []

if( res != PCAN_ERROR_OK ):
	res = bus.GetErrorText(res)
	print(res[1])
else:
     print("Initialized correctly")
Thanks in advance for any ideas that can help me !
Last edited by K.Wagner on Thu 16. May 2019, 12:44, edited 1 time in total.
Reason: Format applied for better reading

Bourass
Posts: 13
Joined: Mon 28. Jan 2019, 18:31

Re: Ask for information

Post by Bourass » Thu 16. May 2019, 13:53

Hi,

and When i run the program the first time it gives me an error " A PCAN Channel has not been initialized yet or the initialization process has failed ". Is there anyone who can tell me how to remove this error because i am stuck with this problem. but when i run it for the seconde it worked correctly

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

Re: Ask for information

Post by K.Wagner » Thu 16. May 2019, 14:18

Hello,

this happens when connections to PCAN channels are kept in the background. You have to be sure to call CAN_Uninitialize before exiting your app. Note that python may stay in the background and in this way avoid the closing of any connection you have done. If this happens, please close your Python interpreter and start it again.
Best regards,
Keneth

Bourass
Posts: 13
Joined: Mon 28. Jan 2019, 18:31

Re: Ask for information

Post by Bourass » Thu 16. May 2019, 14:52

i did not understand your idea
this happens when connections to PCAN channels are kept in the background.
could you please explain more about this issue because i am using code python as exe on another app and i am getting this issue everytime.
regarding the CAN_Uninitialization of course at end of my code i am Uninitialize but the same issue was appeared!

Code: Select all

res = bus.Uninitialize(PCAN_USBBUS1)
    if( res != PCAN_ERROR_OK ):
    	res = bus.GetErrorText(res)
    	print(res[1])
    else:
         print("Uninitialized correctly")
    bus.Reset(Channel = PCAN_USBBUS1)
Please share with me your thoughts and ideas regarding this issue

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

Re: Ask for information

Post by K.Wagner » Thu 16. May 2019, 17:08

Hello,
Bourass wrote:i did not understand your idea
this happens when connections to PCAN channels are kept in the background.
Python is an interpreter, which launches python scripts. Every time you start a python app, a new child process is launched. Sometimes they stay "alive" even if you don't see the console window. So, if in one of those a channel is being used, you will be not able to initialize it again from any other app.
Bourass wrote:regarding the CAN_Uninitialization of course at end of my code i am Uninitialize but the same issue was appeared!
if you app crashes before reaching the line where you do uninitialize, then you can get the same problem.
Bourass wrote:Please share with me your thoughts and ideas regarding this issue
Are you using Windows 7 or an not up to date Windows 10? There was a problem introduced by Windows updates that were avoiding the driver to clean abandoned connection. More information here: Need to reboot to initialize PCAN-USB
Best regards,
Keneth

Bourass
Posts: 13
Joined: Mon 28. Jan 2019, 18:31

Re: Ask for information

Post by Bourass » Thu 16. May 2019, 17:44

Thanks for your repy , i am using windows 10. i am using Uninitialization at end of my code and in the start of the code , it means

Uninitialize
initialize
data Traitement( read and write)
Uninitialize
what do you think?

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

Re: Ask for information

Post by K.Wagner » Fri 17. May 2019, 08:34

Hello,

yes it is ok, just check the result of those function calls; if the function calls work the result must be PCAN_ERROR_OK. You can also try the compiled samples that are located within the folders Win32 and x64 of the PCAN-basic package. Check which channels are shown there available, and if you can connect them. If you don't have problem with it, then you need to inspect your code better.
Best regards,
Keneth

Bourass
Posts: 13
Joined: Mon 28. Jan 2019, 18:31

Re: Ask for information

Post by Bourass » Mon 20. May 2019, 14:31

in the configuration of the bitrate should i change something or it is ok
bitrate = b"f_clock_mhz=80, nom_brp=10, nom_tseg1=12, nom_tseg2=3, nom_sjw=1, data_brp=4, data_tseg1=7, data_tseg2=2, data_sjw=1"
i have the feeling that the bitrate it is not well configured as i copy paste it because i did not find the meaning of each element ( f_clock_mhz, nom_tseg1, nom_sjw)
i will be more than happy if you could support on that !

Note : i use python

Thanks

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

Re: Ask for information

Post by K.Wagner » Mon 20. May 2019, 16:56

Hello
Bourass wrote:in the configuration of the bitrate should i change something or it is ok
sorry, but I cannot tell you if your bitrate is OK. Only you know your CAN network and device configurations. This is your job.
Bourass wrote:i have the feeling that the bitrate it is not well configured as i copy paste it because i did not find the meaning of each element
if you don't understand something and you copy paste it, then don't be surprised if it doesn't work. The information is in the help file and in the header files, also for python - here an extract of that file, PCANBasic.py:

Code: Select all

# Represents the configuration for a CAN bit rate
# Note: 
#    * Each parameter and its value must be separated with a '='.
#    * Each pair of parameter/value must be separated using ','. 
#
# Example:
#    f_clock=80000000,nom_brp=10,nom_tseg1=5,nom_tseg2=2,nom_sjw=1,data_brp=4,data_tseg1=7,data_tseg2=2,data_sjw=1
#
PCAN_BR_CLOCK                 = TPCANBitrateFD(b"f_clock")
PCAN_BR_CLOCK_MHZ             = TPCANBitrateFD(b"f_clock_mhz")
PCAN_BR_NOM_BRP               = TPCANBitrateFD(b"nom_brp")
PCAN_BR_NOM_TSEG1             = TPCANBitrateFD(b"nom_tseg1")
PCAN_BR_NOM_TSEG2             = TPCANBitrateFD(b"nom_tseg2")
PCAN_BR_NOM_SJW               = TPCANBitrateFD(b"nom_sjw")
PCAN_BR_NOM_SAMPLE            = TPCANBitrateFD(b"nom_sam")
PCAN_BR_DATA_BRP              = TPCANBitrateFD(b"data_brp")
PCAN_BR_DATA_TSEG1            = TPCANBitrateFD(b"data_tseg1")
PCAN_BR_DATA_TSEG2            = TPCANBitrateFD(b"data_tseg2")
PCAN_BR_DATA_SJW              = TPCANBitrateFD(b"data_sjw")
PCAN_BR_DATA_SAMPLE           = TPCANBitrateFD(b"data_ssp_offset")
More information and possible values for e3ach field can be found in the help, PCANBasic_enu.chm, within the chapter Definitions/FD Bit rate Parameter definition
Location of bit rate parameters definitions within the help file
Location of bit rate parameters definitions within the help file
BitrateValues.PNG (36.91 KiB) Viewed 7589 times
Bourass wrote:... because i did not find the meaning of each element
I would say that you didn't search for the information, instead of to say that you didn't find it.
Best regards,
Keneth

Post Reply