PCAN-USB receiving empty data
Posted: Thu 23. Jun 2022, 13:24
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.
print(result[1])
And this is the result we got
.GetErrorText(readResult[0])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
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'