关于M上pythoncan的问题

2024-04-29 14:19:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我开始看罐头,开始有困难

我查看了文档,并尝试在Mac上运行示例代码,我得到了一系列不同的错误,我甚至无法让代码在没有错误的情况下运行一次。很多错误似乎都是错误

我不知道从哪里开始调试。任何建议都将不胜感激

# !/usr/bin/env python
# coding: utf-8

# This example shows how sending a single message works.

from __future__ import print_function

import can

def send_one():

    # this uses the default configuration (for example from the config file)
    # see https://python-can.readthedocs.io/en/stable/configuration.html
    bus = can.interface.Bus()

    # Using specific buses works similar:
    # bus = can.interface.Bus(bustype='socketcan', channel='vcan0', bitrate=250000)
    # bus = can.interface.Bus(bustype='pcan', channel='PCAN_USBBUS1', bitrate=250000)
    # bus = can.interface.Bus(bustype='ixxat', channel=0, bitrate=250000)
    # bus = can.interface.Bus(bustype='vector', app_name='CANalyzer', channel=0, bitrate=250000)
    # ...

    msg = can.Message(arbitration_id=0xc0ffee,
                      data=[0, 25, 0, 1, 3, 1, 4, 1],
                      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_one()

Tags: 代码fromsendmessageexample错误channelcan