赞
踩
直接安装:pip install python-can
如果报这个错
更新一下pip
pip3 install --upgrade pip
或者是 pip install --upgrade pip
再安装wrapt
pip install wrapt
再 pip install python-can 就可以了
测试:
demo.py
- import os
- import can
- import time
-
-
- bus = can.Bus(interface='socketcan',
- channel='can0')
- can.rc['bitrate'] = 10000
-
- '''
- # send a message
- message = can.Message(arbitration_id=123, is_extended_id=True,
- data=[0x11, 0x22, 0x33])
- bus.send(message, timeout=0.2)
- '''
-
- ## received messages
-
- for msg in bus:
-
- timeArray = time.localtime(msg.timestamp)
- otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
-
- print(f"Time: {otherStyleTime} Channel: {msg.channel} DLC={msg.dlc} Data-ID: {msg.arbitration_id:X}")
- i = 0
- for data in msg.data:
- s = str(hex(msg.data[i]))
- i+=1
- print(s[2:].upper(),end=' ')
- print("\n")
- #print(msg)
-
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。