The Controller Area Network is a bus standard designed to allow microcontrollers and devices to communicate with each other. It has priority based bus arbitration and reliable deterministic communication. It is used in cars, trucks, boats, wheelchairs and more.
The can
package provides controller area network support for
Python developers; providing common abstractions to
different hardware devices, and a suite of utilities for sending and receiving
messages on a can bus.
The library currently supports Python 3.6+ as well as PyPy 3 and runs on Mac, Linux and Windows.
Library Version | Python |
2.x | 2.6+, 3.4+ |
3.x | 2.7+, 3.5+ |
4.x (currently on develop) | 3.6+ |
# import the library
import can
# create a bus instance
# many other interfaces are supported as well (see below)
bus = can.Bus(interface='socketcan',
channel='vcan0',
receive_own_messages=True)
# 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("{:X}: {}".format(msg.arbitration_id, msg.data))
# or use an asynchronous notifier
notifier = can.Notifier(bus, [can.Logger("recorded.log"), can.Printer()])
You can find more information in the documentation, online at python-can.readthedocs.org.
If you run into bugs, you can file them in our issue tracker on GitHub.
There is also a python-can mailing list for development discussion.
Stackoverflow has several
questions and answers tagged with python+can
.
Wherever we interact, we strive to follow the Python Community Code of Conduct.
See doc/development.rst for getting started.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。