当前位置:   article > 正文

Python 使用can模块(记录稿)_pip install can

pip install can

直接安装:pip install python-can

如果报这个错

更新一下pip

pip3 install --upgrade pip

或者是 pip install --upgrade pip

再安装wrapt

pip install wrapt

再 pip install python-can 就可以了  

测试:

demo.py

  1. import os
  2. import can
  3. import time
  4. bus = can.Bus(interface='socketcan',
  5. channel='can0')
  6. can.rc['bitrate'] = 10000
  7. '''
  8. # send a message
  9. message = can.Message(arbitration_id=123, is_extended_id=True,
  10. data=[0x11, 0x22, 0x33])
  11. bus.send(message, timeout=0.2)
  12. '''
  13. ## received messages
  14. for msg in bus:
  15. timeArray = time.localtime(msg.timestamp)
  16. otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
  17. print(f"Time: {otherStyleTime} Channel: {msg.channel} DLC={msg.dlc} Data-ID: {msg.arbitration_id:X}")
  18. i = 0
  19. for data in msg.data:
  20. s = str(hex(msg.data[i]))
  21. i+=1
  22. print(s[2:].upper(),end=' ')
  23. print("\n")
  24. #print(msg)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/酷酷是懒虫/article/detail/791329
推荐阅读
相关标签
  

闽ICP备14008679号