推荐学习书目
› 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 · 3722 views
    This topic created in 3322 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
    bingoAI
        2
    bingoAI  
       Aug 24, 2017
    nice
    bingoAI
        3
    bingoAI  
       Aug 24, 2017
    题主在用树莓派开发什么?
    kisscucci
        4
    kisscucci  
    OP
       Aug 24, 2017 via iPhone
    @jiangbingo 获取二维码扫描器数据
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   5196 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 06:13 · PVG 14:13 · LAX 23:13 · JFK 02:13
    ♥ Do have faith in what you're doing.