the code used is as follows:
Code: Select all
from PCANBasic import * ## PCAN-Basic library import
# The Plug & Play Channel (PCAN-USB) is initialized
objPCAN = PCANBasic()
result = objPCAN.Initialize(PCAN_USBBUS2, PCAN_BAUD_500K)
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")
# All initialized channels are released
#objPCAN.Uninitialize(PCAN_NONEBUS)
""""""""""""""""""""""""""""""""""""""""""""""""""
Code: Select all
# A CAN message is configured
msg = TPCANMsg()
msg.ID = 0x100
msg.MSGTYPE = PCAN_MESSAGE_STANDARD
msg.LEN = 3
msg.DATA[0] = 1
msg.DATA[1] = 2
msg.DATA[2] = 3
# The message is sent using the PCAN-USB Channel 1
result = objPCAN.Write(PCAN_USBBUS1,msg)
if result != PCAN_ERROR_OK:
# An error occurred, get a text describing the error and #
result = objPCAN.GetErrorText(result)
print (result)
else:
print ("Message sent successfully")
""""""""""""""""""""""""""""""""""""""""""""""""""""""
Code: Select all
# The USB Channel is released
#
result = objPCAN.Uninitialize(PCAN_USBBUS1)
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 released")
You have already helped me a lot before thank you very much