V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
kisscucci
V2EX  ›  Python

数据以 16 进制发送到树莓派

  •  
  •   kisscucci · Aug 23, 2017 · 3387 views
    This topic created in 3172 days ago, the information mentioned may be changed or developed.
    #实例化串口
    import serial;
    ser = serial.Serial('/dev/ttyUSB0', 9600, timeout = 0.5);

    #需要发送的数据
    strnum = 7e 00 08 01 00 02 01 ab cd
    .....
    #这里该如何将 strnum 转换为 16 进制
    strSerial = strnum
    ser.write(strSerial)
    4 replies    2017-08-24 09:31:07 +08:00
    kisscucci
        1
    kisscucci  
    OP
       Aug 23, 2017
    找到方法了:

    import binascii

    def order_list():
    a = 'aa0902630000bb'
    a_list = []
    for i in a.split():
    a_list.append(binascii.a2b_hex(i))
    return a_list

    ser = serial.Serial('/dev/ttyUSB0', 9600)
    ser.writelines(order_list())

    作者:知乎用户
    链接: https://www.zhihu.com/question/51733053/answer/147899163
    jiangbingo
        2
    jiangbingo  
       Aug 24, 2017
    nice
    jiangbingo
        3
    jiangbingo  
       Aug 24, 2017
    题主在用树莓派开发什么?
    kisscucci
        4
    kisscucci  
    OP
       Aug 24, 2017 via iPhone
    @jiangbingo 获取二维码扫描器数据
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2707 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 47ms · UTC 14:55 · PVG 22:55 · LAX 07:55 · JFK 10:55
    ♥ Do have faith in what you're doing.