python-can icon indicating copy to clipboard operation
python-can copied to clipboard

Introducing the python-can package fails to communicate(CANFD)

Open gcszj opened this issue 3 years ago • 1 comments

Describe the bug

<Hello, administrators, I have a question about calling Python-can and communicating with the lower computer,The CANFD message is sent here.>

To Reproduce

 1:The hardware part is the USB-CANFD professional version of Zhiming Electronics, and the picture is as follows,The lower computer is the company's own chip, and the test is available.

image

  2:Configure the bus part and the message part according to the official documentation of python-can,The configuration code is as follows:(Arbitration field is 1000K, data field is 2000k)
import can
bus = can.interface.Bus(bustype='serial',
                        channel='COM6',
                        #baudrate=1000000,
                        #operation_mode='normal',
                        bitrate = 1000000,
                        data_bitrate=2000000,
                        fd=True )
def send_msg():
    filters = [{"can_id": 0x100, "can_mask": 0xFFFF, "extended": False}]
    msg = can.Message(timestamp=0.2, arbitration_id=0x100, is_extended_id=False, is_remote_frame=False,
                      is_error_frame=False, dlc=5, data=[0x00, 0x01, 0x00, 0x01, 0x03], is_fd=True, is_rx=True,
                       bitrate_switch=True, error_state_indicator=False, check=False)
    bus.send(msg)
    print(f"Message sent on {bus.channel_info}")
    print (msg.data)
    print(bus.state)
def receive_all():
    print('Waiting for RX CAN messages ...')
    for msg in bus:
        #msg = bus.recv(timeout=1)
        print(msg)
    # try:
    #     while True:
    #         msg = bus.recv(1)
    #         if msg is not None:
    #             print(msg)
    # except KeyboardInterrupt:
    #     print("done")
    # bus = can.interface.Bus()
    # while True:
    #with Bus() as bus:
if __name__ == "__main__":
    send_msg()
    receive_all()
  3:The result after running is as follows:

image

It only shows the success of the bus serial port call and the message sending status and data, and in order to return the data of the lower computer, we guess that it may not be sent out. 4:After consulting the python-can document, we found that his interface has serial and Chinese CAN-USB interface (mfg. Robotell etc.)

Expected behavior

It is expected that the corresponding data will be sent as shown in the figure below, and the lower computer will return the corresponding message: image

Additional context

OS and version:Win10 Python version:3.7.9 python-can version:4.0.0 python-can interface/s (if applicable):

I don't know where the bug problem occurred, please let the management staff know, thank you very much

Traceback and logs
bus = can.interface.Bus(bustype='serial',
                        channel='COM6',
                        baudrate=1000000,
                        #operation_mode='normal',
                        #bitrate = 1000000,
                        data_bitrate=2000000,
                        fd=True )
def send_msg():
    filters = [{"can_id": 0x100, "can_mask": 0xFFFF, "extended": False}]
    msg = can.Message(timestamp=0.2, arbitration_id=0x100, is_extended_id=False, is_remote_frame=False,
                      is_error_frame=False, dlc=5, data=[0x00, 0x01, 0x00, 0x01, 0x03], is_fd=True, is_rx=True,
                       bitrate_switch=True, error_state_indicator=False, check=False)
    bus.send(msg)
    print(f"Message sent on {bus.channel_info}")
    print (msg.data)
    print(bus.state)
def receive_all():
    print('Waiting for RX CAN messages ...')
    for msg in bus:
        #msg = bus.recv(timeout=1)
        print(msg)
    # try:
    #     while True:
    #         msg = bus.recv(1)
    #         if msg is not None:
    #             print(msg)
    # except KeyboardInterrupt:
    #     print("done")
    # bus = can.interface.Bus()
    # while True:
    #with Bus() as bus:
if __name__ == "__main__":
    send_msg()
    receive_all()

gcszj avatar Dec 01 '22 07:12 gcszj

Did you succeed in the end? I encountered the same problem

amsyrena avatar Feb 28 '24 03:02 amsyrena