Page 1 of 1

PCAN-USB receiving empty data

Posted: Thu 23. Jun 2022, 13:24
by vijayakumar
We are testing a Battery Management system using PCAN-USB connected to Raspberry Pi4. Installed as chardev device in pi4. written a code to receive the CAN mesages from battety but when we run the code we are getting the expected data frames. getting empty data. the linux driver for peak system installed is 8.14.0 and also installed pcan basic for linux. the BMS communicates with PCAN at 250kbps. i attached the code here.
from PCANBasic import *

objPCAN = PCANBasic()

result = objPCAN.Initialize(PCAN_USBBUS1, PCAN_BAUD_250K)

if result != PCAN_ERROR_OK:
# An error occurred, get a text describing the error and show it
#
result = objPCAN.GetErrorText(result)
print (result[1])
else:
print ("PCAN-USB (Ch-1) was initialized")


readResult = PCAN_ERROR_OK,
while (readResult[0] & PCAN_ERROR_QRCVEMPTY) != PCAN_ERROR_QRCVEMPTY:
# Check the receive queue for new messages
#
readResult = objPCAN.Read(PCAN_USBBUS1)
if readResult[0] != PCAN_ERROR_QRCVEMPTY:
# Process the received message
#
print ("A message was received")
print('[0]',readResult[0]) # A TPCANStatus error code
print('[1]',readResult[1]) # A TPCANMsg structure with the CAN message read
print('[2]',readResult[2]) # A TPCANTimestamp structure with the time when the message was read

msg = readResult[1] #readResult[1] TPCANMsg()
#print('msg = ',msg )
print('ID = ',msg.ID)
print('MSGTYPE = ',msg.MSGTYPE)
print('LEN = ',msg.LEN)
print('DATA[0] = ',msg.DATA[0])
print('DATA[1] = ',msg.DATA[1])
print('DATA[2] = ',msg.DATA[2])
print('DATA[3] = ',msg.DATA[3])
print('DATA[4] = ',msg.DATA[4])
print('DATA[5] = ',msg.DATA[5])
print('DATA[6] = ',msg.DATA[6])
print('DATA[7] = ',msg.DATA[7])

else:
# An error occured, get a text describing the error and show it
#
result = objPCAN
.GetErrorText(readResult[0])
print(result[1])
And this is the result we got
PCAN-USB (Ch-1) was initialized
A message was received
[0] 4
[1] <PCANBasic.TPCANMsg object at 0x7f9d56f640>
[2] <PCANBasic.TPCANTimestamp object at 0x7f9d56f6c0>
ID = 2
MSGTYPE = 128
LEN = 4
DATA[0] = 0
DATA[1] = 0
DATA[2] = 0
DATA[3] = 4
DATA[4] = 0
DATA[5] = 0
DATA[6] = 0
DATA[7] = 0
A message was received
[0] 0
[1] <PCANBasic.TPCANMsg object at 0x7f9d56f740>
[2] <PCANBasic.TPCANTimestamp object at 0x7f9d56f7c0>
ID = 1
MSGTYPE = 128
LEN = 4
DATA[0] = 0
DATA[1] = 0
DATA[2] = 0
DATA[3] = 0
DATA[4] = 0
DATA[5] = 0
DATA[6] = 0
DATA[7] = 0
A message was received
[0] 4
[1] <PCANBasic.TPCANMsg object at 0x7f9d56f640>
[2] <PCANBasic.TPCANTimestamp object at 0x7f9d56f6c0>
ID = 2
MSGTYPE = 128
LEN = 4
DATA[0] = 0
DATA[1] = 0
DATA[2] = 0
DATA[3] = 4
DATA[4] = 0
DATA[5] = 0
DATA[6] = 0
DATA[7] = 0
b'The receive queue is empty'

Re: PCAN-USB receiving empty data

Posted: Thu 23. Jun 2022, 13:56
by M.Maidhof
Hi,

please post the output of cat /proc/pcan

regards

Michael

Re: PCAN-USB receiving empty data

Posted: Wed 6. Jul 2022, 07:31
by vijayakumar
Hi Michael,

i attached the output for cat /proc/pcan for your reference. plz suggest me where it went wrong

Regards
S.Vijayakumar

Re: PCAN-USB receiving empty data

Posted: Wed 6. Jul 2022, 11:35
by PEAK-Support
All looks OK - please us a Windows System, install driver incl. PCAN-View for Windows and connect to your network. Run PCAN-View with you Bitrate and check if you receive any frames.
If not check Status line if you have errors (simply send one single CAN Frame to your bus to test if the Network Environment is OK )
Is you CAN Bus terminated ?
Are the Bitrates 100% identiical on all nodes ?

In your 1st post you recieve Msg Type Status (0x80 & DEC 128) which means this is NO real CAN Frame - it is a Status Information from the driver - your network does not work (see info above to solve / check)