没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
python-can
Release 3.3.4
Oct 04, 2020
Contents
1 Installation 3
1.1 GNU/Linux dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Windows dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 Installing python-can in development mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2 Configuration 5
2.1 In Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 Configuration File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.3 Environment Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.4 Interface Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3 Library API 9
3.1 Bus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.2 Thread safe bus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.3 Message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.4 Listeners . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.5 Asyncio support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.6 Broadcast Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.7 Internal API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.8 Utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
3.9 Notifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
3.10 Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
4 CAN Interface Modules 39
4.1 SocketCAN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
4.2 Kvaser’s CANLIB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
4.3 CAN over Serial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
4.4 CAN over Serial / SLCAN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
4.5 IXXAT Virtual CAN Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
4.6 PCAN Basic API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
4.7 USB2CAN Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
4.8 NI-CAN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
4.9 isCAN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
4.10 NEOVI Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
4.11 Vector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
4.12 Virtual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
4.13 CANalyst-II . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
i
4.14 SYSTEC interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
5 Scripts 65
5.1 can.logger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
5.2 can.player . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
5.3 can.viewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
6 Developer’s Overview 71
6.1 Contributing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
6.2 Building & Installing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
6.3 Creating a new interface/backend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
6.4 Code Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
6.5 Process for creating a new Release . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
7 History and Roadmap 75
7.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
7.2 Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
7.3 Support for CAN within Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
8 Known Bugs 77
Python Module Index 79
Index 81
ii
python-can, Release 3.3.4
The python-can library provides Controller Area Network support for Python, providing common abstractions to
different hardware devices, and a suite of utilities for sending and receiving messages on a CAN bus.
python-can runs any where Python runs; from high powered computers with commercial CAN to usb devices right
down to low powered devices running linux such as a BeagleBone or RaspberryPi.
More concretely, some example uses of the library:
• Passively logging what occurs on a CAN bus. For example monitoring a commercial vehicle using its OBD-II
port.
• Testing of hardware that interacts via CAN. Modules found in modern cars, motocycles, boats, and even
wheelchairs have had components tested from Python using this library.
• Prototyping new hardware modules or software algorithms in-the-loop. Easily interact with an existing bus.
• Creating virtual modules to prototype CAN bus communication.
Brief example of the library in action: connecting to a CAN bus, creating and sending a message:
1 #!/usr/bin/env python
2 # coding: utf-8
3
4 """
5 This example shows how sending a single message works.
6 """
7
8 from __future__ import print_function
9
10 import can
11
12 def send_one():
13
14 # this uses the default configuration (for example from the config file)
15 # see https://python-can.readthedocs.io/en/stable/configuration.html
16 bus = can.interface.Bus()
17
18 # Using specific buses works similar:
19 # bus = can.interface.Bus(bustype='socketcan', channel='vcan0', bitrate=250000)
20 # bus = can.interface.Bus(bustype='pcan', channel='PCAN_USBBUS1', bitrate=250000)
21 # bus = can.interface.Bus(bustype='ixxat', channel=0, bitrate=250000)
22 # bus = can.interface.Bus(bustype='vector', app_name='CANalyzer', channel=0,
˓→bitrate=250000)
23 # ...
24
25 msg = can.Message(arbitration_id=0xc0ffee,
26 data=[0, 25, 0, 1, 3, 1, 4, 1],
27 is_extended_id=True)
28
29 try:
30 bus.send(msg)
31 print("Message sent on {}".format(bus.channel_info))
32 except can.CanError:
33 print("Message NOT sent")
34
35 if __name__ == '__main__':
36 send_one()
Contents:
Contents 1
剩余86页未读,继续阅读
汽车电子小萌新
- 粉丝: 5
- 资源: 22
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页