I try to read CAN msgs and then transmit the processed CAN msgs via PEAK CAN-USB in Python (with the Py) environment, while I found there is a heavy latency communication between PCAN-View and Python environment as shown in below pictures. I simulate the signals from WIN10 PCAN-View and you can see the count number in ubuntu is less than the number in WIN10 PCAN-View and the same situation we can found the Data is also different at the same time
I also tried in ubuntu PCAN-View transmit to ubuntu Python, also occurred the above situation.
Hardware: PCAN-USB Pro FD
And below is the Python code contents:
Code: Select all
from PCANBasic import *
import time
channel = PCAN_USBBUS1
baud = PCAN_BAUD_500K
## The Plug & Play Channel (PCAN-USB) is initialized
##
# objPCAN =# The Plug & Play Channel (PCAN-USB) is initialized
#
objPCAN = PCANBasic()
result = objPCAN.Initialize(channel, baud)
if result != PCAN_ERROR_OK:
# An error occured, get a text describing the error and show it
#
result = objPCAN.GetErrorText(result)
print(result[1])
channel = PCAN_USBBUS2
objPCAN = PCANBasic()
result = objPCAN.Initialize(channel, baud)
if result != PCAN_ERROR_OK:
# An error occured, get a text describing the error and show it
#
result = objPCAN.GetErrorText(result)
print(result[1])
else:
print("PCAN-USBx was initialized")
else:
print("PCAN-USBx was initialized")
# Check the status of the USB Channel
#
result = objPCAN.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 = objPCAN.GetErrorText(result)
print(*result[1])
while (True):
start = time.perf_counter()
objPCAN.FilterMessages(channel, 119, 119, PCAN_MESSAGE_STANDARD)
RecMegs = objPCAN.Read(channel)[1]
print(RecMegs.ID)
print(list(RecMegs.DATA)) # extract the data from CAN Read call back module
# Send the data to CAN bus
msg = TPCANMsg()
msg.ID = 0x56
msg.MSGTYPE = PCAN_MESSAGE_STANDARD
msg.LEN = 8
msg.DATA[0] = 0x08
msg.DATA[1] = 0x00
msg.DATA[2] = 0x00
msg.DATA[3] = 0x80
msg.DATA[4] = 0x00
msg.DATA[5] = 0x00
msg.DATA[6] = 0x00
msg.DATA[7] = 0x00
time.sleep(0.01)
#
result = objPCAN.Write(channel, msg)
if result != PCAN_ERROR_OK:
# An error occured, get a text describing the error and show it
#
result = objPCAN.GetErrorText(result)
print(result)
else:
print("Message sent successfully")
end = time.perf_counter()
duration = end - start
print(duration)
print(' ')
# All initialized channgels are released
#
result = objPCAN.Uninitialize(PCAN_NONEBUS)
if result != PCAN_ERROR_OK:
# An error occured, get a text describing the error and show it
#
result = objPCAN.GetErrorText(result)
print(result)
else:
print("PCAN-USBx was UN-initialized")