[Python] Communication through CAN bus interface is not working

Discussão em 'Python' iniciado por Stack, Setembro 11, 2025.

  1. Stack

    Stack Membro Participativo

    I have Python code running on a Linux-based device which has the following OS specifications:

    NAME=Buildroot
    VERSION=2020.11.1


    This device is connected to a PLC using a three-wire interface (CAN_H, CAN_L, and GND).

    I have written code that sends a message to the PLC using the CAN bus protocol. This is being done with the python-can package.

    I have the following code:

    import can

    def send():
    # USB interface
    #bus = can.interface.Bus(bustype='pcan', channel='PCAN_USBBUS1', bitrate=500000)
    # On Linux
    bus = can.interface.Bus(bustype='socketcan', channel='vcan0', bitrate=500000)
    # On Windows
    #bus = can.interface.Bus(bustype='serial', channel='COM1', bitrate=500000)
    msg = can.Message(arbitration_id=0x68005,data=[0x10,0x11,0x12],is_extended_id=True)
    try:
    bus.send(msg)
    print("Message sent on {}".format(bus.channel_info))
    except can.CanError:
    print("Message NOT sent")


    if __name__ == '__main__':
    send()


    The problem is that the device is not sending any data to the PLC. This is probably due to incorrect options set for bustype and channel.

    What can I provide for bustype and channel for this physical interface with three CAN wires?

    Continue reading...

Compartilhe esta Página