跳转到主要内容

Python的控制器区域网络接口模块

项目描述

Latest Version on PyPi Latest Version on conda-forge Supported Python implementations Downloads on PePy Monthly downloads on PePy

Documentation Github Actions workflow status Test coverage reports on Coveralls.io Mergify Status This project uses the black formatter.

控制器局域网是一种总线标准,旨在允许微控制器和设备之间相互通信。它具有基于优先级的总线仲裁和可靠的确定通信。它被用于汽车、卡车、船只、轮椅等。

can 包为 Python 开发者提供了控制器局域网支持;提供对不同硬件设备的通用抽象,以及一套用于在 CAN 总线上发送和接收消息的实用工具。

该库目前支持 CPython 以及 PyPy,并在 Mac、Linux 和 Windows 上运行。

库版本

Python

2.x

2.6+, 3.4+

3.x

2.7+, 3.5+

4.0+

3.7+

4.3+

3.8+

功能

  • CAN 通信的通用抽象

  • 支持许多不同的后端(见文档

  • 接收、发送和定期发送消息

  • 普通和扩展仲裁 ID

  • CAN FD 支持

  • 许多不同的日志记录器和阅读器支持回放:ASC(CANalyzer 格式)、BLF(Vector 的二进制日志格式)、MF4(ASAM 的测量数据格式 v4)、TRC、CSV、SQLite 和 Canutils 日志

  • 在支持接口上对消息进行高效的内核或硬件过滤

  • 从文件或从环境变量读取总线配置

  • 用于处理 CAN 总线的命令行工具(见文档

  • 更多

示例用法

pip install python-can

# import the library
import can

# create a bus instance using 'with' statement,
# this will cause bus.shutdown() to be called on the block exit;
# many other interfaces are supported as well (see documentation)
with can.Bus(interface='socketcan',
              channel='vcan0',
              receive_own_messages=True) as bus:

   # send a message
   message = can.Message(arbitration_id=123, is_extended_id=True,
                         data=[0x11, 0x22, 0x33])
   bus.send(message, timeout=0.2)

   # iterate over received messages
   for msg in bus:
       print(f"{msg.arbitration_id:X}: {msg.data}")

   # or use an asynchronous notifier
   notifier = can.Notifier(bus, [can.Logger("recorded.log"), can.Printer()])

您可以在python-can.readthedocs.org上找到更多文档信息。

讨论

如果您遇到错误,可以在 GitHub 上的我们的问题跟踪器中提交。

Stackoverflow有几个带有python+can标签的问题和答案。

无论我们在哪里互动,我们都努力遵循Python 社区行为准则

贡献

有关开始的信息,请参阅doc/development.rst

项目详情


发布历史 发布通知 | RSS 源

下载文件

下载适用于您平台的应用程序。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分布

python_can-4.4.2.tar.gz (345.6 kB 查看哈希值)

上传时间

构建分布

python_can-4.4.2-py3-none-any.whl (265.2 kB 查看哈希值)

上传时间 Python 3

支持者

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面